Exemple #1
0
 def test_string(self) -> None:
     val = "default: 'string'"
     val2 = "default: \n\n'string'"
     expected = 'string'
     res = default.parseString(val, parseAll=True)
     self.assertEqual(res[0], expected)
     res = default.parseString(val2, parseAll=True)
     self.assertEqual(res[0], expected)
Exemple #2
0
 def test_expression(self) -> None:
     expr1 = 'datetime.now()'
     expr2 = 'datetime\nnow()'
     val = f"default: `{expr1}`"
     val2 = f"default: `{expr2}`"
     val3 = f"default: ``"
     res = default.parseString(val, parseAll=True)
     self.assertEqual(res[0], f'({expr1})')
     res = default.parseString(val2, parseAll=True)
     self.assertEqual(res[0], f'({expr2})')
     res = default.parseString(val3, parseAll=True)
     self.assertEqual(res[0], '()')
Exemple #3
0
 def test_wrong(self) -> None:
     val = "default: now"
     with self.assertRaises(ParseSyntaxException):
         default.parseString(val, parseAll=True)
Exemple #4
0
 def test_numbers(self) -> None:
     vals = [0, 17, 13.3, 2.0]
     while len(vals) > 0:
         cur = vals.pop()
         res = default.parseString(f'default: {cur}', parseAll=True)
         self.assertEqual((cur), res[0])
Exemple #5
0
 def test_bool(self) -> None:
     vals = ['true', 'false', 'null']
     exps = [True, False, 'NULL']
     while len(vals) > 0:
         res = default.parseString(f'default: {vals.pop()}', parseAll=True)
         self.assertEqual(exps.pop(), res[0])