Skip to content

Commit 0e7fabc

Browse files
committed
Test reading PGN with UTF-8 BOM
1 parent 5826ef5 commit 0e7fabc

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

data/pgn/utf8-bom.pgn

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[Event "A"]
2+
[Site "?"]
3+
[Date "2024.04.25"]
4+
[Round "?"]
5+
[White "White vs 1...c5"]
6+
[Black "?"]
7+
[Result "*"]
8+
[ECO "A00"]
9+
[PlyCount "0"]
10+
[SourceVersionDate "2024.04.25"]
11+
12+
*
13+
14+
[Event "B"]
15+
[Site "?"]
16+
[Date "2024.04.25"]
17+
[Round "?"]
18+
[White "White vs 1...c5"]
19+
[Black "?"]
20+
[Result "*"]
21+
[ECO "A00"]
22+
[PlyCount "0"]
23+
[SourceVersionDate "2024.04.25"]
24+
25+
*
26+

test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,6 +2947,18 @@ def end_variation(self):
29472947
game = chess.pgn.read_game(io.StringIO(pgn)).accept(BlackVariationsOnly())
29482948
self.assertEqual(game.accept(chess.pgn.StringExporter(headers=False)), expected_pgn)
29492949

2950+
def test_utf8_bom(self):
2951+
not_utf8_sig = "utf-8"
2952+
with open("data/pgn/utf8-bom.pgn", encoding=not_utf8_sig) as pgn:
2953+
game = chess.pgn.read_game(pgn)
2954+
self.assertEqual(game.headers["Event"], "A")
2955+
2956+
game = chess.pgn.read_game(pgn)
2957+
self.assertEqual(game.headers["Event"], "B")
2958+
2959+
game = chess.pgn.read_game(pgn)
2960+
self.assertEqual(game, None)
2961+
29502962

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

0 commit comments

Comments
 (0)