Esempio n. 1
0
def test_find_with_regex_filters_results_from_walk_using_regex_nonlazy(exists):
    ('Node#find_with_regex returns an evaluated list of nodes')
    nd = Node('/foo/bar')
    nd.walk = Mock()
    nd.walk.return_value = [
        "/foo/wisdom/aaa.py",
        "/foo/wisdom/bbb.txt",
        "/foo/wisdom/ccc.php",
        "/foo/wisdom/ddd.py",
    ]
    ret = nd.find_with_regex('[.]\w{3}$', lazy=False)
    ret.should.be.a(list)
    ret.should.equal([
        Node("/foo/wisdom/bbb.txt"),
        Node("/foo/wisdom/ccc.php"),
    ])
    nd.walk.assert_once_called_with(lazy=False)
Esempio n. 2
0
def test_find_with_regex_filters_results_from_walk_using_regex(exists):
    ('Node#find_with_regex returns a lazy list of nodes')
    nd = Node('/foo/bar')
    nd.walk = Mock()
    nd.walk.return_value = [
        "/foo/wisdom/aaa.py",
        "/foo/wisdom/bbb.txt",
        "/foo/wisdom/ccc.php",
        "/foo/wisdom/ddd.py",
    ]
    ret = nd.find_with_regex('[.]\w{3}$', lazy='passed-to-walk')
    ret.should.be.a('types.GeneratorType')
    list(ret).should.equal([
        Node("/foo/wisdom/bbb.txt"),
        Node("/foo/wisdom/ccc.php"),
    ])
    nd.walk.assert_once_called_with(lazy='passed-to-walk')
Esempio n. 3
0
def test_find_with_regex_filters_results_from_walk_using_regex_nonlazy(exists):
    ('Node#find_with_regex returns an evaluated list of nodes')
    nd = Node('/foo/bar')
    nd.walk = Mock()
    nd.walk.return_value = [
        "/foo/wisdom/aaa.py",
        "/foo/wisdom/bbb.txt",
        "/foo/wisdom/ccc.php",
        "/foo/wisdom/ddd.py",
    ]
    ret = nd.find_with_regex('[.]\w{3}$', lazy=False)
    ret.should.be.a(list)
    ret.should.equal([
        Node("/foo/wisdom/bbb.txt"),
        Node("/foo/wisdom/ccc.php"),
    ])
    nd.walk.assert_called_once_with(lazy=False)
Esempio n. 4
0
def test_find_with_regex_filters_results_from_walk_using_regex(exists):
    ('Node#find_with_regex returns a lazy list of nodes')
    nd = Node('/foo/bar')
    nd.walk = Mock()
    nd.walk.return_value = [
        "/foo/wisdom/aaa.py",
        "/foo/wisdom/bbb.txt",
        "/foo/wisdom/ccc.php",
        "/foo/wisdom/ddd.py",
    ]
    ret = nd.find_with_regex('[.]\w{3}$', lazy='passed-to-walk')
    ret.should.be.a('types.GeneratorType')
    list(ret).should.equal([
        Node("/foo/wisdom/bbb.txt"),
        Node("/foo/wisdom/ccc.php"),
    ])
    nd.walk.assert_called_once_with(lazy='passed-to-walk')
Esempio n. 5
0
class PipelineScanner(object):
    def __init__(self, lookup_path):
        self.node = Node(lookup_path)
        self.found = self.find_python_files()

    def find_python_files(self):
        found = []
        for node in self.node.find_with_regex("pipelines.py$"):
            module_name = "{0}.{1}".format(
                node.dir.basename,
                node.basename.replace('.py', ''),
            )
            try:
                found.append(imp.load_source(module_name, node.path))
            except (ImportError, SystemError):
                msg = "Failed to import \033[1;33m%s\033[0m"
                logger.exception(msg, str(node.path))

        return found

    def get_pipelines(self):
        return Registry.pipelines_by_name()