Skip to main content

Make the tests for “failing to write” more specific

ID
407aff3
date
2024-08-24 08:55:16+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
12c9255
message
Make the tests for "failing to write" more specific
changed files
1 file, 9 additions, 1 deletion

Changed files

tests/test_javascript.py (6224) → tests/test_javascript.py (6520)

diff --git a/tests/test_javascript.py b/tests/test_javascript.py
index a83f910..9a53181 100644
--- a/tests/test_javascript.py
+++ b/tests/test_javascript.py
@@ -62,9 +62,17 @@ class TestWriteJs:
     def test_fails_if_cannot_write_file(self) -> None:
         red_pentagon = {"sides": 5, "colour": "red"}
 
-        with pytest.raises(OSError):
+        with pytest.raises(FileExistsError):
             write_js("/", value=red_pentagon, varname="redPentagon")
 
+    def test_fails_if_target_is_folder(self, tmp_path: pathlib.Path) -> None:
+        assert tmp_path.is_dir()
+
+        red_pentagon = {"sides": 5, "colour": "red"}
+
+        with pytest.raises(IsADirectoryError):
+            write_js(tmp_path, value=red_pentagon, varname="redPentagon")
+
     def test_creates_parent_directory(self, tmp_path: pathlib.Path) -> None:
         js_path = tmp_path / "1/2/3/shape.js"
         red_pentagon = {"sides": 5, "colour": "red"}