Skip to content

Commit

Permalink
test_real_projects: Use --venv instead of editable install of FD
Browse files Browse the repository at this point in the history
Until now we've used Experiment.venv_with_fawltydeps() to install
FawltyDeps into the experiment's venv before each test run, and
uninstall it afterwards.

The new --venv flag enables us to instead have FawltyDeps analyze the
experiment's venv _without_ first being installed into it.

Use the --venv flag, and remove the now-obsolete FawltyDeps installation
from the experiment venvs.
  • Loading branch information
jherland committed Mar 14, 2023
1 parent edeb89d commit d0cc87d
Showing 1 changed file with 11 additions and 32 deletions.
43 changes: 11 additions & 32 deletions tests/test_real_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import subprocess
import sys
import tarfile
from contextlib import contextmanager
from pathlib import Path
from typing import Any, Dict, Iterator, List, NamedTuple, Optional, Set, Tuple
from urllib.parse import urlparse
Expand Down Expand Up @@ -53,11 +52,11 @@ def verify_requirements(venv_path: Path, requirements: List[str]) -> None:
def run_fawltydeps_json(
*args: str, venv_dir: Optional[Path], cwd: Optional[Path] = None
) -> JsonData:
cmd = ["fawltydeps"]
if venv_dir:
cmd = [f"{venv_dir}/bin/fawltydeps"]
argv = ["fawltydeps", "--config-file=/dev/null", "--json"]
if venv_dir is not None:
argv += [f"--venv={venv_dir}"]
proc = subprocess.run(
cmd + ["--config-file=/dev/null"] + list(args) + ["--json"],
argv + list(args),
stdout=subprocess.PIPE,
check=False,
cwd=cwd,
Expand Down Expand Up @@ -203,26 +202,6 @@ def get_venv_dir(self, cache: pytest.Cache) -> Path:
cache.set(f"fawltydeps/{self.venv_hash()}", str(venv_dir))
return venv_dir

@contextmanager
def venv_with_fawltydeps(self, cache: pytest.Cache) -> Iterator[Path]:
"""Provide this experiments's venv with FawltyDeps installed within.
Provide a context in which the FawltyDeps version located in the current
working directory is installed in editable mode. Uninstall FawltyDeps
upon exiting the context, so that the venv_dir is ready for the next
test (which may be run from a different current working directory).
"""
venv_dir = self.get_venv_dir(cache)
# setup: install editable fawltydeps
subprocess.run([f"{venv_dir}/bin/pip", "install", "-e", "./"], check=True)
try:
yield venv_dir
finally:
# teardown: uninstall fawltydeps
subprocess.run(
[f"{venv_dir}/bin/pip", "uninstall", "-y", "fawltydeps"], check=True
)


class ThirdPartyProject(NamedTuple):
"""Encapsulate a 3rd-party project to be tested with FawltyDeps.
Expand Down Expand Up @@ -375,13 +354,13 @@ def get_project_dir(self, cache: pytest.Cache) -> Path:
)
def test_real_project(request, project, experiment):
project_dir = project.get_project_dir(request.config.cache)
with experiment.venv_with_fawltydeps(request.config.cache) as venv_dir:
verify_requirements(venv_dir, experiment.requirements)
analysis = run_fawltydeps_json(
*experiment.args,
venv_dir=venv_dir,
cwd=project_dir,
)
venv_dir = experiment.get_venv_dir(request.config.cache)
verify_requirements(venv_dir, experiment.requirements)
analysis = run_fawltydeps_json(
*experiment.args,
venv_dir=venv_dir,
cwd=project_dir,
)

print(f"Checking experiment {experiment.name} for project under {project_dir}...")
experiment.verify_analysis_json(analysis)

0 comments on commit d0cc87d

Please sign in to comment.