From 8b0b7bec7427028d5ec0e0146dc2126bcc4ecabc Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Fri, 12 Apr 2024 17:41:29 -0400 Subject: [PATCH] add test for __init__.py (version check branch) --- ntclient/__init__.py | 2 +- tests/test_init.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/test_init.py diff --git a/ntclient/__init__.py b/ntclient/__init__.py index bb1d088..21e6d09 100644 --- a/ntclient/__init__.py +++ b/ntclient/__init__.py @@ -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 index 0000000..5483b88 --- /dev/null +++ b/tests/test_init.py @@ -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", + ) -- 2.52.0