"""Unit tests for scripts/smoke_import.py's version checks.""" import importlib.util import pathlib import pytest SCRIPT = pathlib.Path(__file__).resolve().parent.parent / "scripts" / "smoke_import.py" spec = importlib.util.spec_from_file_location("smoke_import", SCRIPT) smoke_import = importlib.util.module_from_spec(spec) spec.loader.exec_module(smoke_import) @pytest.mark.parametrize( "version", [ "0.0.0", "0.0.1.dev3+gabc1234", # release-branch-semver with no tags reachable (shallow clone): "0.1.0.dev1+g6bd717f23", ], ) def test_tagless_versions_are_rejected(version): with pytest.raises(SystemExit, match="no tags"): smoke_import.check_version(version, expected=None) @pytest.mark.parametrize("version", ["0.2.3", "0.3.0.dev23+gc361b286c", "1.0.0"]) def test_tag_derived_versions_pass(version): smoke_import.check_version(version, expected=None) def test_expected_version_must_match_exactly(): with pytest.raises(SystemExit, match="expected version 0.2.3"): smoke_import.check_version("0.2.3.dev1", expected="0.2.3")