Exemplo n.º 1
0
def test_command_node__run():
    cfg_mock  = flexmock(temp_root = "/tmp")
    cmd_mock  = _build_cmd_mock()
    node_mock = flexmock(CommandNode(cmd_mock))
    node_mock.should_receive("_setup").with_args(cfg_mock, str).ordered.once
    node_mock.should_receive("_run").with_args(cfg_mock, str).ordered.once
    node_mock.should_receive("_teardown").with_args(cfg_mock, str).ordered.once
    with MonkeypatchCreateTempDir():
        node_mock.run(cfg_mock) # pylint: disable=E1103
Exemplo n.º 2
0
def test_commandnode_teardown__missing_optional_files(temp_folder):
    destination, temp_folder = _setup_temp_folders(temp_folder)

    cmd = AtomicCmd(("echo", "-n", "1 2 3"),
                    TEMP_OUT_BAR = "bar.txt",
                    OUT_STDOUT = os.path.join(destination, "foo.txt"))
    cmd.run(temp_folder)
    assert_equal(cmd.join(), [0])
    node = CommandNode(cmd)
    node._teardown(None, temp_folder)
    assert_equal(os.listdir(temp_folder), [])
    assert_equal(os.listdir(destination), ["foo.txt"])
Exemplo n.º 3
0
def test_commandnode_teardown(temp_folder):
    destination, temp_folder = _setup_temp_folders(temp_folder)

    cmd = AtomicCmd(("echo", "-n", "1 2 3"),
                    OUT_STDOUT = os.path.join(destination, "foo.txt"))
    cmd.run(temp_folder)
    assert_equal(cmd.join(), [0])
    node = CommandNode(cmd)
    assert os.path.exists(os.path.join(temp_folder, "foo.txt"))
    assert not os.path.exists(os.path.join(destination, "foo.txt"))
    node._teardown(None, temp_folder)
    assert not os.path.exists(os.path.join(temp_folder, "foo.txt"))
    assert os.path.exists(os.path.join(destination, "foo.txt"))
Exemplo n.º 4
0
def _test_commandnode_teardown__missing_files_in_dest(temp_folder):
    destination, temp_folder = _setup_temp_folders(temp_folder)
    class _CmdMock(AtomicCmd):
        def commit(self, temp):
            AtomicCmd.commit(self, temp)
            os.remove(os.path.join(destination, "foo.txt"))

    cmd = _CmdMock(("touch", "%(OUT_FOO)s", "%(OUT_BAR)s"),
                   OUT_FOO = os.path.join(destination, "foo.txt"),
                   OUT_BAR = os.path.join(destination, "bar.txt"))
    cmd.run(temp_folder)
    assert_equal(cmd.join(), [0])
    node = CommandNode(cmd)
    assert_raises(NodeError, node._teardown, None, temp_folder)
Exemplo n.º 5
0
def test_command_node__run():
    cfg_mock = flexmock(temp_root=_DUMMY_TEMP_ROOT)
    cmd_mock = _build_cmd_mock()
    node_mock = flexmock(CommandNode(cmd_mock))
    node_mock.should_receive("_create_temp_dir").with_args(cfg_mock) \
      .and_return(_DUMMY_TEMP).ordered.once
    node_mock.should_receive("_setup").with_args(cfg_mock,
                                                 _DUMMY_TEMP).ordered.once
    cmd_mock.should_receive("run").with_args(_DUMMY_TEMP).ordered.once
    cmd_mock.should_receive("join").and_return([0]).ordered.once
    node_mock.should_receive("_teardown").with_args(cfg_mock,
                                                    _DUMMY_TEMP).ordered.once
    node_mock.should_receive("_remove_temp_dir").with_args(
        _DUMMY_TEMP).ordered.once
    node_mock.run(cfg_mock)  # pylint: disable=E1103
Exemplo n.º 6
0
def test_commandnode_teardown__extra_files_in_temp(temp_folder):
    destination, temp_folder = _setup_temp_folders(temp_folder)

    cmd = AtomicCmd(("echo", "-n", "1 2 3"),
                    OUT_STDOUT = os.path.join(destination, "foo.txt"))
    cmd.run(temp_folder)
    assert_equal(cmd.join(), [0])
    node = CommandNode(cmd)
    set_file_contents(os.path.join(temp_folder, "bar.txt"), "1 2 3")
    temp_files_before = set(os.listdir(temp_folder))
    dest_files_before = set(os.listdir(destination))

    assert_raises(CmdNodeError, node._teardown, None, temp_folder)
    assert_equal(temp_files_before, set(os.listdir(temp_folder)))
    assert_equal(dest_files_before, set(os.listdir(destination)))
Exemplo n.º 7
0
def _CommandNodeWrap(**kwargs):
    return CommandNode(command=AtomicCmd("true"), **kwargs)
Exemplo n.º 8
0
def test_commandnode_teardown__commit(temp_folder):
    cmd_mock = _build_cmd_mock()
    cmd_mock.should_receive("commit").with_args(temp_folder).once
    node = CommandNode(cmd_mock)
    node._teardown(None, temp_folder)
Exemplo n.º 9
0
def test_commandnode_run__exception_on_error():
    cmd_mock = _build_cmd_mock()
    cmd_mock.should_receive("run").ordered.once
    cmd_mock.should_receive("join").and_return((1, )).ordered.once
    node = CommandNode(cmd_mock)
    assert_raises(CmdNodeError, node._run, None, None)
Exemplo n.º 10
0
def test_commandnode_run__call_order():
    cmd_mock = _build_cmd_mock()
    cmd_mock.should_receive("run").with_args("xTMPx").ordered.once
    cmd_mock.should_receive("join").with_args().and_return((0, )).ordered.once
    node = CommandNode(cmd_mock)
    node._run(None, "xTMPx")
Exemplo n.º 11
0
 def _do_test_commandnode_setup(kwargs):
     cmd_mock = _build_cmd_mock(**kwargs)
     node = CommandNode(cmd_mock)
     assert_raises(NodeError, node._setup, None, None)
Exemplo n.º 12
0
 def _do_test_commandnode_setup(kwargs):
     cmd_mock = _build_cmd_mock(**kwargs)
     node = CommandNode(cmd_mock)
     node._setup(None, None)
Exemplo n.º 13
0
def test_commandnode_constructor__dependencies__default():
    cmd_mock = CommandNode(command=_SIMPLE_CMD_MOCK, subnodes=_SIMPLE_SUBS)
    assert_equal(cmd_mock.dependencies, frozenset())
Exemplo n.º 14
0
    assert_raises(NodeError, node._teardown, None, None)


################################################################################
################################################################################
## CommandNode: Constructor

_SIMPLE_DEPS = Node()
_SIMPLE_SUBS = Node()
_SIMPLE_CMD_MOCK = flexmock(input_files=_IN_FILES,
                            output_files=_OUT_FILES,
                            executables=_EXEC_FILES,
                            auxiliary_files=_AUX_FILES,
                            requirements=_REQUIREMENTS)
_SIMPLE_CMD_NODE = CommandNode(command=_SIMPLE_CMD_MOCK,
                               subnodes=_SIMPLE_SUBS,
                               dependencies=_SIMPLE_DEPS)


def test_commandnode_constructor__input_files():
    assert_equal(_SIMPLE_CMD_NODE.input_files, _IN_FILES)


def test_commandnode_constructor__output_files():
    assert_equal(_SIMPLE_CMD_NODE.output_files, _OUT_FILES)


def test_commandnode_constructor__auxiliary_files():
    assert_equal(_SIMPLE_CMD_NODE.auxiliary_files, _AUX_FILES)