This repository was archived by the owner on Mar 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsgf_parsing_test.py
More file actions
84 lines (65 loc) · 2.71 KB
/
Copy pathsgf_parsing_test.py
File metadata and controls
84 lines (65 loc) · 2.71 KB
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
79
80
81
82
83
84
import unittest
from sgf_parsing import parse, SgfTree
# Tests adapted from `problem-specifications//canonical-data.json`
class SgfParsingTest(unittest.TestCase):
def test_empty_input(self):
input_string = ""
with self.assertRaisesWithMessage(ValueError):
parse(input_string)
def test_tree_with_no_nodes(self):
input_string = "()"
with self.assertRaisesWithMessage(ValueError):
parse(input_string)
def test_node_without_tree(self):
input_string = ";"
with self.assertRaisesWithMessage(ValueError):
parse(input_string)
def test_node_without_properties(self):
input_string = "(;)"
expected = SgfTree()
self.assertEqual(parse(input_string), expected)
def test_single_node_tree(self):
input_string = "(;A[B])"
expected = SgfTree(properties={"A": ["B"]})
self.assertEqual(parse(input_string), expected)
def test_multiple_properties(self):
input_string = "(;A[b]C[d])"
expected = SgfTree(properties={"A": ["b"], "C": ["d"]})
self.assertEqual(parse(input_string), expected)
def test_properties_without_delimiter(self):
input_string = "(;A)"
with self.assertRaisesWithMessage(ValueError):
parse(input_string)
def test_all_lowercase_property(self):
input_string = "(;a[b])"
with self.assertRaisesWithMessage(ValueError):
parse(input_string)
def test_upper_and_lowercase_property(self):
input_string = "(;Aa[b])"
with self.assertRaisesWithMessage(ValueError):
parse(input_string)
def test_two_nodes(self):
input_string = "(;A[B];B[C])"
expected = SgfTree(properties={"A": ["B"]}, children=[
SgfTree({"B": ["C"]})])
self.assertEqual(parse(input_string), expected)
def test_two_child_trees(self):
input_string = "(;A[B](;B[C])(;C[D]))"
expected = SgfTree(
properties={"A": ["B"]},
children=[SgfTree({"B": ["C"]}), SgfTree({"C": ["D"]})],
)
self.assertEqual(parse(input_string), expected)
def test_multiple_property_values(self):
input_string = "(;A[b][c][d])"
expected = SgfTree(properties={"A": ["b", "c", "d"]})
self.assertEqual(parse(input_string), expected)
def test_escaped_property(self):
input_string = "(;A[\\]b\nc\nd\t\te \n\\]])"
expected = SgfTree(properties={"A": ["]b\nc\nd e \n]"]})
self.assertEqual(parse(input_string), expected)
# Utility functions
def assertRaisesWithMessage(self, exception):
return self.assertRaisesRegex(exception, r".+")
if __name__ == "__main__":
unittest.main()