예제 #1
0
    def decodes_to(self, text, doc, dump_kwargs=None, load_kwargs=None):
        dump_kwargs = dump_kwargs or {}
        load_kwargs = load_kwargs or {}
        decoded = loads(text, **load_kwargs)
        encoded = dumps(doc, **dump_kwargs)
        self.assertDictEqual(decoded, doc)

        # now, decode the encoded text
        double_decoded = loads(encoded, **load_kwargs)
        self.assertDictEqual(double_decoded, doc)

        return decoded
예제 #2
0
    def check(self, toml_path, yaml_path):
        toml_contents = read_test_file(toml_path)
        yaml_contents = read_test_file(yaml_path)

        toml_decoded = eztoml.loads(toml_contents)
        yaml_decoded = yaml.safe_load(yaml_contents)

        self.assertEqual(toml_decoded, yaml_decoded)
예제 #3
0
    def assert_pretty(self, original_path, pretty_path):

        with io.open(os.path.join(test_dir, "files", original_path), "r") as f:
            original = eztoml.load(f)

        with io.open(os.path.join(test_dir, "files", pretty_path), "r") as f:
            pretty_str = f.read()
            expected_pretty = eztoml.loads(pretty_str)

        self.assertDictEqual(original, expected_pretty)

        encoded = eztoml.dumps(original, sort_keys=True, indent=2)
        self.assertEqual(encoded, pretty_str)
예제 #4
0
    def test_float_constants(self):
        decoded = loads("""
        # infinity
        sf1 = inf  # positive infinity
        sf2 = +inf # positive infinity
        sf3 = -inf # negative infinity
        
        # not a number
        sf4 = nan  # actual sNaN/qNaN encoding is implementation-specific
        sf5 = +nan # same as `nan`
        sf6 = -nan # valid, actual encoding is implementation-specific
        """)

        # in python, NaN == NaN will always be false
        self.assertEqual(len(decoded), 6)
        self.assertEqual(decoded["sf1"], float("inf"))
        self.assertEqual(decoded["sf2"], float("+inf"))
        self.assertEqual(decoded["sf3"], float("-inf"))

        self.assertTrue(math.isnan(decoded["sf4"]))
        self.assertTrue(math.isnan(decoded["sf5"]))
        self.assertTrue(math.isnan(decoded["sf6"]))
예제 #5
0
    def decode_failure(self, text, message=None):
        with self.assertRaises(EzTomlDecodeError) as exc:
            loads(text)

        if message:
            self.assertTrue(str(exc.exception).startswith(message))
예제 #6
0
    def test_parse(self):
        toml_contents = read_test_file("example-v0.3.0.toml")
        eztoml.loads(toml_contents)

        toml_contents = read_test_file("example-v0.4.0.toml")
        eztoml.loads(toml_contents)