Skip to content

Commit 4b94f27

Browse files
committed
Fixing tests depending of the new code architecture
1 parent fb04dcf commit 4b94f27

5 files changed

Lines changed: 82 additions & 82 deletions

File tree

tests/FakeGirderClient.py

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ def authenticate(self, apiKey):
88
return True
99

1010
def resourceLookup(self, path):
11-
return {'_id': 'fake_id', '_modelType': 'folder'}
11+
if path == '/vip/Home/test-VipLauncher-Backup/OUTPUTS':
12+
# Used to test the backup location, linked to the fake fetFolder method
13+
print("FakeGirderClient: resourceLookup called with path:", path)
14+
return {'_id': 'fake_id', '_modelType': 'folder'}
15+
elif path == '/vip/Home/test-VipLauncher-Backup-Special/OUTPUTS':
16+
print("FakeGirderClient: resourceLookup called with path:", path)
17+
return {'_id': 'different_id', '_modelType': 'folder'}
18+
else:
19+
return {'_id': 'other_id', '_modelType': 'folder'}
1220

1321
def createFolder(self, parentId, name, reuseExisting=True, **kwargs):
1422
return {'_id': 'fake_id'}
@@ -17,18 +25,42 @@ def addMetadataToFolder(self, folderId, metadata):
1725
return True
1826

1927
def getFolder(cls, folderId):
20-
metadata = {
21-
'input_settings': {
22-
'zipped_folder': 'fake_value',
23-
'basis_file': 'fake_value',
24-
'signal_file': ['fake_value', 'fake_value'],
25-
'control_file': ['fake_value']},
26-
"pipeline_id": cls.pipeline_id,
27-
'session_name': 'test-VipLauncher',
28-
'workflows': {},
29-
"vip_output_dir": "/vip/Home/test-VipLauncher/OUTPUTS"
30-
}
31-
return {'_id': 'fake_id', 'meta': metadata}
28+
if folderId == 'fake_id':
29+
print("FakeGirderClient: getFolder called with folderId:", folderId)
30+
metadata = {
31+
'input_settings': {
32+
'zipped_folder': 'fake_value1',
33+
'basis_file': 'fake_value2',
34+
'signal_file': ['fake_value3', 'fake_value4'],
35+
'control_file': ['fake_value5']
36+
},
37+
"pipeline_id": cls.pipeline_id,
38+
'session_name': 'test-VipLauncher',
39+
'workflows': {},
40+
"vip_output_dir": "/vip/Home/test-VipLauncher-Backup/OUTPUTS",
41+
'output_location': 'girder',
42+
'local_output_dir': '/path/to/local/output',
43+
}
44+
return {'_id': 'fake_id', 'meta': metadata}
45+
elif folderId == 'different_id':
46+
print("FakeGirderClient: getFolder called with folderId:", folderId)
47+
metadata = {
48+
'input_settings': {
49+
'zipped_folder': 'different_value1',
50+
'basis_file': 'different_value2',
51+
'signal_file': ['different_value3', 'different_value4'],
52+
'control_file': ['different_value5']
53+
},
54+
"pipeline_id": cls.pipeline_id,
55+
'session_name': 'test-VipLauncher-Special',
56+
'workflows': {},
57+
"vip_output_dir": "/vip/Home/test-VipLauncher-Backup-Special/OUTPUTS",
58+
'output_location': 'girder',
59+
'local_output_dir': '/path/to/local/output',
60+
}
61+
return {'_id': 'different_id', 'meta': metadata}
62+
else:
63+
return {'_id': 'fake_id', 'meta': {}}
3264

3365
def get(self, path):
3466
return {'_id': 'fake_id'}

tests/mocked_services.py

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ def fake_list_elements(self):
7777
def fake_exists(path):
7878
return False
7979

80-
#mocker.patch("vip_client.utils.vip.exists", side_effect = fake_exists)
80+
def fake_delete_path(path):
81+
return True
82+
83+
# mocker.patch("vip_client.utils.vip.exists", side_effect = fake_exists)
84+
mocker.patch("vip_client.utils.vip.exists").return_value = True
8185
mocker.patch("vip_client.utils.vip.upload").return_value = True
8286
mocker.patch("vip_client.utils.vip.download").return_value = True
8387
mocker.patch("vip_client.utils.vip.pipeline_def").side_effect = fake_pipeline_def
@@ -86,6 +90,7 @@ def fake_exists(path):
8690
mocker.patch("vip_client.utils.vip.init_exec").side_effect = fake_init_exec
8791
mocker.patch("vip_client.utils.vip.execution_info").side_effect = fake_execution_info
8892
mocker.patch("vip_client.utils.vip.list_elements").side_effect = fake_list_elements
93+
mocker.patch("vip_client.utils.vip.delete_path").side_effect = fake_delete_path
8994

