-
Notifications
You must be signed in to change notification settings - Fork 0
/
sgftool_test.py
84 lines (67 loc) · 3.54 KB
/
sgftool_test.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
79
80
81
82
83
84
from __future__ import print_function, division, unicode_literals
from codecs import open
import unittest
import sgftool
import sgfparsing # Parsing logic
class MyTest(unittest.TestCase):
def test_bad_token(self):
self.assertRaises(sgfparsing.InvalidSgfException,
sgfparsing.tree, iter([("bad_token", "value")]))
def test_filter(self):
with open("test.sgf", encoding="utf-8") as input:
with open("test_filter.sgf", encoding="utf-8") as output:
result = sgfparsing.tree(sgfparsing.tokenize(input))
sgftool.filter(result)
self.assertEqual(sgftool.to_sgf(result), output.read().strip())
def test_round_trip(self):
with open("test.sgf", encoding="utf-8") as input:
with open("test.sgf", encoding="utf-8") as output:
result = sgftool.to_sgf(sgfparsing.tree(
sgfparsing.tokenize(input)))
self.assertEqual(result, output.read().strip())
def test_reverse(self):
with open("test.sgf", encoding="utf-8") as input:
with open("test_reverse.sgf", encoding="utf-8") as output:
result = sgfparsing.tree(sgfparsing.tokenize(input))
sgftool.reverse(result)
self.assertEqual(sgftool.to_sgf(result), output.read().strip())
def test_limit(self):
with open("test.sgf", encoding="utf-8") as input:
with open("test_limit.sgf", encoding="utf-8") as output:
result = sgfparsing.tree(sgfparsing.tokenize(input))
sgftool.limit(result, 1)
self.assertEqual(sgftool.to_sgf(result), output.read().strip())
def test_unbalanced_parenthesis(self):
with open("test_unbalanced_parenthesis.sgf", encoding="utf-8") as input:
self.assertRaises(sgfparsing.InvalidSgfException,
sgfparsing.tree,
sgfparsing.tokenize(input))
def test_unclosed_parenthesis(self):
with open("test_unclosed_parenthesis.sgf", encoding="utf-8") as input:
self.assertRaises(sgfparsing.InvalidSgfException,
sgfparsing.tree,
sgfparsing.tokenize(input))
def test_missing_semicolon(self):
with open("test_missing_semicolon.sgf", encoding="utf-8") as input:
self.assertRaises(sgfparsing.InvalidSgfException,
sgfparsing.tree,
sgfparsing.tokenize(input))
def test_unclosed_property(self):
with open("test_unclosed_property.sgf", encoding="utf-8") as input:
self.assertRaises(sgfparsing.InvalidSgfException,
sgfparsing.tree,
sgfparsing.tokenize(input))
def test_invalid_coordinate_number(self):
with open("test_invalid_coordinate_number.sgf",
encoding="utf-8") as input:
self.assertRaises(sgfparsing.InvalidSgfException,
sgftool.reverse,
sgfparsing.tree(sgfparsing.tokenize(input)))
def test_invalid_coordinate_out_of_bounds(self):
with open("test_invalid_coordinate_out_of_bounds.sgf",
encoding="utf-8") as input:
self.assertRaises(sgfparsing.InvalidSgfException,
sgftool.reverse,
sgfparsing.tree(sgfparsing.tokenize(input)))
if __name__ == '__main__':
unittest.main()