Files
@ 70d01e8dc839
Branch filter:
Location: Diana/src/tests/testSgfParser.py - annotation
70d01e8dc839
1.7 KiB
text/x-python
a little refactoring and optimization of parser's regular expressions
c6e20613189d f0b8120281b9 f0b8120281b9 f0b8120281b9 f0b8120281b9 c6e20613189d b66f5379b832 cfcff53c74e6 f0b8120281b9 f0b8120281b9 f0b8120281b9 f0b8120281b9 b66f5379b832 c6e20613189d c6e20613189d c6e20613189d c6e20613189d c6e20613189d c6e20613189d c6e20613189d c6e20613189d c6e20613189d c6e20613189d c6e20613189d c6e20613189d c6e20613189d c6e20613189d c6e20613189d cfcff53c74e6 cfcff53c74e6 0ee71f3564f4 0ee71f3564f4 0ee71f3564f4 0ee71f3564f4 cfcff53c74e6 cfcff53c74e6 cfcff53c74e6 cfcff53c74e6 cfcff53c74e6 cfcff53c74e6 f0b8120281b9 2ed7f0dab5ef 2ed7f0dab5ef 2ed7f0dab5ef 2ed7f0dab5ef 2ed7f0dab5ef 2ed7f0dab5ef 2ed7f0dab5ef 2ed7f0dab5ef 2ed7f0dab5ef a362783e3bec a362783e3bec 2ed7f0dab5ef f0b8120281b9 f0b8120281b9 f0b8120281b9 f0b8120281b9 f0b8120281b9 f0b8120281b9 f0b8120281b9 f0b8120281b9 f0b8120281b9 f0b8120281b9 f0b8120281b9 f0b8120281b9 f0b8120281b9 | from itertools import chain
import unittest
from unittest import TestCase
import os
from sgfParser import strRowCol
from sgfParser.collection import Collection
from sgfParser.property import Property
dataDir=os.path.join(os.path.dirname(__file__), "data")
class TestUtils(TestCase):
def testTextPos(self):
s="abc\ndef\rgh\r\nij\n\rklmn"
rc=[
[1,2,3,4],
[1,2,3,4],
[1,2,3,4],
[1,2,3], [1], # don't care about LFCR, we unicode now
[1,2,3,4]
]
res=chain((r+1,c) for (r,row) in enumerate(rc) for c in row)
for (i,(r,c)) in zip(range(len(s)+1), res):
self.assertEqual(strRowCol(s, i), (r, c))
class TestProperty(TestCase):
def testName(self):
with self.assertRaises(AssertionError):
Property.create("[99]",0)
with self.assertRaises(AssertionError):
Property.create("99[99]",0)
i,prop=Property.create("MN[99]",0)
self.assertNotEqual((i,prop), (0,None))
self.assertEqual((i,prop.name), (6,"MN"))
class TestCollection(TestCase):
def testSubtrees(self):
c=Collection("""
(;B[aa]
(;W[ab]PB[Some Black]PW[Some White];B[ac])
(;W[bb]PB[Other Black]PW[Other White])
)""")
games=list(c.listGames())
self.assertEqual(len(games),2)
self.assertRegex(games[0].export(), r"^\(;B\[aa];(PB\[Some Black]|PW\[Some White]|W\[ab]){3};B\[ac]\)$")
self.assertRegex(games[1].export(), r"^\(;B\[aa];(PB\[Other Black]|PW\[Other White]|W\[bb]){3}\)$")
def testEmptySgf(self):
Collection("(;)")
def testSimpleSgf(self):
with open(os.path.join(dataDir, "simple.sgf")) as f:
Collection(f.read())
def testComplexSgf(self):
with open(os.path.join(dataDir, "kogos.sgf")) as f:
Collection(f.read())
if __name__ == '__main__':
unittest.main()
|