aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_config.py4
-rw-r--r--tests/test_library.py16
-rw-r--r--tests/test_scene.py32
3 files changed, 52 insertions, 0 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index 72ed0f6..d88b534 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -88,3 +88,7 @@ class ConfigTest(unittest.TestCase):
def test_empty_library_root_is_fatal(self):
with self.assertRaisesRegex(Error, "empty library root"):
library_roots([""], self.cfg)
+
+ def test_unexpandable_home_is_fatal(self):
+ with self.assertRaisesRegex(Error, "cannot expand library root"):
+ library_roots(["~nosuchuser_generat3d/lib"], self.cfg)
diff --git a/tests/test_library.py b/tests/test_library.py
index 84fa3cc..7e06ca4 100644
--- a/tests/test_library.py
+++ b/tests/test_library.py
@@ -89,3 +89,19 @@ class LibraryTest(unittest.TestCase):
p = Path(self.tmp.name) / "x.duf"
p.write_text(json.dumps({"x": 1}))
self.assertEqual(read_dson(p), {"x": 1})
+
+
+class ReadDsonCrashTest(unittest.TestCase):
+ def read(self, data):
+ with tempfile.TemporaryDirectory() as d:
+ p = Path(d) / "x.dsf"
+ p.write_bytes(data)
+ read_dson(p)
+
+ def test_corrupt_gzip_is_error(self):
+ with self.assertRaises(Error):
+ self.read(b"\x1f\x8b\x08\x00" + b"\xff" * 20)
+
+ def test_deep_nesting_is_error(self):
+ with self.assertRaises(Error):
+ self.read(b"[" * 200000)
diff --git a/tests/test_scene.py b/tests/test_scene.py
index 76a28b6..056f3e1 100644
--- a/tests/test_scene.py
+++ b/tests/test_scene.py
@@ -233,3 +233,35 @@ class SceneTest(unittest.TestCase):
"output": "hip:/data/Test/Fig2/Fig2.dsf#hip?center_point/y",
"operations": [{"op": "push", "val": 1}]}]})
self.assertEqual(len(scene.graph.formulas["hip:hip?center_point/y"]), 1)
+
+ def raw_fig2(self, text):
+ """Load the temp figure from raw JSON text (for literals json.dumps rejects)."""
+ root = self.dir / "raw"
+ p = root / "data/Test/Fig2/Fig2.dsf"
+ p.parent.mkdir(parents=True)
+ p.write_text(text)
+ nodes = [{"id": "Fig2", "url": "/data/Test/Fig2/Fig2.dsf#Fig2", "name": "Fig2"}]
+ return load_quiet(self.duf({"nodes": nodes}), [root])
+
+ def test_bone_value_not_a_number(self):
+ xyz = [{"id": "x", "value": "a"}]
+ with self.assertRaisesRegex(Error, "hip: center_point is not a finite number"):
+ self.fig2(hip_extra={"center_point": xyz})
+
+ def test_bone_value_not_finite(self):
+ text = json.dumps(self.fig_doc()).replace(
+ '"orientation": [{"id": "x", "value": 0}', '"orientation": [{"id": "x", "value": 1e400}', 1)
+ self.assertIn("1e400", text)
+ with self.assertRaisesRegex(Error, "is not a finite number"):
+ self.raw_fig2(text)
+
+ def test_modifier_value_nan(self):
+ root = self.root(self.MORPHS + "Nan.dsf", self.morph_doc(self.mod("Nan")))
+ p = root / (self.MORPHS + "Nan.dsf")
+ p.write_text(p.read_text().replace('"value": 0', '"value": NaN'))
+ with self.assertRaisesRegex(Error, "Nan: value is not a finite number"):
+ load_quiet(DATA / "scene.duf", [root])
+
+ def test_bad_vertices(self):
+ with self.assertRaisesRegex(Error, "bad vertices"):
+ self.fig2(verts=[[0, 0], [1, 0], [0, 1]])