Пример #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
Пример #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"])
Пример #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"))
Пример #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)
Пример #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
Пример #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)))
Пример #7
0
def _CommandNodeWrap(**kwargs):
    return CommandNode(command=AtomicCmd("true"), **kwargs)
Пример #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)
Пример #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)
Пример #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")
Пример #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)
Пример #12
0
 def _do_test_commandnode_setup(kwargs):
     cmd_mock = _build_cmd_mock(**kwargs)
     node = CommandNode(cmd_mock)
     node._setup(None, None)
Пример #13
0
def test_commandnode_constructor__dependencies__default():
    cmd_mock = CommandNode(command=_SIMPLE_CMD_MOCK, subnodes=_SIMPLE_SUBS)
    assert_equal(cmd_mock.dependencies, frozenset())
Пример #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)