Exemple #1
0
 def test_parse_trip_repeated_key_error(self):
     # perky doesn't like it if you redefine the same key in a dict
     # twice in the same file.
     # note that perky explicitly doesn't complain if you
     # redefine a key in a different (as in, =include'd) file.
     # test_perky_include_nested tests redefining in different files.
     with self.assertRaises(perky.PerkyFormatError):
         perky.loads("a=3\na=5")
Exemple #2
0
    def test_empty_dicts_and_lists(self):
        d = perky.loads('''
a = []
b = {}
c = [ ]
d = { }

''')
        self.assertEqual(d['a'], [])
        self.assertEqual(d['b'], {})
        self.assertEqual(d['c'], [])
        self.assertEqual(d['d'], {})
Exemple #3
0
    def test_perky_roundtrip(self):
        for i in range(1, 300):
            c = chr(i)
            if c.isspace():
                continue
            hex_digits = hex(i).partition("x")[2].rjust(4, "0")
            s = f"U+{hex_digits} {c}"

            d1 = {s: s}
            s1 = perky.dumps(d1)
            d2 = perky.loads(s1)
            s2 = perky.dumps(d2)
            self.assertEqual(d1, d2)
            self.assertEqual(s1, s2)
Exemple #4
0
    def test_parse_triple_quote(self):
        d = perky.loads('''
a = """

    this is flush left
    note the          ^^
    intentional trailing whitespace!

      don't remove it, even though I
      know you want to.
    """

''')
        self.assertEqual(
            d['a'],
            "\nthis is flush left\nnote the          ^^\nintentional trailing whitespace!\n\n  don't remove it, even though I\n  know you want to."
        )
Exemple #5
0
 def test_parse_type(self):
     test = perky.loads(TEST_INPUT_TEXT)
     self.assertEqual(type(test), dict)
Exemple #6
0
 def test_perky_invalid_pragma(self):
     with self.assertRaises(perky.PerkyFormatError):
         root = perky.loads("a=b\n=include '''\nc=d\n",
                            pragmas={'include': perky.pragma_include()})
Exemple #7
0
 def test_parse_trip_q_error(self):
     with self.assertRaises(perky.PerkyFormatError):
         perky.loads(TEST_INPUT_TEXT_TRIPLE_Q_ERROR)
Exemple #8
0
    def test_parse_unterminated_quoted_string(self):
        with self.assertRaises(SyntaxError):
            perky.loads("""
'quoted' = 'unterminated quoted string
""")
Exemple #9
0
 def test_parse_wrong_type_input(self):
     with self.assertRaises(AttributeError):
         perky.loads(3)
Exemple #10
0
 def test_parse_no_input(self):
     with self.assertRaises(AttributeError):
         perky.loads(None)
Exemple #11
0
 def test_parse(self):
     test = perky.loads(TEST_INPUT_TEXT)
     self.assertEqual(test, TEST__PARSE_OUTPUT)