From ed1dea2639b1191421de3986483aedcc14067a12 Mon Sep 17 00:00:00 2001 From: godosa Date: Wed, 7 Oct 2026 00:01:14 +0200 Subject: worldhistory: initial public history --- tests/test_cli.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/test_cli.py (limited to 'tests/test_cli.py') diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..e5a464c --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,44 @@ +import json +import tempfile +import unittest +from pathlib import Path + +import numpy as np + +from tests.helpers import globe_world +from tests.test_engine import small_setup +from worldhistory.cli import main +from worldhistory.engine import Engine +from worldhistory.preview import compare, preview + + +class PreviewTest(unittest.TestCase): + def test_preview_and_compare(self): + with tempfile.TemporaryDirectory() as d: + a, b = Path(d) / "a", Path(d) / "b" + w, h, races = small_setup(1) + Engine(w, h, races).run(a) + w2, h2, races2 = small_setup(2) + Engine(w2, h2, races2).run(b) + files = preview(a, world=w) + names = {p.name for p in files} + self.assertIn("race_y0060.png", names) + self.assertIn("chart.png", names) + self.assertIn("contact.png", names) + same = compare(a, a, world=w) + self.assertEqual(same["agreement"], 1.0) + diff = compare(a, b, world=w, out=Path(d) / "cmp") + self.assertLessEqual(diff["agreement"], 1.0) + self.assertTrue((Path(d) / "cmp" / "compare.png").exists()) + + +class CliTest(unittest.TestCase): + def test_check_config_errors(self): + with tempfile.TemporaryDirectory() as d: + (Path(d) / "races").mkdir() + (Path(d) / "history.toml").write_text("[run]\nyers = 5\n") + (Path(d) / "races" / "a.toml").write_text('id = "a"\n[demography]\ndensity = 1\ngrowth = 0.1\n' + '[habitat]\nterms = [{ p = "land", w = 1 }]\n') + self.assertEqual(main(["check-config", d]), 1) + (Path(d) / "history.toml").write_text("[run]\nyears = 5\n") + self.assertEqual(main(["check-config", d]), 0) -- cgit