示例#1
0
    def check_non_dict(self):
        """Valid JSON which does not parse as a dict should raise a ValueError"""

        # Should be able to parse this as JSON
        json.loads(valid_json_not_dict)

        with pytest.raises(ValueError):
            get_user_defined_globals(valid_json_not_dict)
示例#2
0
    def check_non_dict(self):
        """Valid JSON which does not parse as a dict should raise a ValueError"""

        # Should be able to parse this as JSON
        json.loads(valid_json_not_dict)

        with pytest.raises(ValueError):
            get_user_defined_globals(valid_json_not_dict)
示例#3
0
    def check_non_dict_from_file(self):
        """Validate behavior when given file containing valid JSON which does not parse as a dict"""
        _, fname = tempfile.mkstemp()
        try:
            with open(fname, "w") as fh:
                # Write valid JSON which does not parse as a dict
                fh.write(valid_json_not_dict)

            with pytest.raises(ValueError, match=fname):
                get_user_defined_globals(fname)

        finally:
            os.remove(fname)
示例#4
0
    def check_bad_parse_from_file(self):
        """Validate behavior when given file containing invalid JSON"""
        _, fname = tempfile.mkstemp()
        try:
            with open(fname, "w") as fh:
                # Write invalid JSON
                fh.write(invalid_globals_json)

            with pytest.raises(ValueError):
                get_user_defined_globals(fname)

        finally:
            os.remove(fname)
示例#5
0
    def check_bad_parse_from_file(self):
        """Validate behavior when given file containing invalid JSON"""
        _, fname = tempfile.mkstemp()
        try:
            with open(fname, "w") as fh:
                # Write invalid JSON
                fh.write(invalid_globals_json)

            with pytest.raises(ValueError):
                get_user_defined_globals(fname)

        finally:
            os.remove(fname)
示例#6
0
    def check_immutable(self):
        """Expect the user defined dict object to be immutable."""
        global_dict = get_user_defined_globals(globals_json)

        with pytest.raises(NotImplementedError):
            global_dict["x"] = -1

        with pytest.raises(NotImplementedError):
            global_dict["y"] = 3
示例#7
0
    def check_immutable(self):
        """Expect the user defined dict object to be immutable."""
        global_dict = get_user_defined_globals(globals_json)

        with pytest.raises(NotImplementedError):
            global_dict["x"] = -1

        with pytest.raises(NotImplementedError):
            global_dict["y"] = 3
示例#8
0
    def check_parse_from_file(self):
        """Validate that, given a filename of a file containing valid JSON, we correctly parse the file contents."""
        _, fname = tempfile.mkstemp()
        try:
            with open(fname, "w") as fh:
                fh.write(globals_json)

            global_dict = get_user_defined_globals(fname)
            assert global_dict == json.loads(globals_json)
            assert global_dict["x"] == 200
        finally:
            os.remove(fname)
示例#9
0
    def check_parse_from_file(self):
        """Validate that, given a filename of a file containing valid JSON, we correctly parse the file contents."""
        _, fname = tempfile.mkstemp()
        try:
            with open(fname, "w") as fh:
                fh.write(globals_json)

            global_dict = get_user_defined_globals(fname)
            assert global_dict == json.loads(globals_json)
            assert global_dict["x"] == 200
        finally:
            os.remove(fname)
示例#10
0
 def check_unparseable(self):
     """If globals string is not a path to a file, and not parseable as JSON we want to raise a ValueError
     """
     with pytest.raises(ValueError):
         get_user_defined_globals(invalid_globals_json)
示例#11
0
 def check_parseable_json_string(self):
     """Check if globals_json is parseable as JSON, we get back a dictionary view of parsed JSON."""
     globals_dict = get_user_defined_globals(globals_json)
     assert globals_dict == json.loads(globals_json)
示例#12
0
    def check_pickleable(self):
        """Expect the user defined dict object to be pickleable"""
        globals_dict = get_user_defined_globals(globals_json)

        assert globals_dict  # Need to test non-empty dict, to ensure py3 compatibility
        assert pickle.loads(pickle.dumps(globals_dict)) == globals_dict
示例#13
0
 def check_unparseable(self):
     """If globals string is not a path to a file, and not parseable as JSON we want to raise a ValueError
     """
     with pytest.raises(ValueError):
         get_user_defined_globals(invalid_globals_json)
示例#14
0
 def check_parseable_json_string(self):
     """Check if globals_json is parseable as JSON, we get back a dictionary view of parsed JSON."""
     globals_dict = get_user_defined_globals(globals_json)
     assert globals_dict == json.loads(globals_json)