Skip to content

Commit aa781bb

Browse files
committed
Update tests to fetch OFMX data
1 parent 32c772c commit aa781bb

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
python-version: "3.12"
1515
- name: Install
1616
run: pip install -e .
17+
- name: Fetch OFMX sample data
18+
run: scripts/fetch_ofmx.sh
1719
- name: Unit tests
1820
run: python -m unittest discover -s tests
1921

tests/test_cli.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@
88

99
from ofmx2pgsql import cli
1010

11+
DATA_ROOT = Path("data/ofmx_lk/isolated")
12+
OFMX_FILE = DATA_ROOT / "ofmx_lk.ofmx"
13+
SHAPES_FILE = DATA_ROOT / "ofmx_lk_ofmShapeExtension.xml"
1114

1215
class CliTests(unittest.TestCase):
1316
def test_build_parser_returns_argparse_parser(self) -> None:
1417
parser = cli.build_parser()
1518
self.assertIsInstance(parser, argparse.ArgumentParser)
1619

20+
@unittest.skipUnless(DATA_ROOT.exists(), "OFMX sample data not available")
1721
def test_scan_flag_runs(self) -> None:
18-
exit_code = cli.main(["scan", "ofmx_lk/isolated"])
22+
exit_code = cli.main(["scan", str(DATA_ROOT)])
1923
self.assertEqual(exit_code, 0)
2024

2125
def test_apply_config_populates_defaults(self) -> None:
2226
with tempfile.NamedTemporaryFile("w", delete=False) as handle:
2327
handle.write(
2428
"[ofmx2pgsql]\n"
2529
"dsn = postgresql://user:pass@localhost:5432/ofmx\n"
26-
"ofmx = ofmx_lk/isolated/ofmx_lk.ofmx\n"
27-
"shapes = ofmx_lk/isolated/ofmx_lk_ofmShapeExtension.xml\n"
30+
"ofmx = data/ofmx_lk/isolated/ofmx_lk.ofmx\n"
31+
"shapes = data/ofmx_lk/isolated/ofmx_lk_ofmShapeExtension.xml\n"
2832
"apply_migrations = true\n"
2933
"schema = custom_schema\n"
3034
)
@@ -35,10 +39,10 @@ def test_apply_config_populates_defaults(self) -> None:
3539
args = parser.parse_args(["--config", str(config_path), "import"])
3640
cli._apply_config(args)
3741
self.assertEqual(args.dsn, "postgresql://user:pass@localhost:5432/ofmx")
38-
self.assertEqual(args.ofmx, Path("ofmx_lk/isolated/ofmx_lk.ofmx"))
42+
self.assertEqual(args.ofmx, OFMX_FILE)
3943
self.assertEqual(
4044
args.shapes,
41-
Path("ofmx_lk/isolated/ofmx_lk_ofmShapeExtension.xml"),
45+
SHAPES_FILE,
4246
)
4347
self.assertTrue(args.apply_migrations)
4448
self.assertEqual(args.schema, "custom_schema")

tests/test_parser.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,40 @@
66

77
from ofmx2pgsql import parser
88

9+
DATA_ROOT = Path("data/ofmx_lk/isolated")
10+
OFMX_FILE = DATA_ROOT / "ofmx_lk.ofmx"
11+
SHAPES_FILE = DATA_ROOT / "ofmx_lk_ofmShapeExtension.xml"
12+
HAS_DATA = OFMX_FILE.exists() and SHAPES_FILE.exists()
913

1014
class ParserTests(unittest.TestCase):
15+
@unittest.skipUnless(DATA_ROOT.exists(), "OFMX sample data not available")
1116
def test_iter_ofmx_files_finds_sample(self) -> None:
12-
paths = list(parser.iter_ofmx_files(Path("ofmx_lk/isolated")))
13-
self.assertEqual(paths, [Path("ofmx_lk/isolated/ofmx_lk.ofmx")])
17+
paths = list(parser.iter_ofmx_files(DATA_ROOT))
18+
self.assertEqual(paths, [OFMX_FILE])
1419

20+
@unittest.skipUnless(HAS_DATA, "OFMX sample data not available")
1521
def test_iter_airports_reads_first_airport(self) -> None:
16-
airports = parser.iter_airports(Path("ofmx_lk/isolated/ofmx_lk.ofmx"))
22+
airports = parser.iter_airports(OFMX_FILE)
1723
first = next(airports)
1824
self.assertEqual(first.code_id, "LKCB")
1925
self.assertEqual(first.name, "CHEB")
2026

27+
@unittest.skipUnless(HAS_DATA, "OFMX sample data not available")
2128
def test_iter_waypoints_reads_first_point(self) -> None:
22-
waypoints = parser.iter_waypoints(Path("ofmx_lk/isolated/ofmx_lk.ofmx"))
29+
waypoints = parser.iter_waypoints(OFMX_FILE)
2330
first = next(waypoints)
2431
self.assertEqual(first.code_id, "ENITA")
2532

33+
@unittest.skipUnless(HAS_DATA, "OFMX sample data not available")
2634
def test_iter_navaids_reads_first_vor(self) -> None:
27-
navaids = parser.iter_navaids(Path("ofmx_lk/isolated/ofmx_lk.ofmx"))
35+
navaids = parser.iter_navaids(OFMX_FILE)
2836
first = next(navaids)
2937
self.assertEqual(first.navaid_type, "VOR")
3038
self.assertEqual(first.code_id, "OKG")
3139

40+
@unittest.skipUnless(HAS_DATA, "OFMX sample data not available")
3241
def test_iter_airspace_shapes_reads_sample(self) -> None:
33-
shapes = parser.iter_airspace_shapes(
34-
Path("ofmx_lk/isolated/ofmx_lk_ofmShapeExtension.xml")
35-
)
42+
shapes = parser.iter_airspace_shapes(SHAPES_FILE)
3643
first = next(shapes)
3744
self.assertIsNotNone(first.ofmx_id)
3845
self.assertGreater(len(first.positions), 3)

0 commit comments

Comments
 (0)