9095
def mock_pathlib(mocker):
9196

@@ -102,50 +107,6 @@ def fake_pathlib_iterdir():
102107

103108
def mock_os(mocker):
104109
mocker.patch("os.unlink")
105-
106-
class FakeGirderClient():
107-
108-
pipeline_id = "LCModel/0.1"
109-
def __init__(self, apiUrl):
110-
pass
111-
def authenticate(self, apiKey):
112-
return True
113-
114-
def resourceLookup(self, path):
115-
return {'_id': 'fake_id', '_modelType': 'folder'}
116-
117-
def createFolder(self, parentId, name, reuseExisting=True, **kwargs):
118-
return {'_id': 'fake_id'}
119-
120-
def addMetadataToFolder(self, folderId, metadata):
121-
return True
122-
123-
def getFolder(cls, folderId):
124-
metadata = {
125-
'input_settings': {
126-
'zipped_folder': 'fake_value',
127-
'basis_file': 'fake_value',
128-
'signal_file': ['fake_value', 'fake_value'],
129-
'control_file': ['fake_value']},
130-
"pipeline_id": cls.pipeline_id,
131-
'session_name': 'test-VipLauncher',
132-
'workflows': {},
133-
"vip_output_dir": "/vip/Home/test-VipLauncher/OUTPUTS"
134-
}
135-
return {'_id': 'fake_id', 'meta': metadata}
136-
137-
def get(self, path):
138-
return {'_id': 'fake_id'}
139-
140-
def listFiles(self, folderId):
141-
return [{'_id': 'fake_id'}]
142-
143-
def listItem(self, folderId):
144-
return {'_id': 'fake_id'}
145-
146-
@classmethod
147-
def set_pipeline_id(cls, pipeline_id):
148-
cls.pipeline_id = pipeline_id
149110

150111
def mock_girder_client(mocker):
151112
from FakeGirderClient import FakeGirderClient

tests/test_VipGirder.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,8 @@ def fake_execution_info(workflow_id):
8282
mocker.patch("vip_client.utils.vip.execution_info").side_effect = fake_execution_info
8383

8484
# Launch a Full Session Run
85-
s = VipGirder()
85+
s = VipGirder(output_location="girder", session_name='test-VipLauncher', output_dir=PurePosixPath("/vip/Home/test-VipLauncher/OUTPUTS"))
8686
s.pipeline_id = pipeline_id
87-
s.output_dir = PurePosixPath("/vip/Home/test-VipLauncher/OUTPUTS")
8887
s.input_settings = {
8988
"zipped_folder": 'fake_value',
9089
"basis_file": 'fake_value',
@@ -107,21 +106,21 @@ def fake_execution_info(workflow_id):
107106
"basis_file": 'fake_value2',
108107
"signal_file": ['fake_value3', 'fake_value4'],
109108
"control_file": ['fake_value5']
110-
}, "LCModel/0.1", PurePosixPath("/vip/Home/test-VipLauncher/OUTPUTS"),
109+
}, "LCModel/0.1", PurePosixPath("/vip/Home/test-VipLauncher-Backup/OUTPUTS"),
111110
),
112111
(None, {
113112
"zipped_folder": None,
114113
"basis_file": None,
115114
"signal_file": None,
116115
"control_file": None
117-
}, "LCModel/0.1", PurePosixPath("/vip/Home/test-VipLauncher/OUTPUTS"),
116+
}, "LCModel/0.1", PurePosixPath("/vip/Home/test-VipLauncher-Backup/OUTPUTS"),
118117
),
119118
('girder', {
120119
"zipped_folder": 'different_value1',
121120
"basis_file": 'different_value2',
122121
"signal_file": ['different_value3', 'different_value4'],
123122
"control_file": ['different_value5']
124-
}, "LCModel/0.1", PurePosixPath("/vip/Home/test-VipLauncher/OUTPUTS"),
123+
}, "LCModel/0.1", PurePosixPath("/vip/Home/test-VipLauncher-Backup-Special/OUTPUTS"),
125124
)
126125
]
127126
)
@@ -130,12 +129,13 @@ def test_backup(mocker, backup_location, input_settings, pipeline_id, output_dir
130129
VipGirder._BACKUP_LOCATION = backup_location
131130

132131
# Create session
133-
s1 = VipGirder(pipeline_id=pipeline_id, input_settings=input_settings)
134-
s1.output_dir = output_dir
132+
s1 = VipGirder(pipeline_id=pipeline_id, input_settings=input_settings, output_dir=output_dir)
133+
135134

136135
assert s1._save() is not (VipGirder._BACKUP_LOCATION is None) # Return False if no backup location
137136

138137
# Load backup
138+
print("S1.OUTPUT_DIR", s1.output_dir)
139139
s2 = VipGirder(output_dir=s1.output_dir)
140140
# Check parameters
141141
assert s2.output_dir == s1.output_dir

tests/test_VipLauncher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def fake_delete_path(path):
9494
assert s.workflows[wid]["status"] == "Finished"
9595
assert s.pipeline_id == pipeline_id
9696
# Finish the Session
97-
s.finish(timeout=1)
97+
s.finish(timeout=1, keep_input=True, keep_output=True)
9898
# Check Deletion
9999
assert removed
100100
for wid in s.workflows:

tests/test_global.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"zipped_folder": 'fake_value1',
2323
"basis_file": 'fake_value2',
2424
},
25-
{
26-
}
25+
# {
26+
# }
2727
]
2828

