本文整理匯總了Python中mozprofile.profile.Profile.cleanup方法的典型用法代碼示例。如果您正苦於以下問題:Python Profile.cleanup方法的具體用法?Python Profile.cleanup怎麽用?Python Profile.cleanup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mozprofile.profile.Profile
的用法示例。
在下文中一共展示了Profile.cleanup方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_nonce
# 需要導入模塊: from mozprofile.profile import Profile [as 別名]
# 或者: from mozprofile.profile.Profile import cleanup [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'})
示例2: test_preexisting_preferences
# 需要導入模塊: from mozprofile.profile import Profile [as 別名]
# 或者: from mozprofile.profile.Profile import cleanup [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