Пример #1
0
def test_constructor__requirements():
    node = Node(requirements=id)
    assert_equal(node.requirements, frozenset([id]))
    node = Node(requirements=[id])
    assert_equal(node.requirements, frozenset([id]))
    node = Node(requirements=[id, str])
    assert_equal(node.requirements, frozenset([id, str]))
Пример #2
0
def test_is_done__subnode_output_changes(temp_folder):
    temp_file = os.path.join(temp_folder, "file.txt")
    subnode   = Node(output_files = temp_file)
    my_node   = Node(subnodes = subnode)
    assert not my_node.is_done
    set_file_contents(temp_file, "foo")
    assert my_node.is_done
Пример #3
0
def test_is_outdated__updates():
    my_node = Node(input_files  = "tests/data/timestamp_a_older",
                   output_files = "tests/data/timestamp_a_younger")
    assert not my_node.is_outdated
    my_node = Node(input_files  = "tests/data/timestamp_a_younger",
                   output_files = "tests/data/timestamp_a_older")
    assert my_node.is_outdated
Пример #4
0
def test_metanode__nodes():
    subnodes = [Node(), Node()]
    dependencies = [Node(), Node()]
    node = MetaNode(subnodes = iter(subnodes),
                    dependencies = iter(dependencies))
    assert_equal(node.subnodes, frozenset(subnodes))
    assert_equal(node.dependencies, frozenset(dependencies))
Пример #5
0
def test_run__exception__create_temp_dir():
    cfg_mock = flexmock(temp_root=_DUMMY_TEMP_ROOT)
    node_mock = flexmock(Node())
    node_mock.should_receive('_create_temp_dir').with_args(cfg_mock) \
      .and_raise(OSError()).ordered.once

    assert_raises(NodeUnhandledException, node_mock.run, cfg_mock)  # pylint: disable=E1103
Пример #6
0
        def test_function():
            node_mock = flexmock(Node())
            node_mock.should_receive('_create_temp_dir').with_args(cfg_mock) \
              .and_return(_DUMMY_TEMP).ordered.once
            node_mock.should_receive(key).and_raise(exception).ordered.once
            node_mock.should_receive('_remove_temp_dir').never

            assert_raises(expectation, node_mock.run, cfg_mock)  # pylint: disable=E1103
Пример #7
0
def test_run__order():
    cfg_mock  = flexmock(temp_root = "/tmp")
    node_mock = flexmock(Node())
    node_mock.should_receive("_setup").with_args(cfg_mock, "/tmp/xTMPx").ordered.once
    node_mock.should_receive("_run").with_args(cfg_mock, "/tmp/xTMPx").ordered.once
    node_mock.should_receive("_teardown").with_args(cfg_mock, "/tmp/xTMPx").ordered.once

    with MonkeypatchCreateTempDir():
        node_mock.run(cfg_mock) # pylint: disable=E1103
Пример #8
0
def test_is_done__output_changes(temp_folder):
    temp_file_1 = os.path.join(temp_folder, "file_1.txt")
    temp_file_2 = os.path.join(temp_folder, "file_2.txt")
    my_node   = Node(output_files = (temp_file_1, temp_file_2))
    assert not my_node.is_done
    set_file_contents(temp_file_1, "foo")
    assert not my_node.is_done
    set_file_contents(temp_file_2, "bar")
    assert my_node.is_done
Пример #9
0
def test_run__temp_dirs():
    def assert_dir(_, path):
        assert_equal(path, "/tmp/xTMPx")

    cfg_mock  = flexmock(temp_root = "/tmp")
    node_mock = flexmock(Node(),
                         _setup    = assert_dir,
                         _run      = assert_dir,
                         _teardown = assert_dir)

    with MonkeypatchCreateTempDir():
        node_mock.run(cfg_mock) # pylint: disable=E1103
Пример #10
0
    def _do_test_run__error_log__node_error(temp_folder, exception):
        temp = os.path.join(temp_folder, "xTMPx")
        cfg_mock = flexmock(temp_root=temp_folder)
        node_mock = flexmock(Node())
        node_mock.should_receive("_create_temp_dir").with_args(cfg_mock) \
          .and_return(temp).ordered.once
        node_mock.should_receive("_run").and_raise(exception).ordered.once

        os.mkdir(temp)
        assert_raises(NodeError, node_mock.run, cfg_mock)  # pylint: disable=E1103
        log_file = os.path.join(temp_folder, "xTMPx", "pipe.errors")
        assert os.path.exists(log_file)
        assert_in("Errors =", get_file_contents(log_file))
