-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_parse.py
78 lines (63 loc) · 3.09 KB
/
test_parse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from unittest import TestCase
from SirilParser import *
from Exceptions import SirilError
from DummyFile import DummyFile
class TestParse(TestCase):
def setUp(self):
self.default_assignments_dict = default_assignments_dict.copy()
self.default_statements = default_statements.copy()
self.file = DummyFile()
self.default_assignments_dict["`@output@`"] = self.file
@property
def new_assignments_dict(self):
return self.default_assignments_dict.copy()
def test_parse(self):
self.fail()
def test_argument_parsing(self):
self.fail()
def test_bracket_parsing(self):
self.fail()
def test_string_parsing(self):
line = "\"Test\""
assignments_dict = self.new_assignments_dict
out_line, assignments_dict = string_parsing(line, assignments_dict)
self.assertNotIn(line, assignments_dict)
self.assertNotIn("\"", out_line)
self.assertIn(out_line, assignments_dict)
error_lines = ["\"", "\"\"\"\"", "\"No comma\" b"]
for line in error_lines:
self.assertRaises(SirilError, string_parsing, line, assignments_dict)
assignments_dict = self.new_assignments_dict
line = "assignment, \"string\", repeat({/123/:\"@\", break})"
out_line, assignments_dict = string_parsing(line, assignments_dict)
self.assertIn(("\"string\"",), assignments_dict.values())
self.assertIn(("\"@\"",), assignments_dict.values())
self.assertNotIn(("assignment",) ,assignments_dict.values())
self.assertNotIn(("break",), assignments_dict.values())
self.assertRegex(out_line, r"assignment, `@[0-9]+@`, repeat\(\{/123/:`@[0-9]+@`, break\}\)")
class TestFunction(TestCase):
def setUp(self):
self.default_assignments_dict = default_assignments_dict.copy()
self.default_statements = default_statements.copy()
self.file = DummyFile()
self.default_assignments_dict["`@output@`"] = self.file
@property
def new_assignments_dict(self):
return self.default_assignments_dict.copy()
def test_dynamic_assignment(self):
assignments_dict = self.new_assignments_dict
assign = dynamic_assignment("Test", ("TEST",))
self.assertNotIn("Test", assignments_dict)
_, _, return_assignments_dict = assign((), self.new_assignments_dict)
self.assertNotIn("Test", assignments_dict)
self.assertIn("Test", return_assignments_dict)
self.assertSequenceEqual(("TEST",), return_assignments_dict["Test"])
def call(comp):
return comp.upper()
assign_callable = dynamic_assignment("recall", call)
_, _, return_assignments_dict = assign_callable("Should be a comp", self.new_assignments_dict)
self.assertNotIn("recall", assignments_dict)
self.assertIn("recall", return_assignments_dict)
self.assertEqual("Should be a comp".upper(), return_assignments_dict["recall"])
_, _, return_assignments_dict = assign_callable("Take 2", self.new_assignments_dict)
self.assertEqual("Take 2".upper(), return_assignments_dict["recall"])