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
1724 (
1825 os .path .join (PROJECTS_DIRECTORY , "using_pyversion" ),
1926 (
20- "pyproject.toml" ,
2127 ".python-version" ,
28+ "pyproject.toml" ,
29+ "setup.cfg" ,
2230 ),
2331 ),
24- (os .path .join (PROJECTS_DIRECTORY , "allofthem" ), ("pyproject.toml " , "setup.cfg " , ".python-version " )),
32+ (os .path .join (PROJECTS_DIRECTORY , "allofthem" ), (".python-version " , "pyproject.toml " , "setup.cfg " )),
2533 ],
2634 ids = ["pyproject.toml" , "setup.cfg" , ".python-version" , "allofthem" ],
2735)
@@ -30,6 +38,22 @@ def test_python_project_metadata_detect(project_dir, expected):
3038 assert lookup_metadata_file (project_dir ) == expectation
3139
3240
41+ @pytest .mark .parametrize (
42+ "filename, expected_parser" ,
43+ [
44+ ("pyproject.toml" , parse_pyproject_python_requires ),
45+ ("setup.cfg" , parse_setupcfg_python_requires ),
46+ (".python-version" , parse_pyversion_python_requires ),
47+ ("invalid.txt" , None ),
48+ ],
49+ ids = ["pyproject.toml" , "setup.cfg" , ".python-version" , "invalid" ],
50+ )
51+ def test_get_python_requires_parser (filename , expected_parser ):
52+ metadata_file = pathlib .Path (PROJECTS_DIRECTORY ) / filename
53+ parser = get_python_requires_parser (metadata_file )
54+ assert parser == expected_parser
55+
56+
3357@pytest .mark .parametrize (
3458 "project_dir" ,
3559 [
@@ -53,3 +77,30 @@ def test_python_project_metadata_missing(project_dir):
5377def test_pyprojecttoml_python_requires (project_dir , expected ):
5478 pyproject_file = pathlib .Path (project_dir ) / "pyproject.toml"
5579 assert parse_pyproject_python_requires (pyproject_file ) == expected
80+
81+
82+ @pytest .mark .parametrize (
83+ "project_dir, expected" ,
84+ [
85+ (os .path .join (PROJECTS_DIRECTORY , "using_setupcfg" ), ">=3.8" ),
86+ (os .path .join (PROJECTS_DIRECTORY , "using_pyversion" ), None ),
87+ ],
88+ ids = ["option-exists" , "option-missing" ],
89+ )
90+ def test_setupcfg_python_requires (tmp_path , project_dir , expected ):
91+ setupcfg_file = pathlib .Path (project_dir ) / "setup.cfg"
92+ assert parse_setupcfg_python_requires (setupcfg_file ) == expected
93+
94+
95+ @pytest .mark .parametrize (
96+ "project_dir, expected" ,
97+ [
98+ (os .path .join (PROJECTS_DIRECTORY , "using_pyversion" ), ">=3.8, <3.12" ),
99+ # There is no case (option-missing) where the .python-version file is empty,
100+ # so we don't test that.
101+ ],
102+ ids = ["option-exists" ],
103+ )
104+ def test_pyversion_python_requires (tmp_path , project_dir , expected ):
105+ versionfile = pathlib .Path (project_dir ) / ".python-version"
106+ assert parse_pyversion_python_requires (versionfile ) == expected
0 commit comments