|
13 | 13 | import glob |
14 | 14 | import sys |
15 | 15 |
|
| 16 | +from unittest.mock import MagicMock |
16 | 17 | from ci_tools.parsing import ParsedSetup |
17 | | - |
18 | | -# Import the functions we want to test from the verify modules |
19 | | -tox_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..", "tox")) |
20 | | -if tox_path not in sys.path: |
21 | | - sys.path.append(tox_path) |
22 | | - |
23 | | -# Also add the azure-sdk-tools path so pypi_tools can be imported |
24 | | -tools_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) |
25 | | -if tools_path not in sys.path: |
26 | | - sys.path.append(tools_path) |
27 | | - |
28 | | -from verify_whl import verify_whl_root_directory |
29 | | -from verify_sdist import verify_sdist |
| 18 | +from azpysdk.verify_whl import ( |
| 19 | + verify_whl_root_directory, |
| 20 | + has_stable_version_on_pypi, |
| 21 | + verify_conda_section, |
| 22 | +) |
| 23 | +from azpysdk.verify_sdist import verify_sdist_helper |
30 | 24 |
|
31 | 25 | # Test scenario paths |
32 | 26 | scenarios_folder = os.path.join(os.path.dirname(__file__), "integration", "scenarios") |
@@ -99,9 +93,13 @@ def test_verify_valid_metadata_passes(package_type, scenario_name, scenario_path |
99 | 93 | # Run the appropriate verification function |
100 | 94 | if package_type == "wheel": |
101 | 95 | expected_module = parsed_pkg.namespace.split(".")[0] if parsed_pkg.namespace else "azure" |
102 | | - result = verify_whl_root_directory(os.path.dirname(package_path), expected_module, parsed_pkg) |
| 96 | + result = verify_whl_root_directory( |
| 97 | + os.path.dirname(package_path), expected_module, parsed_pkg, sys.executable, pypi_versions=[] |
| 98 | + ) |
103 | 99 | else: |
104 | | - result = verify_sdist(actual_scenario_path, os.path.dirname(package_path), parsed_pkg) |
| 100 | + result = verify_sdist_helper( |
| 101 | + actual_scenario_path, os.path.dirname(package_path), parsed_pkg, sys.executable |
| 102 | + ) |
105 | 103 |
|
106 | 104 | # The valid metadata should pass verification (return True) |
107 | 105 | assert result is True, f"verify_{package_type} should return True for valid {scenario_name} metadata scenario" |
@@ -142,9 +140,13 @@ def test_verify_invalid_metadata_fails(package_type, scenario_name, scenario_pat |
142 | 140 | with caplog.at_level("ERROR"): |
143 | 141 | if package_type == "wheel": |
144 | 142 | expected_module = parsed_pkg.namespace.split(".")[0] if parsed_pkg.namespace else "azure" |
145 | | - result = verify_whl_root_directory(os.path.dirname(package_path), expected_module, parsed_pkg) |
| 143 | + result = verify_whl_root_directory( |
| 144 | + os.path.dirname(package_path), expected_module, parsed_pkg, sys.executable, pypi_versions=None |
| 145 | + ) |
146 | 146 | else: |
147 | | - result = verify_sdist(actual_scenario_path, os.path.dirname(package_path), parsed_pkg) |
| 147 | + result = verify_sdist_helper( |
| 148 | + actual_scenario_path, os.path.dirname(package_path), parsed_pkg, sys.executable |
| 149 | + ) |
148 | 150 |
|
149 | 151 | # The invalid metadata should fail verification (return False) |
150 | 152 | assert ( |
@@ -173,3 +175,66 @@ def test_verify_invalid_metadata_fails(package_type, scenario_name, scenario_pat |
173 | 175 | # Cleanup dist directory |
174 | 176 | if os.path.exists(dist_dir): |
175 | 177 | shutil.rmtree(dist_dir) |
| 178 | + |
| 179 | + |
| 180 | +# ======================= has_stable_version_on_pypi tests ======================= |
| 181 | + |
| 182 | + |
| 183 | +def test_has_stable_version_on_pypi_with_stable(): |
| 184 | + """Returns True when at least one stable version exists.""" |
| 185 | + assert has_stable_version_on_pypi(["1.0.0", "2.0.0b1", "0.1.0"]) is True |
| 186 | + |
| 187 | + |
| 188 | +def test_has_stable_version_on_pypi_only_previews(): |
| 189 | + """Returns False when all versions are pre-releases.""" |
| 190 | + assert has_stable_version_on_pypi(["1.0.0b1", "2.0.0a3", "0.1.0rc1"]) is False |
| 191 | + |
| 192 | + |
| 193 | +def test_has_stable_version_on_pypi_empty(): |
| 194 | + """Returns False for an empty version list.""" |
| 195 | + assert has_stable_version_on_pypi([]) is False |
| 196 | + |
| 197 | + |
| 198 | +def test_has_stable_version_on_pypi_only_zero(): |
| 199 | + """Returns False when the only stable version is 0.0.0.""" |
| 200 | + assert has_stable_version_on_pypi(["0.0.0"]) is False |
| 201 | + |
| 202 | + |
| 203 | +# ======================= verify_conda_section tests ======================= |
| 204 | + |
| 205 | + |
| 206 | +def test_verify_conda_section_skips_when_no_stable_version(): |
| 207 | + """Should return True (pass) when there are no stable versions on PyPI.""" |
| 208 | + parsed_pkg = MagicMock() |
| 209 | + result = verify_conda_section("/fake/path", "pkg", parsed_pkg, pypi_versions=["1.0.0b1"]) |
| 210 | + assert result is True |
| 211 | + |
| 212 | + |
| 213 | +def test_verify_conda_section_fails_missing_conda_section(tmp_path): |
| 214 | + """Should fail when pyproject.toml exists but has no [tool.azure-sdk-conda] section.""" |
| 215 | + pyproject = tmp_path / "pyproject.toml" |
| 216 | + pyproject.write_text("[project]\nname = 'pkg'\n") |
| 217 | + parsed_pkg = MagicMock() |
| 218 | + parsed_pkg.get_conda_config.return_value = None |
| 219 | + result = verify_conda_section(str(tmp_path), "pkg", parsed_pkg, pypi_versions=["1.0.0"]) |
| 220 | + assert result is False |
| 221 | + |
| 222 | + |
| 223 | +def test_verify_conda_section_fails_missing_in_bundle(tmp_path): |
| 224 | + """Should fail when [tool.azure-sdk-conda] exists but 'in_bundle' key is missing.""" |
| 225 | + pyproject = tmp_path / "pyproject.toml" |
| 226 | + pyproject.write_text("[tool.azure-sdk-conda]\nsome_other_key = true\n") |
| 227 | + parsed_pkg = MagicMock() |
| 228 | + parsed_pkg.get_conda_config.return_value = {"some_other_key": True} |
| 229 | + result = verify_conda_section(str(tmp_path), "pkg", parsed_pkg, pypi_versions=["1.0.0"]) |
| 230 | + assert result is False |
| 231 | + |
| 232 | + |
| 233 | +def test_verify_conda_section_passes_with_valid_config(tmp_path): |
| 234 | + """Should pass when [tool.azure-sdk-conda] has 'in_bundle' defined.""" |
| 235 | + pyproject = tmp_path / "pyproject.toml" |
| 236 | + pyproject.write_text("[tool.azure-sdk-conda]\nin_bundle = true\n") |
| 237 | + parsed_pkg = MagicMock() |
| 238 | + parsed_pkg.get_conda_config.return_value = {"in_bundle": True} |
| 239 | + result = verify_conda_section(str(tmp_path), "pkg", parsed_pkg, pypi_versions=["1.0.0"]) |
| 240 | + assert result is True |
0 commit comments