@@ -40,30 +40,64 @@ def test_pyproject_support(tmpdir, monkeypatch):
40
40
assert res == "12.34"
41
41
42
42
43
- def test_pyproject_support_with_git (tmpdir , monkeypatch , wd ):
44
- pytest .importorskip ("toml" )
45
- pkg = tmpdir .join ("wd" )
46
- pkg .join ("pyproject.toml" ).write ("""[tool.setuptools_scm]""" )
47
- pkg .join ("setup.py" ).write (
48
- "__import__('setuptools').setup(name='setuptools_scm_example')"
49
- )
50
- res = do ((sys .executable , "setup.py" , "--version" ), pkg )
43
+ PYPROJECT_FILES = {
44
+ "setup.py" : "[tool.setuptools_scm]" ,
45
+ "setup.cfg" : "[tool.setuptools_scm]" ,
46
+ "pyproject tool.setuptools_scm" : (
47
+ "[tool.setuptools_scm]\n dist_name='setuptools_scm_example'"
48
+ ),
49
+ "pyproject.project" : (
50
+ "[project]\n name='setuptools_scm_example'\n [tool.setuptools_scm]"
51
+ ),
52
+ }
53
+
54
+ SETUP_PY_PLAIN = "__import__('setuptools').setup()"
55
+ SETUP_PY_WITH_NAME = "__import__('setuptools').setup(name='setuptools_scm_example')"
56
+
57
+ SETUP_PY_FILES = {
58
+ "setup.py" : SETUP_PY_WITH_NAME ,
59
+ "setup.cfg" : SETUP_PY_PLAIN ,
60
+ "pyproject tool.setuptools_scm" : SETUP_PY_PLAIN ,
61
+ "pyproject.project" : SETUP_PY_PLAIN ,
62
+ }
63
+
64
+ SETUP_CFG_FILES = {
65
+ "setup.py" : "" ,
66
+ "setup.cfg" : "[metadata]\n name=setuptools_scm_example" ,
67
+ "pyproject tool.setuptools_scm" : "" ,
68
+ "pyproject.project" : "" ,
69
+ }
70
+
71
+ with_metadata_in = pytest .mark .parametrize (
72
+ "metadata_in" ,
73
+ ["setup.py" , "setup.cfg" , "pyproject tool.setuptools_scm" , "pyproject.project" ],
74
+ )
75
+
76
+
77
+ @with_metadata_in
78
+ def test_pyproject_support_with_git (wd , metadata_in ):
79
+ pytest .importorskip ("tomli" )
80
+ wd .write ("pyproject.toml" , PYPROJECT_FILES [metadata_in ])
81
+ wd .write ("setup.py" , SETUP_PY_FILES [metadata_in ])
82
+ wd .write ("setup.cfg" , SETUP_CFG_FILES [metadata_in ])
83
+ res = wd ((sys .executable , "setup.py" , "--version" ))
51
84
assert res .endswith ("0.1.dev0" )
52
85
53
86
54
- def test_pretend_version (tmpdir , monkeypatch , wd ):
87
+ def test_pretend_version (monkeypatch , wd ):
55
88
monkeypatch .setenv (PRETEND_KEY , "1.0.0" )
56
89
57
90
assert wd .get_version () == "1.0.0"
58
91
assert wd .get_version (dist_name = "ignored" ) == "1.0.0"
59
92
60
93
61
- def test_pretend_version_named_pyproject_integration (tmpdir , monkeypatch , wd ):
62
- test_pyproject_support_with_git (tmpdir , monkeypatch , wd )
94
+ @with_metadata_in
95
+ def test_pretend_version_named_pyproject_integration (monkeypatch , wd , metadata_in ):
96
+ test_pyproject_support_with_git (wd , metadata_in )
63
97
monkeypatch .setenv (
64
98
PRETEND_KEY_NAMED .format (name = "setuptools_scm_example" .upper ()), "3.2.1"
65
99
)
66
- res = do ((sys .executable , "setup.py" , "--version" ), tmpdir / "wd" )
100
+ res = wd ((sys .executable , "setup.py" , "--version" ))
67
101
assert res .endswith ("3.2.1" )
68
102
69
103
0 commit comments