Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 84632c7

Browse files
Extract subprocess.run logic repeated in test_installation
This creates a function (technically, a callable `partial` object) for `test_installation` to use instead of repeating `subproces.run` keyword arguments all the time. This relates directly to steps in `_set_up_venv`, and it's makes about as much sense to do it there as in `test_installation`, so it is placed (and described) in `_set_up_venv`.
1 parent 953d161 commit 84632c7

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

‎test/test_installation.py‎

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
33

44
import ast
5+
import functools
56
import os
67
import subprocess
78

@@ -11,35 +12,23 @@
1112
class TestInstallation(TestBase):
1213
@with_rw_directory
1314
def test_installation(self, rw_dir):
14-
venv = self._set_up_venv(rw_dir)
15+
venv, run = self._set_up_venv(rw_dir)
1516

16-
result = subprocess.run(
17-
[venv.pip, "install", "."],
18-
stdout=subprocess.PIPE,
19-
cwd=venv.sources,
20-
)
17+
result = run([venv.pip, "install", "."])
2118
self.assertEqual(
2219
0,
2320
result.returncode,
2421
msg=result.stderr or result.stdout or "Can't install project",
2522
)
2623

27-
result = subprocess.run(
28-
[venv.python, "-c", "import git"],
29-
stdout=subprocess.PIPE,
30-
cwd=venv.sources,
31-
)
24+
result = run([venv.python, "-c", "import git"])
3225
self.assertEqual(
3326
0,
3427
result.returncode,
3528
msg=result.stderr or result.stdout or "Self-test failed",
3629
)
3730

38-
result = subprocess.run(
39-
[venv.python, "-c", "import gitdb; import smmap"],
40-
stdout=subprocess.PIPE,
41-
cwd=venv.sources,
42-
)
31+
result = run([venv.python, "-c", "import gitdb; import smmap"])
4332
self.assertEqual(
4433
0,
4534
result.returncode,
@@ -49,11 +38,7 @@ def test_installation(self, rw_dir):
4938
# Even IF gitdb or any other dependency is supplied during development by
5039
# inserting its location into PYTHONPATH or otherwise patched into sys.path,
5140
# make sure it is not wrongly inserted as the *first* entry.
52-
result = subprocess.run(
53-
[venv.python, "-c", "import sys; import git; print(sys.path)"],
54-
stdout=subprocess.PIPE,
55-
cwd=venv.sources,
56-
)
41+
result = run([venv.python, "-c", "import sys; import git; print(sys.path)"])
5742
syspath = result.stdout.decode("utf-8").splitlines()[0]
5843
syspath = ast.literal_eval(syspath)
5944
self.assertEqual(
@@ -74,4 +59,11 @@ def _set_up_venv(rw_dir):
7459
target_is_directory=True,
7560
)
7661

77-
return venv
62+
# Create a convenience function to run commands in it.
63+
run = functools.partial(
64+
subprocess.run,
65+
stdout=subprocess.PIPE,
66+
cwd=venv.sources,
67+
)
68+
69+
return venv, run

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /