diff options
| author | Danilo M. <danix@danix.xyz> | 2026-10-28 10:38:06 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-10-28 10:38:06 +0100 |
| commit | 688b945b206d94e4176f69f2dc8bdcb810061b36 (patch) | |
| tree | 4fce9159c107331547d8e2e96f686d5fb1c9efea /tests/test_cli.py | |
| parent | 3a2884f1f056922758bf9fe790dfd05a3843055d (diff) | |
| download | generat3D-688b945b206d94e4176f69f2dc8bdcb810061b36.tar.gz generat3D-688b945b206d94e4176f69f2dc8bdcb810061b36.zip | |
Add command line interface
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/test_cli.py')
| -rw-r--r-- | tests/test_cli.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..3177997 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,64 @@ +# generat3D - evaluate Daz DSON scenes and write .dbz files +# Copyright (C) 2026 Danilo M. <danix@danix.xyz> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import contextlib +import gzip +import io +import json +import shutil +import tempfile +import unittest +from pathlib import Path + +from generat3d.__main__ import main + +DATA = Path(__file__).parent / "data" + + +class CliTest(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.dir = Path(self.tmp.name) + self.duf = self.dir / "scene.duf" + shutil.copy(DATA / "scene.duf", self.duf) + + def tearDown(self): + self.tmp.cleanup() + + def run_main(self, *args): + out, err = io.StringIO(), io.StringIO() + with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err): + code = main(list(args)) + return code, out.getvalue(), err.getvalue() + + def test_default_output_beside_scene(self): + code, out, _ = self.run_main(str(self.duf), "-L", str(DATA / "lib")) + self.assertEqual((code, out), (0, "")) + doc = json.loads(gzip.decompress((self.dir / "scene.dbz").read_bytes())) + self.assertEqual(doc["figures"][0]["name"], "Fig") + + def test_explicit_output(self): + target = self.dir / "other.dbz" + code, _, _ = self.run_main(str(self.duf), "-L", str(DATA / "lib"), "-o", str(target)) + self.assertEqual(code, 0) + self.assertTrue(target.exists()) + + def test_error_exits_1_without_output(self): + code, _, err = self.run_main(str(self.duf), "-L", str(self.dir / "nope")) + self.assertEqual(code, 1) + self.assertIn("generat3d: error: library root not found", err) + self.assertFalse((self.dir / "scene.dbz").exists()) |
