|
| 1 | +import os |
| 2 | +import pathlib |
| 3 | + |
| 4 | +from rsconnect.pyproject import lookup_metadata_file, parse_pyproject_python_requires |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | +HERE = os.path.dirname(__file__) |
| 9 | +PROJECTS_DIRECTORY = os.path.abspath(os.path.join(HERE, "testdata", "python-project")) |
| 10 | + |
| 11 | + |
| 12 | +@pytest.mark.parametrize( |
| 13 | + "project_dir, expected", |
| 14 | + [ |
| 15 | + (os.path.join(PROJECTS_DIRECTORY, "using_pyproject"), ("pyproject.toml",)), |
| 16 | + (os.path.join(PROJECTS_DIRECTORY, "using_setupcfg"), ("setup.cfg",)), |
| 17 | + ( |
| 18 | + os.path.join(PROJECTS_DIRECTORY, "using_pyversion"), |
| 19 | + ( |
| 20 | + "pyproject.toml", |
| 21 | + ".python-version", |
| 22 | + ), |
| 23 | + ), |
| 24 | + (os.path.join(PROJECTS_DIRECTORY, "allofthem"), ("pyproject.toml", "setup.cfg", ".python-version")), |
| 25 | + ], |
| 26 | + ids=["pyproject.toml", "setup.cfg", ".python-version", "allofthem"], |
| 27 | +) |
| 28 | +def test_python_project_metadata_detect(project_dir, expected): |
| 29 | + expectation = [(f, pathlib.Path(project_dir) / f) for f in expected] |
| 30 | + assert lookup_metadata_file(project_dir) == expectation |
| 31 | + |
| 32 | + |
| 33 | +@pytest.mark.parametrize( |
| 34 | + "project_dir", |
| 35 | + [ |
| 36 | + os.path.join(PROJECTS_DIRECTORY, "empty"), |
| 37 | + os.path.join(PROJECTS_DIRECTORY, "missing"), |
| 38 | + ], |
| 39 | + ids=["empty", "missing"], |
| 40 | +) |
| 41 | +def test_python_project_metadata_missing(project_dir): |
| 42 | + assert lookup_metadata_file(project_dir) == [] |
| 43 | + |
| 44 | + |
| 45 | +@pytest.mark.parametrize( |
| 46 | + "project_dir, expected", |
| 47 | + [ |
| 48 | + (os.path.join(PROJECTS_DIRECTORY, "using_pyproject"), ">=3.8"), |
| 49 | + (os.path.join(PROJECTS_DIRECTORY, "using_pyversion"), None), |
| 50 | + ], |
| 51 | + ids=["option-exists", "option-missing"], |
| 52 | +) |
| 53 | +def test_pyprojecttoml_python_requires(project_dir, expected): |
| 54 | + pyproject_file = pathlib.Path(project_dir) / "pyproject.toml" |
| 55 | + assert parse_pyproject_python_requires(pyproject_file) == expected |
0 commit comments