Skip to content

Commit 4f583e6

Browse files
vsochMarDiehl
andauthored
Test on GitHub (#185)
* Test different python versions * GitHub CI now has singularity. * specify version * better be careful with actions not under control of GitHub or any other trusted source * standard invocation * failure in one python version does not cancel the others https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstrategyfail-fast * use default number of columns * testing giving instances a name Signed-off-by: vsoch <[email protected]> Co-authored-by: Martin Diehl <[email protected]>
1 parent 64358eb commit 4f583e6

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

.github/workflows/main.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,29 @@ jobs:
2828
export PATH="/usr/share/miniconda/bin:$PATH"
2929
source activate black
3030
pyflakes spython/oci spython/image spython/instance spython/main
31+
32+
pytest:
33+
runs-on: ubuntu-latest
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
python-version: [3.7, 3.8, 3.9]
38+
39+
steps:
40+
- uses: actions/checkout@v2
41+
- uses: eWaterCycle/setup-singularity@1631b12cf3878381179be0eab9624219bc12979e # v6 release
42+
43+
- name: Set up Python ${{ matrix.python-version }}
44+
uses: actions/setup-python@v2
45+
with:
46+
python-version: ${{ matrix.python-version }}
47+
48+
- name: Install dependencies
49+
run: |
50+
sudo ln -s $SINGULARITY_ROOT/bin/singularity /usr/bin/
51+
python -m pip install --upgrade pip
52+
pip install pytest semver pytest-runner requests
53+
54+
- name: Run unit tests
55+
run: |
56+
pytest

spython/tests/test_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ def test_docker_pull(docker_container):
4343
def test_execute(docker_container):
4444
result = Client.execute(docker_container[1], "ls /")
4545
print(result)
46+
if isinstance(result, list):
47+
result = "".join(result)
4648
assert "tmp\nusr\nvar" in result
4749

4850

4951
def test_execute_with_return_code(docker_container):
5052
result = Client.execute(docker_container[1], "ls /", return_result=True)
5153
print(result)
54+
if isinstance(result["message"], list):
55+
result["message"] = "".join(result["message"])
5256
assert "tmp\nusr\nvar" in result["message"]
5357
assert result["return_code"] == 0
5458

spython/tests/test_instances.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
import pytest
1010
from spython.main import Client
1111

12+
# name instance based on Python version in case running in parallel
13+
import sys
14+
15+
version_string = "%s_%s_%s" % (
16+
sys.version_info[0],
17+
sys.version_info[1],
18+
sys.version_info[2],
19+
)
20+
1221

1322
def test_instance_class():
1423
instance = Client.instance("docker://ubuntu", start=False)
@@ -28,13 +37,10 @@ def test_has_no_instances():
2837

2938
class TestInstanceFuncs(object):
3039
@pytest.fixture(autouse=True)
31-
def cleanup(self):
32-
yield
33-
Client.instance_stopall()
34-
3540
def test_instance_cmds(self, docker_container):
3641
image = docker_container[1]
37-
myinstance = Client.instance(image)
42+
instance_name = "instance1_" + version_string
43+
myinstance = Client.instance(image, name=instance_name)
3844
assert myinstance.get_uri().startswith("instance://")
3945

4046
print("...Case 2: List instances")
@@ -58,12 +64,13 @@ def test_instance_cmds(self, docker_container):
5864
myinstance.stop()
5965
instances = Client.instances()
6066
assert instances == []
61-
myinstance1 = Client.instance(image)
62-
myinstance2 = Client.instance(image)
67+
myinstance1 = Client.instance(image, name="instance1_" + version_string)
68+
myinstance2 = Client.instance(image, name="instance2_" + version_string)
6369
assert myinstance1 is not None
6470
assert myinstance2 is not None
6571
instances = Client.instances()
6672
assert len(instances) == 2
67-
Client.instance_stopall()
73+
myinstance1.stop()
74+
myinstance2.stop()
6875
instances = Client.instances()
6976
assert instances == []

0 commit comments

Comments
 (0)