def test_database_save_load(self): """Testing database save-load""" game_model = pgnfile0.loadToModel(0) p0, p1 = pgnfile0.get_player_names(0) game_model.players = (TestPlayer(p0), TestPlayer(p1)) in_game = [] walk(game_model.boards[0].board, in_game, game_model) in_game = " ".join(in_game) in_bb_list = [board.board.friends for board in game_model.boards] save(None, game_model) db = load(None) result = self.engine.execute(db.select) db.games = result.fetchall() print("%s selected" % len(db.games)) game_model = db.loadToModel(0) out_game = [] walk(game_model.boards[0].board, out_game, game_model) out_game = " ".join(out_game) out_bb_list = [board.board.friends for board in game_model.boards] self.assertEqual(in_game, out_game) self.assertEqual(in_bb_list, out_bb_list)
def pgn_test(self, name): pgnfile = load(protoopen("gamefiles/%s.pgn" % name)) pgnfile.limit = 1000 pgnfile.init_tag_database() games, plys = pgnfile.get_records() for i, game in enumerate(games): print("%s/%s" % (i + 1, pgnfile.get_count())) orig_moves_text = normalize(pgnfile.get_movetext(game)) model = pgnfile.loadToModel(game) print(model.tags["Site"]) new_moves = [] walk(model.boards[0].board, new_moves, model) new_moves_text = normalize(" ".join(new_moves)) for orig, new in zip(orig_moves_text.split(), new_moves_text.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 elif orig[-1] in "?!" and new[-1] not in "?!": # pgn export format uses nag break elif (orig == "0-0" and new == "O-O") or (orig == "0-0-0" and new == "O-O-O"): continue self.assertEqual(orig, new) pgnfile.close()
def test_databas(self): """Testing database save-load""" model = pgnfile.loadToModel(0) p0, p1 = pgnfile.get_player_names(0) model.players = (TestPlayer(p0), TestPlayer(p1)) in_game = [] walk(model.boards[0].board, in_game, model) in_game = " ".join(in_game) save(None, model) db = load(None) result = self.conn.execute(db.select) db.games = result.fetchall() print("%s selected" % len(db.games)) model = db.loadToModel(0) out_game = [] walk(model.boards[0].board, out_game, model) out_game = " ".join(out_game) self.assertEqual(in_game, out_game)
filenames = ("atomic", "chess960rwch", "world_matches", "zh") for filename in filenames: print("Creating test methods for %s" % filename) pgnfile = load(protoopen('gamefiles/%s.pgn' % filename)) pgnfile.get_records() for i, game in enumerate(pgnfile.games): print("%s/%s" % (i + 1, len(pgnfile.games))) if i > 100: break orig = normalize(pgnfile.get_movetext(game)) model = pgnfile.loadToModel(game) new = [] walk(model.boards[0].board, new, model) new = normalize(" ".join(new)) # 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) test_method.__doc__ = "Pgn read-write %s" % ' '.join( test_method.__name__.split('_')) # monkey patch PgnTestCase class, adding the new test method setattr(PgnTestCase, test_method.__name__, test_method) if __name__ == '__main__': unittest.main()
filenames = ("atomic", "chess960rwch", "world_matches", "zh2200plus") for filename in filenames: print("Creating test methods for %s" % filename) pgnfile = load(open('gamefiles/%s.pgn' % filename)) for i, game in enumerate(pgnfile.games): print("%s/%s" % (i + 1, len(pgnfile.games))) if i > 100: break orig = normalize(game[1]) model = pgnfile.loadToModel(i) new = [] walk(model.boards[0].board, new, model) new = normalize(" ".join(new)) # 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) test_method.__doc__ = "Pgn read-write %s" % ' '.join(test_method.__name__.split('_')) # monkey patch PgnTestCase class, adding the new test method setattr(PgnTestCase, test_method.__name__, test_method) if __name__ == '__main__': unittest.main()