Bug 1431024 - Modified error criterion check in prefs.py. r=wlach
MozReview-Commit-ID: 6nEXiIQ7awD
--- a/testing/mozbase/mozprofile/mozprofile/prefs.py
+++ b/testing/mozbase/mozprofile/mozprofile/prefs.py
@@ -143,17 +143,17 @@ class Preferences(object):
if [i for i in prefs if type(i) != list or len(i) != 2]:
raise PreferencesReadError("Malformed preferences: %s" % path)
values = [i[1] for i in prefs]
elif isinstance(prefs, dict):
values = prefs.values()
else:
raise PreferencesReadError("Malformed preferences: %s" % path)
types = (bool, string_types, int)
- if [i for i in values if not [isinstance(i, j) for j in types]]:
+ if [i for i in values if not any([isinstance(i, j) for j in types])]:
raise PreferencesReadError("Only bool, string, and int values allowed")
return prefs
@classmethod
def read_prefs(cls, path, pref_setter='user_pref', interpolation=None):
"""
Read preferences from (e.g.) prefs.js
--- a/testing/mozbase/mozprofile/tests/test_preferences.py
+++ b/testing/mozbase/mozprofile/tests/test_preferences.py
@@ -11,17 +11,17 @@ import mozhttpd
import os
import shutil
import tempfile
import unittest
import mozunit
from mozprofile.cli import MozProfileCLI
-from mozprofile.prefs import Preferences
+from mozprofile.prefs import Preferences, PreferencesReadError
from mozprofile.profile import Profile
here = os.path.dirname(os.path.abspath(__file__))
class PreferencesTest(unittest.TestCase):
"""test mozprofile preference handling"""
@@ -300,16 +300,27 @@ user_pref("webgl.force-enabled", true);
# just repr it...could use the json module but we don't need it here
with mozfile.NamedTemporaryFile(suffix='.json') as f:
f.write(json)
f.flush()
commandline = ["--preferences", f.name]
self.compare_generated(_prefs, commandline)
+ def test_json_datatypes(self):
+ # minPercent is at 30.1 to test if non-integer data raises an exception
+ json = """{"zoom.minPercent": 30.1, "zoom.maxPercent": 300}"""
+
+ with mozfile.NamedTemporaryFile(suffix='.json') as f:
+ f.write(json)
+ f.flush()
+
+ with self.assertRaises(PreferencesReadError):
+ Preferences.read_json(f._path)
+
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