2929
# VipSession trouve pas que l'input est vide quand on a '' et non []
@@ -66,19 +66,22 @@ def setup_teardown_vip_launcher(request, mocker):
6666
VipGirder.init(vip_key="FAKE_KEY", girder_key="FAKE_KEY")
6767
print("Setup done")
6868

69-
69+
# BIZARRE
7070
@pytest.mark.parametrize(
7171
"input_settings, tested_class", test_cases_missing_input_fields
7272
)
73-
def test_missing_input_settings(input_settings, tested_class):
73+
def test_missing_input_settings(mocker, input_settings, tested_class):
7474

7575
VipGirder._BACKUP_LOCATION = None
7676

7777
# Copy the first session
78-
s = VipGirder()
78+
s = tested_class(session_name="test-VipLauncher", input_settings=input_settings)
7979
s.pipeline_id = "LCModel/0.1"
80-
s.output_dir = "/path/to/output"
81-
s.input_settings = input_settings
80+
if tested_class == VipLauncher:
81+
s.output_dir = "/path/to/output"
82+
if tested_class == VipSession:
83+
mocker.patch.object(VipSession, '_exists', return_value=True)
84+
s.input_dir = "."
8285

8386
needed_fields = ["zipped_folder", "basis_file", "signal_file"]
8487
missing_fields = [field for field in needed_fields if field not in input_settings]
@@ -113,22 +116,26 @@ def is_input_full(value):
113116
mocker.patch("pathlib.Path.is_file").return_value = True
114117

115118
# Copy the first session
116-
s = tested_class()
117-
s.pipeline_id = "LCModel/0.1"
118-
if tested_class == VipSession:
119-
mocker.patch.object(VipSession, '_exists', return_value=True)
120-
s.input_dir = "."
121-
else:
122-
s.output_dir = "/path/to/output"
119+
120+
#else:
121+
#s.output_dir = "/path/to/output"
123122

124123
missing_fields = [field for field in input_settings if not is_input_full(input_settings[field])]
125124

126125
if not missing_fields:
127-
s.input_settings = input_settings
126+
s = tested_class(input_settings=input_settings, session_name="test-VipLauncher")
127+
s.pipeline_id = "LCModel/0.1"
128+
if tested_class == VipSession:
129+
mocker.patch.object(VipSession, '_exists', return_value=True)
130+
s.input_dir = "."
128131
s.run_session()
129132
return
130133
# Catch the exception message
131134
with pytest.raises(ValueError) as e:
132-
s.input_settings = input_settings
135+
s = tested_class(input_settings=input_settings, session_name="test-VipLauncher")
136+
s.pipeline_id = "LCModel/0.1"
137+
if tested_class == VipSession:
138+
mocker.patch.object(VipSession, '_exists', return_value=True)
139+
s.input_dir = "."
133140
s.run_session()
134141
assert str(e.value) == "Missing input value(s) for parameter(s): " + ", ".join(sorted(missing_fields))

0 commit comments

Comments
 (0)