Skip to content

Commit f7caf93

Browse files
committed
Added test for file resource
1 parent d62c139 commit f7caf93

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

tests/test_resource.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from os.path import join
2+
3+
from pyflow import FileResource, Notebook, Suite
4+
from pyflow.host import SSHHost
5+
6+
7+
def test_file_resource():
8+
9+
resouces_directory = "/resources_directory"
10+
11+
sshhost_1 = SSHHost("example_ssh_host_1", resources_directory=resouces_directory)
12+
sshhost_2 = SSHHost("example_ssh_host_2", resources_directory=resouces_directory)
13+
host_set = [sshhost_1, sshhost_2]
14+
15+
source_file = "./tests/file_resource.txt"
16+
name = "file_resource"
17+
18+
with Suite("s", host=sshhost_1) as s:
19+
s.resource_file = FileResource(name, hosts=host_set, source_file=source_file)
20+
21+
# Check that variables are set correctly
22+
assert s.resource_file.host == sshhost_1
23+
assert s.resource_file.location() == join(
24+
str(sshhost_1.resources_directory), s.name, name
25+
)
26+
assert s.resource_file._hosts == host_set
27+
28+
# Check that the deployment scripts have been generated
29+
s.check_definition()
30+
s.generate_node()
31+
32+
s.deploy_suite(target=Notebook)
33+
34+
generate_file_resource_script_lines, _ = s.resource_file.generate_script()
35+
assert any(sshhost_1.name in s for s in generate_file_resource_script_lines)
36+
assert any(sshhost_2.name in s for s in generate_file_resource_script_lines)
37+
38+
39+
if __name__ == "__main__":
40+
from os import path
41+
42+
import pytest
43+
44+
pytest.main(path.abspath(__file__))

0 commit comments

Comments
 (0)