Created
March 1, 2016 14:07
-
-
Save milliams/43bb69cf7f18dc398526 to your computer and use it in GitHub Desktop.
Example pytest fixtures for little ganga
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
from Ganga.GPIDev.Base.Proxy import stripProxy | |
@pytest.yield_fixture | |
def ganga(): | |
""" | |
Provide the ganga GPI and runtime to the test | |
""" | |
import ganga | |
yield ganga | |
ganga.jobs.clean(confirm=True) # This could be anything but simple for now | |
@pytest.fixture | |
def monitor(): | |
""" | |
A function to run a job to completion | |
""" | |
def monitor_job(j): | |
j = stripProxy(j) | |
b = type(j.backend) | |
while True: | |
print('j.status') | |
if j.status in ['completed', 'failed']: | |
return True | |
b.master_updateMonitoringInformation([j]) | |
return monitor_job |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_ganga(ganga, monitor): | |
""" | |
Test that we can submit and monitor jobs | |
""" | |
j = ganga.Job() | |
j.submit() | |
monitor(j) | |
assert j.status == 'completed' | |
def test_cleanup(ganga): | |
""" | |
Test that the jobs registry is cleaned | |
""" | |
assert len(ganga.jobs) == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment