Skip to content

Commit

Permalink
Support git being installed on windows in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodearnest committed Dec 8, 2022
1 parent 0ee72f1 commit 95d2b40
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 42 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:

jobs:
check:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
Expand All @@ -26,7 +26,7 @@ jobs:
test-job:
strategy:
matrix:
os: [ubuntu-latest, windows-2019]
os: [ubuntu-20.04, windows-2019]
# Python 3.8 is what we currently support for running cohortextractor
# locally, and 3.9 is what we required for databuilder so we need to make
# sure we can run with those
Expand All @@ -49,15 +49,15 @@ jobs:
- uses: extractions/setup-just@aa5d15c144db4585980a44ebfdd2cf337c4f14cb # 1.4

- name: Run actual tests on ${{ matrix.os }}
if: ${{ matrix.os == 'ubuntu-latest' }}
run: just test
if: ${{ matrix.os == 'ubuntu-20.04' }}
run: just test -vvv

- name: Run actual tests on ${{ matrix.os }}
if: ${{ matrix.os == 'windows-2019' }}
run: just test-no-docker
run: just test-no-docker -vvv

test-package-build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
name: Test we can build PyPI package
steps:
- name: Checkout
Expand All @@ -84,7 +84,7 @@ jobs:
run: just package-test sdist

test-docker:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
name: Test docker image
steps:
- name: Checkout
Expand All @@ -102,7 +102,7 @@ jobs:
run: just docker/test

test-github-workflow-output:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
name: Inspect test runner output in the context of a Github Workflow
steps:
- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions jobrunner/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _is_valid_backend_name(name):
VERSION = subprocess.check_output(
["git", "describe", "--tags"], text=True
).strip()
except subprocess.CalledProcessError:
except (FileNotFoundError, subprocess.CalledProcessError):
pass


Expand All @@ -33,7 +33,7 @@ def _is_valid_backend_name(name):
GIT_SHA = subprocess.check_output(
["git", "rev-parse", "--short", "HEAD"], text=True
).strip()
except subprocess.CalledProcessError:
except (FileNotFoundError, subprocess.CalledProcessError):
pass


Expand Down
74 changes: 42 additions & 32 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


script = """
from jobrunner import config;
from jobrunner import config
cfg = {k: str(v) for k, v in vars(config).items() if k.isupper()}
print(repr(cfg))
"""
Expand All @@ -25,17 +25,20 @@ def import_cfg(env, raises=None):
if "SYSTEMROOT" in os.environ:
env["SYSTEMROOT"] = os.environ["SYSTEMROOT"]

ps = subprocess.run(
[sys.executable, "-c", script],
env=env,
text=True,
capture_output=True,
)
if ps.returncode == 0:
print(ps.stdout)
return ast.literal_eval(ps.stdout), None
else:
return None, ps.stderr
try:
ps = subprocess.run(
[sys.executable, "-c", script],
env=env,
text=True,
check=True,
capture_output=True,
)
except subprocess.CalledProcessError as err:
print(err.stderr)
raise

print(ps.stdout)
return ast.literal_eval(ps.stdout)


def test_config_imports_with_clean_env():
Expand All @@ -47,22 +50,22 @@ def test_config_presto_paths(tmp_path):
key.write_text("key")
cert = tmp_path / "cert"
cert.write_text("cert")
cfg, err = import_cfg(
print(key)
print(cert)
cfg = import_cfg(
{"PRESTO_TLS_KEY_PATH": str(key), "PRESTO_TLS_CERT_PATH": str(cert)}
)
assert err is None
assert cfg["PRESTO_TLS_KEY"] == "key"
assert cfg["PRESTO_TLS_CERT"] == "cert"


def test_config_presto_paths_not_exist(tmp_path):

key = tmp_path / "key"
key.write_text("key")
cert = tmp_path / "cert"
cert.write_text("cert")

cfg, err = import_cfg(
cfg = import_cfg(
{
"PRESTO_TLS_KEY_PATH": str(key),
"PRESTO_TLS_CERT_PATH": str(cert),
Expand All @@ -71,25 +74,32 @@ def test_config_presto_paths_not_exist(tmp_path):
assert cfg["PRESTO_TLS_KEY"] == "key"
assert cfg["PRESTO_TLS_CERT"] == "cert"

# only one
_, err = import_cfg({"PRESTO_TLS_KEY_PATH": "foo"})
assert "Both PRESTO_TLS_KEY_PATH and PRESTO_TLS_CERT_PATH must be defined" in err
with pytest.raises(subprocess.CalledProcessError) as err:
import_cfg({"PRESTO_TLS_KEY_PATH": "foo"})

cfg, err = import_cfg(
{
"PRESTO_TLS_KEY_PATH": "key.notexists",
"PRESTO_TLS_CERT_PATH": str(cert),
}
assert "Both PRESTO_TLS_KEY_PATH and PRESTO_TLS_CERT_PATH must be defined" in str(
err.value.stderr
)
assert "PRESTO_TLS_KEY_PATH=key.notexists" in err

cfg, err = import_cfg(
{
"PRESTO_TLS_KEY_PATH": str(key),
"PRESTO_TLS_CERT_PATH": "cert.notexists",
}
)
assert "PRESTO_TLS_CERT_PATH=cert.notexists" in err
with pytest.raises(subprocess.CalledProcessError) as err:
import_cfg(
{
"PRESTO_TLS_KEY_PATH": "key.notexists",
"PRESTO_TLS_CERT_PATH": str(cert),
}
)

assert "PRESTO_TLS_KEY_PATH=key.notexists" in str(err.value.stderr)

with pytest.raises(subprocess.CalledProcessError) as err:
import_cfg(
{
"PRESTO_TLS_KEY_PATH": str(key),
"PRESTO_TLS_CERT_PATH": "cert.notexists",
}
)

assert "PRESTO_TLS_CERT_PATH=cert.notexists" in str(err.value.stderr)


@pytest.mark.parametrize(
Expand Down
3 changes: 3 additions & 0 deletions tests/test_local_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,9 @@ def test_finalize_failed_oomkilled(docker_cleanup, test_repo, tmp_work_dir, volu

wait_for_state(api, job, ExecutorState.EXECUTED)

# let the docker service catch up, or else it can sometimes not mark it as OOMKilled fast enough
time.sleep(5)

status = api.finalize(job)
assert status.state == ExecutorState.FINALIZING

Expand Down

0 comments on commit 95d2b40

Please sign in to comment.