Skip to content
Prev Previous commit
Next Next commit
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`.
  • Loading branch information
EliahKagan committed Jun 15, 2025
commit 84632c78512e070a7aaa9ff1dd046c77293a58a4
36 changes: 14 additions & 22 deletions test/test_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import ast
import functools
import os
import subprocess

Expand All @@ -11,35 +12,23 @@
class TestInstallation(TestBase):
@with_rw_directory
def test_installation(self, rw_dir):
venv = self._set_up_venv(rw_dir)
venv, run = self._set_up_venv(rw_dir)

result = subprocess.run(
[venv.pip, "install", "."],
stdout=subprocess.PIPE,
cwd=venv.sources,
)
result = run([venv.pip, "install", "."])
self.assertEqual(
0,
result.returncode,
msg=result.stderr or result.stdout or "Can't install project",
)

result = subprocess.run(
[venv.python, "-c", "import git"],
stdout=subprocess.PIPE,
cwd=venv.sources,
)
result = run([venv.python, "-c", "import git"])
self.assertEqual(
0,
result.returncode,
msg=result.stderr or result.stdout or "Self-test failed",
)

result = subprocess.run(
[venv.python, "-c", "import gitdb; import smmap"],
stdout=subprocess.PIPE,
cwd=venv.sources,
)
result = run([venv.python, "-c", "import gitdb; import smmap"])
self.assertEqual(
0,
result.returncode,
Expand All @@ -49,11 +38,7 @@ def test_installation(self, rw_dir):
# Even IF gitdb or any other dependency is supplied during development by
# inserting its location into PYTHONPATH or otherwise patched into sys.path,
# make sure it is not wrongly inserted as the *first* entry.
result = subprocess.run(
[venv.python, "-c", "import sys; import git; print(sys.path)"],
stdout=subprocess.PIPE,
cwd=venv.sources,
)
result = run([venv.python, "-c", "import sys; import git; print(sys.path)"])
syspath = result.stdout.decode("utf-8").splitlines()[0]
syspath = ast.literal_eval(syspath)
self.assertEqual(
Expand All @@ -74,4 +59,11 @@ def _set_up_venv(rw_dir):
target_is_directory=True,
)

return venv
# Create a convenience function to run commands in it.
run = functools.partial(
subprocess.run,
stdout=subprocess.PIPE,
cwd=venv.sources,
)

return venv, run
Loading