[Pkg-mozext-commits] [requestpolicy] 60/257: [tst][ref] Marionette prefs api: override Prefs class
David Prévot
taffit at moszumanska.debian.org
Thu Jan 28 03:19:56 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository requestpolicy.
commit 3a2f12d67dd89d366e515b2ff5d150f1bb7f3df1
Author: Martin Kimmerle <dev at 256k.de>
Date: Sat Sep 26 19:51:32 2015 +0200
[tst][ref] Marionette prefs api: override Prefs class
Override the `Preferences` class so that `using_pref()` can be
called like `self.prefs.using_pref()`.
---
tests/marionette/rp_puppeteer/__init__.py | 4 ++++
tests/marionette/rp_puppeteer/api/prefs.py | 27 +++++++++++++----------
tests/marionette/rp_puppeteer/tests/test_prefs.py | 4 +---
3 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/tests/marionette/rp_puppeteer/__init__.py b/tests/marionette/rp_puppeteer/__init__.py
index c7f32b4..d3ec217 100644
--- a/tests/marionette/rp_puppeteer/__init__.py
+++ b/tests/marionette/rp_puppeteer/__init__.py
@@ -12,6 +12,10 @@ class RequestPolicyPuppeteer(object):
RequestPolicyTestCase instance.
"""
+ @use_class_as_property('api.prefs.Preferences')
+ def prefs(self):
+ pass
+
@use_class_as_property('api.rules.Rules')
def rules(self):
pass
diff --git a/tests/marionette/rp_puppeteer/api/prefs.py b/tests/marionette/rp_puppeteer/api/prefs.py
index d58af37..faccbb4 100644
--- a/tests/marionette/rp_puppeteer/api/prefs.py
+++ b/tests/marionette/rp_puppeteer/api/prefs.py
@@ -3,18 +3,21 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from contextlib import contextmanager
+from firefox_puppeteer.api.prefs import Preferences as FxPreferences
- at contextmanager
-def using_pref(prefs, pref_name, pref_value):
- """Context manager for setting a pref temporarily.
- :param prefs: The Preferences() object.
- :param pref_name: The preference to set.
- :param pref_value: The value to set the preference to.
- """
+class Preferences(FxPreferences):
- prefs.set_pref(pref_name, pref_value)
- try:
- yield
- finally:
- prefs.reset_pref(pref_name)
+ @contextmanager
+ def using_pref(self, pref_name, pref_value):
+ """Context manager for setting a pref temporarily.
+
+ :param pref_name: The preference to set.
+ :param pref_value: The value to set the preference to.
+ """
+
+ self.set_pref(pref_name, pref_value)
+ try:
+ yield
+ finally:
+ self.reset_pref(pref_name)
diff --git a/tests/marionette/rp_puppeteer/tests/test_prefs.py b/tests/marionette/rp_puppeteer/tests/test_prefs.py
index 58ae98d..c7a1dc9 100644
--- a/tests/marionette/rp_puppeteer/tests/test_prefs.py
+++ b/tests/marionette/rp_puppeteer/tests/test_prefs.py
@@ -4,8 +4,6 @@
from rp_ui_harness import RequestPolicyTestCase
-from rp_puppeteer.api.prefs import using_pref
-
class TestPrefs(RequestPolicyTestCase):
@@ -18,7 +16,7 @@ class TestPrefs(RequestPolicyTestCase):
self.assertEqual(self.prefs.get_pref(self.new_pref), None,
msg="The pref initially doesn't exist.")
- with using_pref(self.prefs, self.new_pref, 'unittest'):
+ with self.prefs.using_pref(self.new_pref, 'unittest'):
self.assertEqual(self.prefs.get_pref(self.new_pref), 'unittest',
msg="The pref has been set.")
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git
More information about the Pkg-mozext-commits
mailing list