2 new revisions:
Revision: b4e713c50653
Branch: default
Author: gbtami
Date: Sun Jan 4 21:32:34 2015 UTC
Log: Fixed pgn unit test
https://code.google.com/p/pychess/source/detail?r=b4e713c50653
Revision: 2b60768faaa9
Branch: default
Author: gbtami
Date: Sun Jan 4 21:47:26 2015 UTC
Log: Fixed database unit test with Python3
https://code.google.com/p/pychess/source/detail?r=2b60768faaa9
==============================================================================
Revision: b4e713c50653
Branch: default
Author: gbtami
Date: Sun Jan 4 21:32:34 2015 UTC
Log: Fixed pgn unit test
https://code.google.com/p/pychess/source/detail?r=b4e713c50653
Modified:
/testing/pgn.py
=======================================
--- /testing/pgn.py Tue Dec 30 12:55:47 2014 UTC
+++ /testing/pgn.py Sun Jan 4 21:32:34 2015 UTC
@@ -1,4 +1,6 @@
from __future__ import print_function
+
+import re
import sys
import unittest
@@ -16,25 +18,36 @@
matches = [m[MOVE-1] for m in pattern.findall(moves)]
self.assertEqual(' '.join(matches), ' '.join(moves.split()))
-def create_test(lines, result):
+def create_test(o, n):
def test_expected(self):
- for orig, new in zip(lines.split(), result.split()):
+ for orig, new in zip(o.split(), n.split()):
# Seems most .PGN unnecessary contains unambiguous notation
# when second move candidate is invalid (leaves king in check)
# f.e.: 1.e4 e5 2.d4 Nf6 3.Nc3 Bb4 Nge2
if len(orig) == len(new)+1 and orig[0] == new[0] and orig[2:]
== new[1:]:
continue
- if orig[-1] in "?!" and new[-1] not in "?!":
+ elif orig[-1] in "?!" and new[-1] not in "?!":
# pgn export format uses nag
break
- elif orig == "0-0" or orig == "0-0-0":
+
+ elif (orig == "0-0" and new == "O-O") or (orig == "0-0-0" and
new == "O-O-O"):
continue
self.assertEqual(orig, new)
return test_expected
+def normalize(text):
+ text = text.splitlines()
+ text = " ".join(text)
+ text = text.replace('. ', '. ').replace('. ', '. ')
+ text = text.replace(' )', ')').replace(' )', ')')
+ text = text.replace('( ', '(').replace('( ', '(')
+ text = text.replace(' }', '}').replace(' }', '}')
+ text = text.replace('{ ', '{').replace('{ ', '{')
+ return text
+
filenames = ("atomic", "chess960rwch", "world_matches", "zh2200plus")
for filename in filenames:
@@ -44,27 +57,16 @@
print("%s/%s" % (i+1, len(pgnfile.games)))
if i > 100:
break
+
+ orig = normalize(game[1])
+
model = pgnfile.loadToModel(i)
- result = []
- walk(model.boards[0].board, result, model)
- result = " ".join(result)
- status = reprResult[model.status]
-
- lines = game[1].replace('. ', '. ').replace('. ', '. ')
- lines = lines.replace('\r\n', ' ')
- lines = lines.replace(' )', ')').replace(' )', ')')
- lines = lines.replace('( ', '(').replace('( ', '(')
- lines = lines.replace(' }', '}').replace(' }', '}')
- lines = lines.replace('{ ', '{').replace('{ ', '{')
- lines = lines.replace('(\r\n', '(').replace('\r\n)', ')')
- lines = lines.replace('{\r\n', '{').replace('\r\n}', '}')
- lines = lines.splitlines()
- lines = [line.strip() for line in lines]
- lines = ' '.join(lines)
- result = "%s %s" % (result, status)
+ new = []
+ walk(model.boards[0].board, new, model)
+ new = normalize(" ".join(new))
- # create a new test method
- test_method = create_test(lines, result)
+ # create test method
+ test_method = create_test(orig, new)
# change it's name to be unique in PgnTestCase class
test_method.__name__ = 'test_%s_%d' % (filename, i+1)
==============================================================================
Revision: 2b60768faaa9
Branch: default
Author: gbtami
Date: Sun Jan 4 21:47:26 2015 UTC
Log: Fixed database unit test with Python3
https://code.google.com/p/pychess/source/detail?r=2b60768faaa9
Modified:
/lib/pychess/Savers/database.py
/testing/database.py
=======================================
--- /lib/pychess/Savers/database.py Tue Dec 30 12:55:47 2014 UTC
+++ /lib/pychess/Savers/database.py Sun Jan 4 21:47:26 2015 UTC
@@ -47,11 +47,11 @@
if not name:
return None
- s = select([
table.c.id],
table.c.name==name.decode("utf_8"))
+ s = select([
table.c.id],
table.c.name==name)
result = conn.execute(s)
id_ = result.scalar()
if id_ is None:
- result =
conn.execute(table.insert().values(name=name.decode("utf_8")))
+ result = conn.execute(table.insert().values(name=name))
id_ = result.inserted_primary_key[0]
return id_
@@ -93,7 +93,7 @@
'annotator_id': annotator_id,
'collection_id': collection_id,
'movelist': movelist.tostring(),
- 'comments': "|".join(comments).decode("utf_8"),
+ 'comments': "|".join(comments),
}
if hasattr(model, "game_id") and model.game_id is not None:
=======================================
--- /testing/database.py Tue Dec 30 12:55:47 2014 UTC
+++ /testing/database.py Sun Jan 4 21:47:26 2015 UTC
@@ -16,6 +16,8 @@
def __repr__(self):
return
self.name
+pgnfile = pgnload(open('gamefiles/annotated.pgn'))
+
class DbTestCase(unittest.TestCase):
def setUp(self):
@@ -26,7 +28,6 @@
def test_databas(self):
"""Testing database save-load"""
- pgnfile = pgnload(open('gamefiles/annotated.pgn'))
model = pgnfile.loadToModel(0)
p0, p1 = pgnfile.get_player_names(0)