Пример #11
0
def test_run__order():
    cfg_mock = flexmock(temp_root=_DUMMY_TEMP_ROOT)
    node_mock = flexmock(Node())
    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
    node_mock.should_receive("_run").with_args(cfg_mock,
                                               _DUMMY_TEMP).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
Пример #12
0
    def _do_test_run__error_log__node_error(temp_folder, exception):
        cfg_mock = flexmock(temp_root = temp_folder)
        node_mock = flexmock(Node())
        node_mock.should_receive("_run").and_raise(exception).once

        try:
            os.mkdir(os.path.join(temp_folder, "xTMPx"))
            with MonkeypatchCreateTempDir(root = temp_folder, subfolder = "xTMPx"):
                # pylint: disable=E1103
                node_mock.run(cfg_mock) # pragma: no coverage
        except NodeError:
            log_file = os.path.join(temp_folder, "xTMPx", "pipe.errors")
            assert os.path.exists(log_file)
            assert_in("Errors =", get_file_contents(log_file))
            return
        assert False # pragma: no coverage
Пример #13
0
 def __get_node__(self, func, max_threads=1):
     """Gets the Node containing the passed function.
     If no Node exists, one is created and a map record
     is made
     :func: The passed function
     :max_threads: The maximum number of threads for
     a new node. If a node already exists for the function,
     this parameter is ignored.
     :return: A node encapsulating the function
     """
     if func in self.func_node_map:
         return self.func_node_map[func]
     else:
         node = Node(func, self, max_threads=max_threads)
         self.func_node_map[func] = node
         return node
Пример #14
0
def test__teardown__output_files_missing():
    node = Node(input_files=_EMPTY_FILE, output_files=_OUT_FILES)
    assert_raises(NodeError, node._teardown, None, None)
Пример #15
0
 def _do_test__setup__input_files_exist(kwargs):
     assert_raises(NodeError, Node(**kwargs)._setup, None, None)
Пример #16
0
def test__teardown__output_files():
    Node(input_files=_EMPTY_FILE, output_files=_IN_FILES)._teardown(None, None)
Пример #17
0
def test_is_done__no_output():
    assert Node().is_done
Пример #18
0
 def _do_test__setup__input_files_exist(kwargs):
     Node(**kwargs)._setup(None, None)
Пример #19
0
def test_is_outdated__input_but_no_output():
    assert not Node(input_files = _IN_FILES).is_outdated
Пример #20
0
def test_is_outdated__no_output():
    assert not Node().is_outdated
Пример #21
0
 def _do_test_constructor__iterable(key):
     sub_nodes = [Node(), Node()]
     my_node = Node(**{key: iter(sub_nodes)})
     assert_equal(getattr(my_node, key), frozenset(sub_nodes))
Пример #22
0
def test_is_outdated__output_but_no_input():
    assert not Node(output_files = _OUT_FILES).is_outdated
Пример #23
0
 def _do_test_constructor__none_nodes(key):
     my_node = Node(**{key: None})
     assert_equal(getattr(my_node, key), frozenset())
Пример #24
0
 def _do_test_constructor__single_node(key):
     sub_node = Node()
     my_node = Node(**{key: sub_node})
     assert_equal(getattr(my_node, key), frozenset([sub_node]))
Пример #25
0
 def test_function():
     node_mock = flexmock(Node())
     node_mock.should_receive(key).and_raise(exception).once
     with MonkeypatchCreateTempDir():
         node_mock.run(cfg_mock) # pylint: disable=E1103
Пример #26
0
 def _do_test_constructor__single_value(key, value):
     defaults = {"input_files": _EMPTY_FILE}
     defaults[key] = value
     node = Node(**defaults)
     expected = safe_coerce_to_frozenset(value)
     assert_equal(getattr(node, key), expected)
Пример #27
0

def test__teardown__output_files():
    Node(input_files=_EMPTY_FILE, output_files=_IN_FILES)._teardown(None, None)


def test__teardown__output_files_missing():
    node = Node(input_files=_EMPTY_FILE, output_files=_OUT_FILES)
    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)

Пример #28
0
 def _do_test_constructor__single_value(key, value):
     node   = Node(**{key : value})
     expected = safe_coerce_to_frozenset(value)
     assert_equal(getattr(node, key), expected)
Пример #29
0
def test__teardown__output_files():
    Node(output_files = _IN_FILES)._teardown(None, None)