File tree Expand file tree Collapse file tree 3 files changed +21
-5
lines changed
Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -21,9 +21,11 @@ def parse_map(file: Path) -> TiledMap:
2121 # The type ignores are because mypy for some reason thinks those functions return Any
2222 if parser == "tmx" :
2323 return tmx_map_parse (file ) # type: ignore
24- elif parser == "json" :
25- return json_map_parse (file ) # type: ignore
2624 else :
27- raise UnknownFormat (
28- "Unknown Map Format, please use either the TMX or JSON format."
29- )
25+ try :
26+ return json_map_parse (file ) # type: ignore
27+ except ValueError :
28+ raise UnknownFormat (
29+ "Unknown Map Format, please use either the TMX or JSON format. "
30+ "This message could also mean your map file is invalid or corrupted."
31+ )
Original file line number Diff line number Diff line change 1+ |thisissomegarbageformat||||ohmylookhowbaditis||thiswillcertainlybreakthigns|||
Original file line number Diff line number Diff line change 1+ import os
2+ from pathlib import Path
3+
4+ import pytest
5+
6+ from pytiled_parser import UnknownFormat , parse_map
7+
8+ TESTS_DIR = Path (os .path .dirname (os .path .abspath (__file__ )))
9+ MAP_FILE = TESTS_DIR / "test_data/invalid_format.garbage"
10+
11+ def test_map_invalid_format ():
12+ with pytest .raises (UnknownFormat ) as e :
13+ parse_map (MAP_FILE )
You can’t perform that action at this time.
0 commit comments