Bug 1431024 - Modified error criterion check in prefs.py. r=wlach draft
authorVedant Chakravadhanula <vedantc98@gmail.com>
Wed, 24 Jan 2018 21:39:14 +0530
changeset 724176 f2cf67130ff35395796e32a0e75964a112190e8c
parent 723950 b0baaec09caf3e1b30ec6b238f5c46ef9b3188be
child 747079 af80f911d28f903f27f73a11a18333e07b36b3f0
push id96672
push userbmo:vedantc98@gmail.com
push dateWed, 24 Jan 2018 16:11:17 +0000
reviewerswlach
bugs1431024
milestone60.0a1
Bug 1431024 - Modified error criterion check in prefs.py. r=wlach MozReview-Commit-ID: 6nEXiIQ7awD
testing/mozbase/mozprofile/mozprofile/prefs.py
testing/mozbase/mozprofile/tests/test_preferences.py
--- 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 True not in [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,26 @@ 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):
+        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