def test_prefs_write(): """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, mode="w+t") 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) assert read_prefs == _prefs
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 try: with tempfile.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 self.assertEqual(dict(Preferences.read_prefs(path)), _prefs) finally: # cleanup os.remove(path)
def create_profile(addons, pref_categories, profile=None): from mozprofile.prefs import Preferences from mozprofile.profile import Profile from subprocess import check_output prefs = Preferences() for category in pref_categories: prefs.add_file("{}:{}".format(C.MOZRUNNER_PREFS_INI, category)) return Profile( addons=addons, preferences=prefs(), restore=False, )
def test_read_prefs_ttw(): """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)) assert dict(read) == _prefs_with_comments finally: httpd.stop()
def test_read_prefs_ttw(): """test reading preferences through the web via wptserve""" # create a WebTestHttpd instance docroot = os.path.join(here, "files") host = "127.0.0.1" port = 8888 httpd = server.WebTestHttpd(host=host, port=port, doc_root=docroot) # create a preferences instance prefs = Preferences() try: # start server httpd.start() # read preferences through the web read = prefs.read_prefs("http://%s:%d/prefs_with_comments.js" % (host, port)) assert dict(read) == _prefs_with_comments finally: httpd.stop()