Skip to content

Commit 849fd47

Browse files
committed
tweak test
1 parent e5ded03 commit 849fd47

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

rsconnect/pyproject.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def adapt_python_requires(
122122
"""
123123
current_contraints = python_requires.split(",")
124124

125-
def _adapt_contraint(constraints: list[str]) -> typing.Generator[str, None, None]:
125+
def _adapt_contraint(constraints: typing.List[str]) -> typing.Generator[str, None, None]:
126126
for constraint in constraints:
127127
constraint = constraint.strip()
128128
if "@" in constraint or "-" in constraint or "/" in constraint:

tests/test_environment.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ def test_pyproject_toml(self):
143143
def test_python_version(self):
144144
env = Environment.create_python_environment(os.path.join(TESTDATA, "python-project", "using_pyversion"))
145145
assert env.python_interpreter == sys.executable
146-
assert env.python_version_requirement == ">=3.8, <3.12"
146+
assert env.python_version_requirement == ">=3.8,<3.12"
147147

148148
def test_all_of_them(self):
149149
env = Environment.create_python_environment(os.path.join(TESTDATA, "python-project", "allofthem"))
150150
assert env.python_interpreter == sys.executable
151-
assert env.python_version_requirement == ">=3.8, <3.12"
151+
assert env.python_version_requirement == ">=3.8,<3.12"
152152

153153
def test_missing(self):
154154
env = Environment.create_python_environment(os.path.join(TESTDATA, "python-project", "empty"))

tests/test_pyproject.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_setupcfg_python_requires(project_dir, expected):
118118
@pytest.mark.parametrize(
119119
"project_dir, expected",
120120
[
121-
(os.path.join(PROJECTS_DIRECTORY, "using_pyversion"), ">=3.8, <3.12"),
121+
(os.path.join(PROJECTS_DIRECTORY, "using_pyversion"), ">=3.8,<3.12"),
122122
],
123123
ids=["option-exists"],
124124
)
@@ -140,7 +140,7 @@ def test_detect_python_version_requirement():
140140
version requirement is used.
141141
"""
142142
project_dir = os.path.join(PROJECTS_DIRECTORY, "allofthem")
143-
assert detect_python_version_requirement(project_dir) == ">=3.8, <3.12"
143+
assert detect_python_version_requirement(project_dir) == ">=3.8,<3.12"
144144

145145
assert detect_python_version_requirement(os.path.join(PROJECTS_DIRECTORY, "empty")) is None
146146

@@ -182,15 +182,21 @@ def test_python_version_file_adapt(content, expected):
182182
183183
We should convert them to the constraints that connect expects.
184184
"""
185-
with tempfile.NamedTemporaryFile(mode="w+") as tmpfile:
185+
# delete=False is necessary on windows to reopen the file.
186+
# Otherwise it can't be opened again.
187+
# Ideally delete_on_close=False does what we need, but it's only >=3.12
188+
with tempfile.NamedTemporaryFile(mode="w+", delete=False) as tmpfile:
186189
tmpfile.write(content)
187190
tmpfile.flush()
188-
189-
versionfile = pathlib.Path(tmpfile.name)
190-
191-
if isinstance(expected, Exception):
192-
with pytest.raises(expected.__class__) as excinfo:
193-
parse_pyversion_python_requires(versionfile)
194-
assert str(excinfo.value) == expected.args[0]
195-
else:
196-
assert parse_pyversion_python_requires(versionfile) == expected
191+
tmpfile.close() # Also needed for windows to allow subsequent reading.
192+
193+
try:
194+
versionfile = pathlib.Path(tmpfile.name)
195+
if isinstance(expected, Exception):
196+
with pytest.raises(expected.__class__) as excinfo:
197+
parse_pyversion_python_requires(versionfile)
198+
assert str(excinfo.value) == expected.args[0]
199+
else:
200+
assert parse_pyversion_python_requires(versionfile) == expected
201+
finally:
202+
os.remove(tmpfile.name)

0 commit comments

Comments
 (0)