11import os
22import pathlib
3+ import tempfile
34
4- from rsconnect .pyproject import lookup_metadata_file , parse_pyproject_python_requires
5+ from rsconnect .pyproject import (
6+ lookup_metadata_file ,
7+ parse_pyproject_python_requires ,
8+ parse_setupcfg_python_requires ,
9+ parse_pyversion_python_requires ,
10+ get_python_requires_parser ,
11+ )
512
613import pytest
714
2330 (
2431 os .path .join (PROJECTS_DIRECTORY , "using_pyversion" ),
2532 (
26- "pyproject.toml" ,
2733 ".python-version" ,
34+ "pyproject.toml" ,
35+ "setup.cfg" ,
2836 ),
2937 ),
30- (os .path .join (PROJECTS_DIRECTORY , "allofthem" ), ("pyproject.toml " , "setup.cfg " , ".python-version " )),
38+ (os .path .join (PROJECTS_DIRECTORY , "allofthem" ), (".python-version " , "pyproject.toml " , "setup.cfg " )),
3139 ],
3240 ids = ["pyproject.toml" , "setup.cfg" , ".python-version" , "allofthem" ],
3341)
@@ -37,6 +45,22 @@ def test_python_project_metadata_detect(project_dir, expected):
3745 assert lookup_metadata_file (project_dir ) == expectation
3846
3947
48+ @pytest .mark .parametrize (
49+ "filename, expected_parser" ,
50+ [
51+ ("pyproject.toml" , parse_pyproject_python_requires ),
52+ ("setup.cfg" , parse_setupcfg_python_requires ),
53+ (".python-version" , parse_pyversion_python_requires ),
54+ ("invalid.txt" , None ),
55+ ],
56+ ids = ["pyproject.toml" , "setup.cfg" , ".python-version" , "invalid" ],
57+ )
58+ def test_get_python_requires_parser (filename , expected_parser ):
59+ metadata_file = pathlib .Path (PROJECTS_DIRECTORY ) / filename
60+ parser = get_python_requires_parser (metadata_file )
61+ assert parser == expected_parser
62+
63+
4064@pytest .mark .parametrize (
4165 "project_dir" ,
4266 [
@@ -65,3 +89,30 @@ def test_pyprojecttoml_python_requires(project_dir, expected):
6589 """
6690 pyproject_file = pathlib .Path (project_dir ) / "pyproject.toml"
6791 assert parse_pyproject_python_requires (pyproject_file ) == expected
92+
93+
94+ @pytest .mark .parametrize (
95+ "project_dir, expected" ,
96+ [
97+ (os .path .join (PROJECTS_DIRECTORY , "using_setupcfg" ), ">=3.8" ),
98+ (os .path .join (PROJECTS_DIRECTORY , "using_pyversion" ), None ),
99+ ],
100+ ids = ["option-exists" , "option-missing" ],
101+ )
102+ def test_setupcfg_python_requires (tmp_path , project_dir , expected ):
103+ setupcfg_file = pathlib .Path (project_dir ) / "setup.cfg"
104+ assert parse_setupcfg_python_requires (setupcfg_file ) == expected
105+
106+
107+ @pytest .mark .parametrize (
108+ "project_dir, expected" ,
109+ [
110+ (os .path .join (PROJECTS_DIRECTORY , "using_pyversion" ), ">=3.8, <3.12" ),
111+ # There is no case (option-missing) where the .python-version file is empty,
112+ # so we don't test that.
113+ ],
114+ ids = ["option-exists" ],
115+ )
116+ def test_pyversion_python_requires (tmp_path , project_dir , expected ):
117+ versionfile = pathlib .Path (project_dir ) / ".python-version"
118+ assert parse_pyversion_python_requires (versionfile ) == expected
0 commit comments