Add a couple of tests for appending to incorrect paths
- ID
5caf656- date
2024-08-24 09:11:40+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
ca37b5e- message
Add a couple of tests for appending to incorrect paths- changed files
1 file, 28 additions
Changed files
tests/test_javascript.py (6522) → tests/test_javascript.py (7664)
diff --git a/tests/test_javascript.py b/tests/test_javascript.py
index 482181f..d33c509 100644
--- a/tests/test_javascript.py
+++ b/tests/test_javascript.py
@@ -126,6 +126,20 @@ class TestAppendToArray:
with pytest.raises(ValueError, match="does not look like an array"):
append_to_js_array(js_path, value=["yellow"])
+ def test_error_if_path_doesnt_exist(self, js_path: pathlib.Path) -> None:
+ """
+ Appending to the path of a non-existent file throws FileNotFoundError.
+ """
+ with pytest.raises(FileNotFoundError):
+ append_to_js_array(js_path, value="alex")
+
+ def test_error_if_path_is_dir(self, tmp_path: pathlib.Path) -> None:
+ """
+ Appending to a path which is a directory throws IsADirectoryError.
+ """
+ with pytest.raises(IsADirectoryError):
+ append_to_js_array(tmp_path, value="alex")
+
class TestAppendToObject:
@pytest.mark.parametrize(
@@ -156,6 +170,20 @@ class TestAppendToObject:
with pytest.raises(ValueError, match="does not look like an object"):
append_to_js_object(js_path, key="sideLengths", value=[5, 5, 6, 6, 6])
+ def test_error_if_path_doesnt_exist(self, js_path: pathlib.Path) -> None:
+ """
+ Appending to the path of a non-existent file throws FileNotFoundError.
+ """
+ with pytest.raises(FileNotFoundError):
+ append_to_js_object(js_path, key="name", value="alex")
+
+ def test_error_if_path_is_dir(self, tmp_path: pathlib.Path) -> None:
+ """
+ Appending to a path which is a directory throws IsADirectoryError.
+ """
+ with pytest.raises(IsADirectoryError):
+ append_to_js_object(tmp_path, key="name", value="alex")
+
class TestRoundTrip:
@pytest.mark.parametrize(