|  | 
| 1 | 1 | import importlib.metadata | 
|  | 2 | +import sys | 
| 2 | 3 | 
 | 
|  | 4 | +import pytest | 
| 3 | 5 | from polylith import distributions | 
| 4 | 6 | 
 | 
| 5 | 7 | 
 | 
| @@ -40,3 +42,39 @@ def test_distribution_sub_packages(): | 
| 40 | 42 | 
 | 
| 41 | 43 |     assert res.get(expected_dist) is not None | 
| 42 | 44 |     assert expected_sub_package in res[expected_dist] | 
|  | 45 | + | 
|  | 46 | + | 
|  | 47 | +@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher") | 
|  | 48 | +def test_package_distributions_returning_top_namespace(monkeypatch): | 
|  | 49 | +    fake_dists = { | 
|  | 50 | +        "something": ["something-subnamespace"], | 
|  | 51 | +        "opentelemetry": ["opentelemetry-instrumentation-fastapi"], | 
|  | 52 | +        "google": ["google-cloud-storage", "google-api-core"], | 
|  | 53 | +        "other": ["other-sub-ns"], | 
|  | 54 | +    } | 
|  | 55 | + | 
|  | 56 | +    fake_project_deps = { | 
|  | 57 | +        "opentelemetry-instrumentation-fastapi", | 
|  | 58 | +        "fastapi", | 
|  | 59 | +        "something-subnamespace", | 
|  | 60 | +        "google-cloud-storage", | 
|  | 61 | +    } | 
|  | 62 | + | 
|  | 63 | +    monkeypatch.setattr( | 
|  | 64 | +        distributions.core.importlib.metadata, | 
|  | 65 | +        "packages_distributions", | 
|  | 66 | +        lambda: fake_dists, | 
|  | 67 | +    ) | 
|  | 68 | + | 
|  | 69 | +    res = distributions.core.get_packages_distributions(fake_project_deps) | 
|  | 70 | + | 
|  | 71 | +    assert res == {"google", "opentelemetry", "something"} | 
|  | 72 | + | 
|  | 73 | + | 
|  | 74 | +@pytest.mark.skipif(sys.version_info > (3, 9), reason="asserting python3.9 and lower") | 
|  | 75 | +def test_package_distributions_returning_empty_set(): | 
|  | 76 | +    fake_project_deps = {"something-subnamespace"} | 
|  | 77 | + | 
|  | 78 | +    res = distributions.core.get_packages_distributions(fake_project_deps) | 
|  | 79 | + | 
|  | 80 | +    assert res == set() | 
0 commit comments