aboutsummaryrefslogtreecommitdiffziptar.gz
path: root/tests/test_cli.py
diff options
context:
space:
mode:
authorgodosa <godosa@godosa.eu>2026-10-07 00:01:14 +0200
committergodosa <godosa@godosa.eu>2026-10-07 00:01:14 +0200
commited1dea2639b1191421de3986483aedcc14067a12 (patch)
tree0118c6e119a84f1a9433ed0a304c8be1c9098463 /tests/test_cli.py
downloadworldhistory-ed1dea2639b1191421de3986483aedcc14067a12.tar.gz
worldhistory-ed1dea2639b1191421de3986483aedcc14067a12.zip
worldhistory: initial public history
Diffstat (limited to 'tests/test_cli.py')
-rw-r--r--tests/test_cli.py44
1 files changed, 44 insertions, 0 deletions
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)