Skip to content

Commit

Permalink
improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
mam10eks committed Dec 19, 2024
1 parent adf060a commit 1546436
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions test/test_python_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
import tempfile
import unittest
import zipfile
from contextlib import contextmanager
from pathlib import Path

from approvaltests import verify_as_json

TEST_RESOURCES = pathlib.Path(__file__).parent.parent.resolve() / "test" / "test-resources.zip"


@contextmanager
def resource(resource_name):
with tempfile.TemporaryDirectory(delete=False) as f:
with tempfile.TemporaryDirectory() as f:
with zipfile.ZipFile(TEST_RESOURCES, "r") as zip_ref:
zip_ref.extractall(f)
ret = Path(f) / resource_name
assert ret.is_dir(), ret
return ret
yield ret


def run_command_and_return_persisted_metadata(command):
Expand All @@ -36,9 +38,8 @@ def run_command_and_return_persisted_metadata(command):

class PythonScriptApprovalTests(unittest.TestCase):
def test_for_valid_git_repo(self):
pyterrier_dir = resource("pyterrier")

actual = run_command_and_return_persisted_metadata(
lambda i: ["python3", f"{pyterrier_dir}/example-script.py", i]
)
verify_as_json(actual)
with resource("pyterrier") as pyterrier_dir:
actual = run_command_and_return_persisted_metadata(
lambda i: ["python3", f"{pyterrier_dir}/example-script.py", i]
)
verify_as_json(actual)

0 comments on commit 1546436

Please sign in to comment.