Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/emap-setup-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: emap setup tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop, sk/waveform-dev ]
repository_dispatch:
permissions:
contents: read
checks: write
id-token: write
pull-requests: read # needed by paths-filter
jobs:
filter:
runs-on: ubuntu-latest
outputs:
emap-setup: ${{ steps.filter.outputs.emap-setup }}
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
emap-setup:
- '.github/**'
- 'emap-checker.xml'
- 'emap-setup/**'
emap-setup-tests:
needs: [filter]
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT_READ_AND_COMMENT }}
if: needs.filter.outputs.emap-setup == 'true'
steps:
- uses: actions/checkout@v3
- name: Set up python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: "pip"
- name: Install Python Dependencies
run: |
python -m pip install -r emap-setup/requirements.txt
- name: Run tests
run: |
cd emap-setup
pytest --cov=./ --cov-report=term
4 changes: 4 additions & 0 deletions emap-setup/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[run]
omit =
__init__.py
tests/*
4 changes: 4 additions & 0 deletions emap-setup/emap_runner/setup/repos.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import git
import os
import shutil

from pathlib import Path
Expand Down Expand Up @@ -118,6 +119,9 @@ def path(self) -> Path:
@property
def https_git_url(self) -> str:
"""Generate a https URL. e.g. https://github.com/../emap-setup.git"""
gh_token = os.environ.get('GITHUB_TOKEN', False)
if gh_token:
return f"https://{gh_token}@{self._base_git_url}/{self.name}"
return f"https://{self._base_git_url}/{self.name}"

@property
Expand Down
7 changes: 7 additions & 0 deletions emap-setup/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pytest
pytest-cov
PyYAML
gitpython
black
tqdm
setuptools
62 changes: 57 additions & 5 deletions emap-setup/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@
pytest
PyYAML
gitpython
black
tqdm
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in -o requirements.txt
black==25.9.0
# via -r requirements.in
click==8.3.0
# via black
coverage==7.10.7
# via pytest-cov
exceptiongroup==1.3.0
# via pytest
gitdb==4.0.12
# via gitpython
gitpython==3.1.45
# via -r requirements.in
iniconfig==2.1.0
# via pytest
mypy-extensions==1.1.0
# via black
packaging==25.0
# via
# black
# pytest
pathspec==0.12.1
# via black
platformdirs==4.4.0
# via black
pluggy==1.6.0
# via
# pytest
# pytest-cov
pygments==2.19.2
# via pytest
pytest==8.4.2
# via
# -r requirements.in
# pytest-cov
pytest-cov==7.0.0
# via -r requirements.in
pytokens==0.1.10
# via black
pyyaml==6.0.2
# via -r requirements.in
setuptools==80.9.0
# via -r requirements.in
smmap==5.0.2
# via gitdb
tomli==2.2.1
# via
# black
# coverage
# pytest
tqdm==4.67.1
# via -r requirements.in
typing-extensions==4.15.0
# via
# black
# exceptiongroup
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ EMAP_PROJECT_NAME:
only_emap_setup

repositories:
emap_documentation:
internal_emap_documentation:
branch: main
# For testing outside the GAE, you can enable a fake UDS
fake_uds:
Expand Down
6 changes: 3 additions & 3 deletions emap-setup/tests/data/test-global-configuration-onlyhl7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ EMAP_PROJECT_NAME:
my_project_name

repositories:
core:
branch: main
emap:
branch: develop

rabbitmq:
SPRING_RABBITMQ_HOST: rabbitmq
Expand All @@ -34,7 +34,7 @@ dates:
common:
UDS_JDBC_URL: jdbc:postgresql://host.docker.internal:5432/ids

core:
uds:
UDS_SCHEMA: inform_schema
UDS_USERNAME: someuser
UDS_PASSWORD: redacted
Expand Down
31 changes: 9 additions & 22 deletions emap-setup/tests/data/test-global-configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ EMAP_PROJECT_NAME:
my_project_name

repositories:
InformDB:
branch: develop
hl7-vitals:
branch: main
repo_name: core
emap:
branch: develop

hoover:
branch: main

# Configuration data for the rabbitmq instance used by Spring in the pipeline

Expand Down Expand Up @@ -42,23 +41,11 @@ dates:
start: 2020-06-04T00:00:00.00Z
end:

informdb:
common:
UDS_JDBC_URL: jdbc:postgresql://host.docker.internal:5432/ids
core:
UDS_SCHEMA: inform_schema
UDS_USERNAME: someuser
UDS_PASSWORD: redacted
OMOP-ETL:
UDS_SCHEMA: inform_schema
UDS_USERNAME: someuser_omop
UDS_PASSWORD: redacted_omop
UDS_DDL_AUTO: update
INFORM_INIT_MODE: always
hl7-vitals:
UDS_SCHEMA: inform_schema_for_branch
UDS_USERNAME: someuseraaa
UDS_PASSWORD: redactedaaa
common:
UDS_JDBC_URL: jdbc:postgresql://host.docker.internal:5432/ids
UDS_SCHEMA: inform_schema
UDS_USERNAME: someuser
UDS_PASSWORD: redacted

# For testing outside the GAE, you can enable a fake UDS
fake_uds:
Expand Down
10 changes: 7 additions & 3 deletions emap-setup/tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
config_path_all = Path(
dirname(abspath(__file__)), "data", "test-global-configuration.yaml"
)
config_path_config_dir = Path(
dirname(abspath(__file__)), "data", "config"
)


@work_in_tmp_directory(to_copy=None)
Expand All @@ -36,14 +39,14 @@ def test_clone_then_clean_repos():
runner.run()

# Ensure that the cloned directory exists
assert exists("emap_documentation")
assert exists("internal_emap_documentation")
assert exists("config")

# and can be cleaned
runner = EMAPRunner(args=parser.parse_args(["setup", "-c"]), config=config)
runner.run()

assert not exists("emap_documentation")
assert not exists("internal_emap_documentation")


@work_in_tmp_directory(to_copy=None)
Expand All @@ -58,7 +61,7 @@ def test_double_clone():
runner = EMAPRunner(args=parser.parse_args(args), config=config)
runner.run()
# Make some un-pushed changes to newly cloned repo
file_to_keep = Path('emap_documentation/my_favourite_file.txt')
file_to_keep = Path('internal_emap_documentation/my_favourite_file.txt')
with open(file_to_keep, 'w') as fh:
fh.write("cheese")

Expand Down Expand Up @@ -148,6 +151,7 @@ def test_validation_source_arguments_set_correct_runner_attributes(args_list,
(1, 1, False),
(2, 1, True),
])
@work_in_tmp_directory(to_copy=[config_path_config_dir])
def test_validation_timeout(num_trues, timeout_seconds, expect_raises):
parser = create_parser()
args = parser.parse_args(["validation", "--use-waveform", "--timeout", str(timeout_seconds / 3600)])
Expand Down
4 changes: 2 additions & 2 deletions emap-setup/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from shutil import rmtree, copy
from distutils.dir_util import copy_tree
import setuptools
from pathlib import Path
from tempfile import mkdtemp
from functools import wraps
Expand All @@ -22,7 +22,7 @@ def wrapped_function(*args, **kwargs):

for item in to_copy:
if Path(item).is_dir():
copy_tree(item, tmpdir_path)
setuptools.distutils.dir_util.copy_tree(item, tmpdir_path)
else:
copy(item, tmpdir_path)

Expand Down
Loading