Skip to content

Commit

Permalink
Added test case for pyflow file resource
Browse files Browse the repository at this point in the history
  • Loading branch information
tbkr committed Jun 11, 2024
1 parent d62c139 commit dab0d83
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/test_resource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from os import path
from os.path import join

from pyflow import FileResource, Notebook, Suite
from pyflow.host import SSHHost


def test_file_resource():

resouces_directory = "/resources_directory"

sshhost_1 = SSHHost("example_ssh_host_1", resources_directory=resouces_directory)
sshhost_2 = SSHHost("example_ssh_host_2", resources_directory=resouces_directory)
host_set = [sshhost_1, sshhost_2]

source_file = path.join(path.dirname(path.abspath(__file__)), "file_resource.txt")
name = "file_resource"

with Suite("s", host=sshhost_1) as s:
s.resource_file = FileResource(name, hosts=host_set, source_file=source_file)

# Check that variables are set correctly
assert s.resource_file.host == sshhost_1
assert s.resource_file.location() == join(
str(sshhost_1.resources_directory), s.name, name
)
assert s.resource_file._hosts == host_set

# Check that the deployment scripts have been generated
s.check_definition()
s.generate_node()

s.deploy_suite(target=Notebook)

generate_file_resource_script_lines, _ = s.resource_file.generate_script()
assert any(sshhost_1.name in s for s in generate_file_resource_script_lines)
assert any(sshhost_2.name in s for s in generate_file_resource_script_lines)


if __name__ == "__main__":

import pytest

pytest.main(path.abspath(__file__))

0 comments on commit dab0d83

Please sign in to comment.