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