Skip to content

Commit

Permalink
Test reading PGN with UTF-8 BOM
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Sep 27, 2024
1 parent 5826ef5 commit 0e7fabc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
26 changes: 26 additions & 0 deletions data/pgn/utf8-bom.pgn
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[Event "A"]
[Site "?"]
[Date "2024.04.25"]
[Round "?"]
[White "White vs 1...c5"]
[Black "?"]
[Result "*"]
[ECO "A00"]
[PlyCount "0"]
[SourceVersionDate "2024.04.25"]

*

[Event "B"]
[Site "?"]
[Date "2024.04.25"]
[Round "?"]
[White "White vs 1...c5"]
[Black "?"]
[Result "*"]
[ECO "A00"]
[PlyCount "0"]
[SourceVersionDate "2024.04.25"]

*

12 changes: 12 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2947,6 +2947,18 @@ def end_variation(self):
game = chess.pgn.read_game(io.StringIO(pgn)).accept(BlackVariationsOnly())
self.assertEqual(game.accept(chess.pgn.StringExporter(headers=False)), expected_pgn)

def test_utf8_bom(self):
not_utf8_sig = "utf-8"
with open("data/pgn/utf8-bom.pgn", encoding=not_utf8_sig) as pgn:
game = chess.pgn.read_game(pgn)
self.assertEqual(game.headers["Event"], "A")

game = chess.pgn.read_game(pgn)
self.assertEqual(game.headers["Event"], "B")

game = chess.pgn.read_game(pgn)
self.assertEqual(game, None)


@unittest.skipIf(sys.platform == "win32" and (3, 8, 0) <= sys.version_info < (3, 8, 1), "https://bugs.python.org/issue34679")
class EngineTestCase(unittest.TestCase):
Expand Down

0 comments on commit 0e7fabc

Please sign in to comment.