-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathtest_RWR.py
More file actions
62 lines (53 loc) · 2.59 KB
/
test_RWR.py
File metadata and controls
62 lines (53 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import shutil
from filecmp import cmp
from pathlib import Path
import pytest
import spras.config.config as config
from spras.config.container_schema import ContainerFramework, ProcessedContainerSettings
from spras.rwr import RWR, RWRParams
config.init_from_file("config/config.yaml")
TEST_DIR = Path('test', 'algorithms', 'RWR/')
OUT_FILE = Path(TEST_DIR, 'output', 'rwr-output.txt')
class TestRWR:
"""
Run the RWR algorithm on the example input files and check the output matches the expected output
"""
def test_rwr(self):
OUT_FILE.unlink(missing_ok=True)
RWR.run({"network": Path(TEST_DIR, 'input', 'rwr-network.txt'),
"nodes": Path(TEST_DIR, 'input','rwr-nodes.txt')},
args=RWRParams(alpha=0.85, threshold=200),
output_file=OUT_FILE)
assert OUT_FILE.exists(), 'Output file was not written'
expected_file = Path(TEST_DIR, 'expected_output', 'rwr-output.txt')
assert cmp(OUT_FILE, expected_file, shallow=False), 'Output file does not match expected output file'
"""
Run the RWR algorithm with a missing input file
"""
def test_missing_file(self):
with pytest.raises(OSError):
RWR.run({"network": Path(TEST_DIR, 'input', 'missing.txt'),
"nodes": Path(TEST_DIR, 'input','rwr-nodes.txt')},
args=RWRParams(alpha=0.85, threshold=200),
output_file=OUT_FILE)
"""
Run the RWR algorithm with an improperly formatted network file
"""
def test_format_error(self):
with pytest.raises(ValueError):
RWR.run({"network": Path(TEST_DIR, 'input', 'rwr-bad-network.txt'),
"nodes": Path(TEST_DIR, 'input','rwr-nodes.txt')},
args=RWRParams(alpha=0.85, threshold=200),
output_file=OUT_FILE)
# Only run Singularity test if the binary is available on the system
# spython is only available on Unix, but do not explicitly skip non-Unix platforms
@pytest.mark.skipif(not shutil.which('singularity'), reason='Singularity not found on system')
def test_rwr_singularity(self):
OUT_FILE.unlink(missing_ok=True)
# Only include required arguments and run with Singularity
RWR.run({"network": Path(TEST_DIR, 'input', 'rwr-network.txt'),
"nodes": Path(TEST_DIR, 'input','rwr-nodes.txt')},
args=RWRParams(alpha=0.85, threshold=200),
output_file=OUT_FILE,
container_settings=ProcessedContainerSettings(framework=ContainerFramework.singularity))
assert OUT_FILE.exists()