|
| 1 | +from os import listdir |
| 2 | +from pathlib import Path |
| 3 | +from shutil import rmtree |
| 4 | +from subprocess import check_call |
| 5 | +from sys import executable |
| 6 | +from zipfile import ZipFile |
| 7 | + |
| 8 | + |
| 9 | +def test_project_basic_multiple_primary(): |
| 10 | + project = "test_project_multiple_primary" |
| 11 | + try: |
| 12 | + rmtree(f"hatch_multi/tests/{project}/dist") |
| 13 | + except FileNotFoundError: |
| 14 | + pass |
| 15 | + |
| 16 | + check_call( |
| 17 | + [ |
| 18 | + executable, |
| 19 | + "-m", |
| 20 | + "build", |
| 21 | + "-n", |
| 22 | + "-w", |
| 23 | + ], |
| 24 | + cwd=f"hatch_multi/tests/{project}", |
| 25 | + env={"SKIP_HATCH_MULTI": "1"}, |
| 26 | + ) |
| 27 | + |
| 28 | + assert Path(f"hatch_multi/tests/{project}/dist").exists() |
| 29 | + assert listdir(f"hatch_multi/tests/{project}/dist") == ["hatch_cpp_test_project_basic-0.1.0-py3-none-any.whl"] |
| 30 | + with ZipFile(f"hatch_multi/tests/{project}/dist/hatch_cpp_test_project_basic-0.1.0-py3-none-any.whl", "r") as zip_ref: |
| 31 | + zip_ref.extractall(f"hatch_multi/tests/{project}/dist/extracted") |
| 32 | + assert ( |
| 33 | + Path(f"hatch_multi/tests/{project}/dist/extracted").joinpath("hatch_cpp_test_project_basic-0.1.0.dist-info/METADATA").read_text() |
| 34 | + == """Metadata-Version: 2.4 |
| 35 | +Name: hatch-cpp-test-project-basic |
| 36 | +Version: 0.1.0 |
| 37 | +Dynamic: Requires-Dist |
| 38 | +Summary: Basic test project for hatch-cpp |
| 39 | +Requires-Python: >=3.11 |
| 40 | +Provides-Extra: main |
| 41 | +Requires-Dist: superstore; extra == 'main' |
| 42 | +Provides-Extra: other |
| 43 | +Requires-Dist: organizeit2; extra == 'other' |
| 44 | +""" |
| 45 | + ) |
| 46 | + rmtree(f"hatch_multi/tests/{project}/dist") |
| 47 | + |
| 48 | + check_call( |
| 49 | + [ |
| 50 | + executable, |
| 51 | + "-m", |
| 52 | + "build", |
| 53 | + "-n", |
| 54 | + "-w", |
| 55 | + ], |
| 56 | + cwd=f"hatch_multi/tests/{project}", |
| 57 | + ) |
| 58 | + |
| 59 | + assert Path(f"hatch_multi/tests/{project}/dist").exists() |
| 60 | + assert listdir(f"hatch_multi/tests/{project}/dist") == ["hatch_cpp_test_project_basic-0.1.0-py3-none-any.whl"] |
| 61 | + with ZipFile(f"hatch_multi/tests/{project}/dist/hatch_cpp_test_project_basic-0.1.0-py3-none-any.whl", "r") as zip_ref: |
| 62 | + zip_ref.extractall(f"hatch_multi/tests/{project}/dist/extracted") |
| 63 | + assert ( |
| 64 | + Path(f"hatch_multi/tests/{project}/dist/extracted").joinpath("hatch_cpp_test_project_basic-0.1.0.dist-info/METADATA").read_text() |
| 65 | + == """Metadata-Version: 2.4 |
| 66 | +Name: hatch-cpp-test-project-basic |
| 67 | +Version: 0.1.0 |
| 68 | +Summary: Basic test project for hatch-cpp |
| 69 | +Requires-Python: >=3.11 |
| 70 | +Requires-Dist: organizeit2 |
| 71 | +Requires-Dist: superstore |
| 72 | +Provides-Extra: main |
| 73 | +Requires-Dist: superstore; extra == 'main' |
| 74 | +Provides-Extra: other |
| 75 | +Requires-Dist: organizeit2; extra == 'other' |
| 76 | +""" |
| 77 | + ) |
| 78 | + rmtree(f"hatch_multi/tests/{project}/dist") |
| 79 | + |
| 80 | + check_call( |
| 81 | + [ |
| 82 | + executable, |
| 83 | + "-m", |
| 84 | + "build", |
| 85 | + "-n", |
| 86 | + "-w", |
| 87 | + ], |
| 88 | + cwd=f"hatch_multi/tests/{project}", |
| 89 | + env={"HATCH_MULTI_BUILD": "other"}, |
| 90 | + ) |
| 91 | + |
| 92 | + assert Path(f"hatch_multi/tests/{project}/dist").exists() |
| 93 | + assert listdir(f"hatch_multi/tests/{project}/dist") == ["hatch_cpp_test_project_basic_other-0.1.0-py3-none-any.whl"] |
| 94 | + with ZipFile(f"hatch_multi/tests/{project}/dist/hatch_cpp_test_project_basic_other-0.1.0-py3-none-any.whl", "r") as zip_ref: |
| 95 | + zip_ref.extractall(f"hatch_multi/tests/{project}/dist/extracted") |
| 96 | + assert ( |
| 97 | + Path(f"hatch_multi/tests/{project}/dist/extracted").joinpath("hatch_cpp_test_project_basic_other-0.1.0.dist-info/METADATA").read_text() |
| 98 | + == """Metadata-Version: 2.4 |
| 99 | +Name: hatch-cpp-test-project-basic-other |
| 100 | +Version: 0.1.0 |
| 101 | +Summary: Basic test project for hatch-cpp |
| 102 | +Requires-Python: >=3.11 |
| 103 | +Requires-Dist: organizeit2 |
| 104 | +Provides-Extra: main |
| 105 | +Requires-Dist: superstore; extra == 'main' |
| 106 | +""" |
| 107 | + ) |
| 108 | + rmtree(f"hatch_multi/tests/{project}/dist") |
0 commit comments