]> Nutra Git (v2) - nutratech/cli.git/commitdiff
add test for __init__.py (version check branch)
authorShane Jaroch <chown_tee@proton.me>
Fri, 12 Apr 2024 21:41:29 +0000 (17:41 -0400)
committerShane Jaroch <chown_tee@proton.me>
Fri, 12 Apr 2024 21:41:29 +0000 (17:41 -0400)
ntclient/__init__.py
tests/test_init.py [new file with mode: 0644]

index bb1d0886858836add28e77628cd0cbcbce9c3015..21e6d0904b8520b796c2d9acd41a393cef33b962 100644 (file)
@@ -45,7 +45,7 @@ PY_MIN_STR = ".".join(str(x) for x in PY_MIN_VER)
 PY_SYS_STR = ".".join(str(x) for x in PY_SYS_VER)
 if PY_SYS_VER < PY_MIN_VER:
     # TODO: make this testable with: `class CliConfig`?
-    raise RuntimeError(  # pragma: no cover
+    raise RuntimeError(
         "ERROR: %s requires Python %s or later to run" % (__title__, PY_MIN_STR),
         "HINT:  You're running Python %s" % PY_SYS_STR,
     )
diff --git a/tests/test_init.py b/tests/test_init.py
new file mode 100644 (file)
index 0000000..5483b88
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""
+Created on Fri Apr 12 17:30:01 2024
+
+@author: shane
+"""
+from unittest.mock import patch
+
+import pytest
+
+
+@patch("sys.version_info", (3, 4, 0))
+def test_archaic_python_version_raises_runtime_error() -> None:
+    """Test that the correct error is raised when the Python version is too low."""
+    with pytest.raises(RuntimeError) as exc_info:
+        # pylint: disable=import-outside-toplevel
+        from ntclient import PY_MIN_VER, PY_SYS_VER, __title__
+
+        assert __title__ == "nutra"
+        assert PY_MIN_VER == (3, 4, 3)
+        assert PY_SYS_VER == (3, 4, 0)
+
+    assert "ERROR: nutra requires Python 3.4.3 or later to run" in str(exc_info.value)
+    assert "HINT:  You're running Python 3.4.0" in str(exc_info.value)
+    assert exc_info.type == RuntimeError
+    assert exc_info.value.args == (
+        "ERROR: nutra requires Python 3.4.3 or later to run",
+        "HINT:  You're running Python 3.4.0",
+    )