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")
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'], {})
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)
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." )
def test_parse_type(self): test = perky.loads(TEST_INPUT_TEXT) self.assertEqual(type(test), dict)
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()})
def test_parse_trip_q_error(self): with self.assertRaises(perky.PerkyFormatError): perky.loads(TEST_INPUT_TEXT_TRIPLE_Q_ERROR)
def test_parse_unterminated_quoted_string(self): with self.assertRaises(SyntaxError): perky.loads(""" 'quoted' = 'unterminated quoted string """)
def test_parse_wrong_type_input(self): with self.assertRaises(AttributeError): perky.loads(3)
def test_parse_no_input(self): with self.assertRaises(AttributeError): perky.loads(None)
def test_parse(self): test = perky.loads(TEST_INPUT_TEXT) self.assertEqual(test, TEST__PARSE_OUTPUT)