From fb4aa68e6b869ccc9a19a6a5266a191858fa0b89 Mon Sep 17 00:00:00 2001 From: tomcodgen Date: Mon, 27 Jan 2025 18:52:20 +0100 Subject: [PATCH] Revert "skip tests requiring auth, remove hardcoded gh install (#47)" This reverts commit 7baab10f6efa91e64a5225e81abe41686d7f488b. --- tests/conftest.py | 39 --------------------------- tests/integration/codemod/conftest.py | 4 --- tests/shared/codemod/models.py | 12 +++------ 3 files changed, 3 insertions(+), 52 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 495d2fd54..526d5eeb6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,5 @@ import logging import os -from pathlib import Path - -import pytest from tests.shared.codemod.models import Size @@ -77,39 +74,3 @@ def pytest_configure(config): filename=f"build/logs/tests_{worker_id}.log", level=config.getini("log_file_level"), ) - - -def is_git_lfs_pointer(file_path: Path) -> bool: - """Check if a file is a git LFS pointer file""" - try: - with open(file_path) as f: - first_line = f.readline().strip() - return first_line == "version https://git-lfs.github.com/spec/v1" - except Exception: - return False - - -@pytest.hookimpl(hookwrapper=True) -def pytest_runtest_makereport(item, call): - outcome = yield - report = outcome.get_result() - - if report.when == "call" and report.failed: - if "NodeJS or npm is not installed" in str(report.longrepr): - pytest.skip("Test requires NodeJS and npm to be installed") - - -@pytest.fixture(autouse=True) -def skip_lfs_tests(request): - """Skip tests that depend on git LFS files if they haven't been pulled""" - # Get the test module path - test_path = Path(request.module.__file__) - - # Only run for integration tests - if not str(test_path).startswith(str(Path.cwd() / "tests" / "integration")): - return - - # Get the expected diff path from the test's expected fixture - expected = request.getfixturevalue("expected") - if isinstance(expected, Path) and is_git_lfs_pointer(expected): - pytest.skip(f"Test requires git LFS file {expected} which hasn't been pulled") diff --git a/tests/integration/codemod/conftest.py b/tests/integration/codemod/conftest.py index 84ff4df0b..33363c3a9 100644 --- a/tests/integration/codemod/conftest.py +++ b/tests/integration/codemod/conftest.py @@ -141,10 +141,6 @@ def token(request): def op(repo: Repo, token: str | None) -> YieldFixture[LocalRepoOperator]: with filelock.FileLock(BASE_TMP_DIR / "locks" / repo.name): op = repo.to_op(repo.name, token) - if isinstance(op, tuple): - # This means we got (None, error_message) - _, msg = op - pytest.skip(msg or "Could not create repo operator") yield op diff --git a/tests/shared/codemod/models.py b/tests/shared/codemod/models.py index 62f028fcf..35106d27b 100644 --- a/tests/shared/codemod/models.py +++ b/tests/shared/codemod/models.py @@ -60,23 +60,17 @@ class Repo(BaseModel): def from_json(cls, json_str: str) -> "Repo": return cls.model_validate(json.loads(json_str)) - def to_op(self, name: str, token: str | None) -> LocalRepoOperator | tuple[None, str | None]: + def to_op(self, name: str, token: str | None) -> LocalRepoOperator: base_path = BASE_TMP_DIR / ("extra_repos" if self.extra_repo else "oss_repos") / name base_path.mkdir(exist_ok=True, parents=True) url = self.url if token: url = url.replace("://", f"://{token}@") elif self.repo_id is not None: - # TODO: this is a very messy hack to check whether we should prompt the user for auth - # if REPO_ID_TO_URL is not set, we probably don't need auth. this is assuming that for - # OSS repos, we don't need to pull any private repos. - if not REPO_ID_TO_URL: - return (None, "Could not create repo operator - skipping test") - + print("Setting up auth using the github cli") if not which("gh"): - return (None, "GitHub CLI (gh) is not installed. Please install it first. Skipping test.") + os.system("brew install gh") if '[credential "https://github.codegen.app"]' not in (Path.home() / ".gitconfig").read_text(): - print("Setting up auth using the github cli") os.system("gh auth login -h github.codegen.app") os.system("gh auth setup-git -h github.codegen.app") return LocalRepoOperator.create_from_commit(str(base_path), self.default_branch, self.commit, url)