本文整理汇总了Python中mozprofile.prefs.Preferences.read_prefs方法的典型用法代码示例。如果您正苦于以下问题:Python Preferences.read_prefs方法的具体用法?Python Preferences.read_prefs怎么用?Python Preferences.read_prefs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozprofile.prefs.Preferences
的用法示例。
在下文中一共展示了Preferences.read_prefs方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reset_should_remove_added_prefs
# 需要导入模块: from mozprofile.prefs import Preferences [as 别名]
# 或者: from mozprofile.prefs.Preferences import read_prefs [as 别名]
def test_reset_should_remove_added_prefs(self):
"""Check that when we call reset the items we expect are updated"""
profile = Profile()
prefs_file = os.path.join(profile.profile, 'user.js')
# we shouldn't have any initial preferences
initial_prefs = Preferences.read_prefs(prefs_file)
self.assertFalse(initial_prefs)
initial_prefs = file(prefs_file).read().strip()
self.assertFalse(initial_prefs)
# add some preferences
prefs1 = [("mr.t.quotes", "i aint getting on no plane!")]
profile.set_preferences(prefs1)
self.assertEqual(prefs1, Preferences.read_prefs(prefs_file))
lines = file(prefs_file).read().strip().splitlines()
self.assertTrue(bool([line for line in lines
if line.startswith('#MozRunner Prefs Start')]))
self.assertTrue(bool([line for line in lines
if line.startswith('#MozRunner Prefs End')]))
profile.reset()
self.assertNotEqual(prefs1,
Preferences.read_prefs(os.path.join(profile.profile, 'user.js')),
"I pity the fool who left my pref")
示例2: test_nonce
# 需要导入模块: from mozprofile.prefs import Preferences [as 别名]
# 或者: from mozprofile.prefs.Preferences import read_prefs [as 别名]
def test_nonce(self):
# make a profile with one preference
path = tempfile.mktemp()
profile = Profile(path,
preferences={'foo': 'bar'},
restore=False)
user_js = os.path.join(profile.profile, 'user.js')
self.assertTrue(os.path.exists(user_js))
# ensure the preference is correct
prefs = Preferences.read_prefs(user_js)
self.assertEqual(dict(prefs), {'foo': 'bar'})
del profile
# augment the profile with a second preference
profile = Profile(path,
preferences={'fleem': 'baz'},
restore=True)
prefs = Preferences.read_prefs(user_js)
self.assertEqual(dict(prefs), {'foo': 'bar', 'fleem': 'baz'})
# cleanup the profile;
# this should remove the new preferences but not the old
profile.cleanup()
prefs = Preferences.read_prefs(user_js)
self.assertEqual(dict(prefs), {'foo': 'bar'})
示例3: test_prefs_write
# 需要导入模块: from mozprofile.prefs import Preferences [as 别名]
# 或者: from mozprofile.prefs.Preferences import read_prefs [as 别名]
def test_prefs_write(self):
"""test that the Preferences.write() method correctly serializes preferences"""
_prefs = {'browser.startup.homepage': "http://planet.mozilla.org",
'zoom.minPercent': 30,
'zoom.maxPercent': 300}
# make a Preferences manager with the testing preferences
preferences = Preferences(_prefs)
# write them to a temporary location
path = None
read_prefs = None
try:
with mozfile.NamedTemporaryFile(suffix='.js', delete=False) as f:
path = f.name
preferences.write(f, _prefs)
# read them back and ensure we get what we put in
read_prefs = dict(Preferences.read_prefs(path))
finally:
# cleanup
if path and os.path.exists(path):
os.remove(path)
self.assertEqual(read_prefs, _prefs)
示例4: test_can_read_prefs_with_multiline_comments
# 需要导入模块: from mozprofile.prefs import Preferences [as 别名]
# 或者: from mozprofile.prefs.Preferences import read_prefs [as 别名]
def test_can_read_prefs_with_multiline_comments(self):
"""
Ensure that multiple comments in the file header do not break reading
the prefs (https://bugzilla.mozilla.org/show_bug.cgi?id=1233534).
"""
user_js = tempfile.NamedTemporaryFile(suffix='.js', delete=False)
self.addCleanup(mozfile.remove, user_js.name)
with user_js:
user_js.write("""
# Mozilla User Preferences
/* Do not edit this file.
*
* If you make changes to this file while the application is running,
* the changes will be overwritten when the application exits.
*
* To make a manual change to preferences, you can visit the URL about:config
*/
user_pref("webgl.enabled_for_all_sites", true);
user_pref("webgl.force-enabled", true);
""")
self.assertEqual(
Preferences.read_prefs(user_js.name),
[('webgl.enabled_for_all_sites', True),
('webgl.force-enabled', True)]
)
示例5: test_read_prefs_with_comments
# 需要导入模块: from mozprofile.prefs import Preferences [as 别名]
# 或者: from mozprofile.prefs.Preferences import read_prefs [as 别名]
def test_read_prefs_with_comments(self):
"""test reading preferences from a prefs.js file that contains comments"""
_prefs = {'browser.startup.homepage': 'http://planet.mozilla.org',
'zoom.minPercent': 30,
'zoom.maxPercent': 300,
'webgl.verbose': 'false'}
path = os.path.join(here, 'files', 'prefs_with_comments.js')
self.assertEqual(dict(Preferences.read_prefs(path)), _prefs)
示例6: test_magic_markers
# 需要导入模块: from mozprofile.prefs import Preferences [as 别名]
# 或者: from mozprofile.prefs.Preferences import read_prefs [as 别名]
def test_magic_markers(self):
"""ensure our magic markers are working"""
profile = Profile()
prefs_file = os.path.join(profile.profile, 'user.js')
# we shouldn't have any initial preferences
initial_prefs = Preferences.read_prefs(prefs_file)
self.assertFalse(initial_prefs)
initial_prefs = file(prefs_file).read().strip()
self.assertFalse(initial_prefs)
# add some preferences
prefs1 = [("browser.startup.homepage", "http://planet.mozilla.org/"),
("zoom.minPercent", 30)]
profile.set_preferences(prefs1)
self.assertEqual(prefs1, Preferences.read_prefs(prefs_file))
lines = file(prefs_file).read().strip().splitlines()
self.assertTrue(bool([line for line in lines
if line.startswith('#MozRunner Prefs Start')]))
self.assertTrue(bool([line for line in lines
if line.startswith('#MozRunner Prefs End')]))
# add some more preferences
prefs2 = [("zoom.maxPercent", 300),
("webgl.verbose", 'false')]
profile.set_preferences(prefs2)
self.assertEqual(prefs1 + prefs2, Preferences.read_prefs(prefs_file))
lines = file(prefs_file).read().strip().splitlines()
self.assertTrue(len([line for line in lines
if line.startswith('#MozRunner Prefs Start')]) == 2)
self.assertTrue(len([line for line in lines
if line.startswith('#MozRunner Prefs End')]) == 2)
# now clean it up
profile.clean_preferences()
final_prefs = Preferences.read_prefs(prefs_file)
self.assertFalse(final_prefs)
lines = file(prefs_file).read().strip().splitlines()
self.assertTrue('#MozRunner Prefs Start' not in lines)
self.assertTrue('#MozRunner Prefs End' not in lines)
示例7: test_preexisting_preferences
# 需要导入模块: from mozprofile.prefs import Preferences [as 别名]
# 或者: from mozprofile.prefs.Preferences import read_prefs [as 别名]
def test_preexisting_preferences(self):
"""ensure you don't clobber preexisting preferences"""
# make a pretend profile
tempdir = tempfile.mkdtemp()
try:
# make a user.js
contents = """
user_pref("webgl.enabled_for_all_sites", true);
user_pref("webgl.force-enabled", true);
"""
user_js = os.path.join(tempdir, 'user.js')
f = file(user_js, 'w')
f.write(contents)
f.close()
# make sure you can read it
prefs = Preferences.read_prefs(user_js)
original_prefs = [('webgl.enabled_for_all_sites', True), ('webgl.force-enabled', True)]
self.assertTrue(prefs == original_prefs)
# now read this as a profile
profile = Profile(tempdir, preferences={"browser.download.dir": "/home/jhammel"})
# make sure the new pref is now there
new_prefs = original_prefs[:] + [("browser.download.dir", "/home/jhammel")]
prefs = Preferences.read_prefs(user_js)
self.assertTrue(prefs == new_prefs)
# clean up the added preferences
profile.cleanup()
del profile
# make sure you have the original preferences
prefs = Preferences.read_prefs(user_js)
self.assertTrue(prefs == original_prefs)
except:
shutil.rmtree(tempdir)
raise
示例8: compare_generated
# 需要导入模块: from mozprofile.prefs import Preferences [as 别名]
# 或者: from mozprofile.prefs.Preferences import read_prefs [as 别名]
def compare_generated(self, _prefs, commandline):
"""
writes out to a new profile with mozprofile command line
reads the generated preferences with prefs.py
compares the results
cleans up
"""
profile, stderr, code = self.run_command(*commandline)
prefs_file = os.path.join(profile, 'user.js')
self.assertTrue(os.path.exists(prefs_file))
read = Preferences.read_prefs(prefs_file)
if isinstance(_prefs, dict):
read = dict(read)
self.assertEqual(_prefs, read)
shutil.rmtree(profile)
示例9: test_read_prefs_with_interpolation
# 需要导入模块: from mozprofile.prefs import Preferences [as 别名]
# 或者: from mozprofile.prefs.Preferences import read_prefs [as 别名]
def test_read_prefs_with_interpolation(self):
"""test reading preferences from a prefs.js file whose values
require interpolation"""
expected_prefs = {
"browser.foo": "http://server-name",
"zoom.minPercent": 30,
"webgl.verbose": "false",
"browser.bar": "somethingxyz"
}
values = {
"server": "server-name",
"abc": "something"
}
path = os.path.join(here, 'files', 'prefs_with_interpolation.js')
read_prefs = Preferences.read_prefs(path, interpolation=values)
self.assertEqual(dict(read_prefs), expected_prefs)
示例10: test_read_prefs_ttw
# 需要导入模块: from mozprofile.prefs import Preferences [as 别名]
# 或者: from mozprofile.prefs.Preferences import read_prefs [as 别名]
def test_read_prefs_ttw(self):
"""test reading preferences through the web via mozhttpd"""
# create a MozHttpd instance
docroot = os.path.join(here, 'files')
host = '127.0.0.1'
port = 8888
httpd = mozhttpd.MozHttpd(host=host, port=port, docroot=docroot)
# create a preferences instance
prefs = Preferences()
try:
# start server
httpd.start(block=False)
# read preferences through the web
read = prefs.read_prefs('http://%s:%d/prefs_with_comments.js' % (host, port))
self.assertEqual(dict(read), self._prefs_with_comments)
finally:
httpd.stop()
示例11: test_read_prefs_with_comments
# 需要导入模块: from mozprofile.prefs import Preferences [as 别名]
# 或者: from mozprofile.prefs.Preferences import read_prefs [as 别名]
def test_read_prefs_with_comments(self):
"""test reading preferences from a prefs.js file that contains comments"""
path = os.path.join(here, 'files', 'prefs_with_comments.js')
self.assertEqual(dict(Preferences.read_prefs(path)), self._prefs_with_comments)