예제 #1
0
파일: test_node.py 프로젝트: aioupload/dexy
def test_pattern_node():
    with wrap() as wrapper:
        with open("foo.txt", "w") as f:
            f.write("foo!")

        with open("bar.txt", "w") as f:
            f.write("bar!")

        wrapper = Wrapper(log_level='DEBUG')
        wrapper.to_valid()

        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        node = PatternNode("*.txt", 
                wrapper,
                [],
                foo="bar")
        assert node.args['foo'] == 'bar'
        wrapper.run_docs(node)
        assert len(node.children) == 2

        for child in node.children:
            assert child.__class__.__name__ == "Doc"
            assert child.args['foo'] == 'bar'
            assert child.key_with_class() in ["doc:foo.txt", "doc:bar.txt"]
            assert child.filters == []
예제 #2
0
def test_text_parser():
    with wrap() as wrapper:
        with open("f1.py", "w") as f:
            f.write("print 'hello'")

        with open("f2.py", "w") as f:
            f.write("print 'hello'")

        with open("index.md", "w") as f:
            f.write("")

        wrapper = Wrapper()
        wrapper.to_valid()

        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = TextFile(wrapper, ast)
        parser.parse(".", """
        *.py
        *.py|pyg
        *.md|jinja
        """)
        ast.walk()
        assert len(wrapper.nodes) == 8
예제 #3
0
def test_pattern_node():
    with wrap() as wrapper:
        with open("foo.txt", "w") as f:
            f.write("foo!")

        with open("bar.txt", "w") as f:
            f.write("bar!")

        wrapper = Wrapper(log_level='DEBUG')
        wrapper.to_valid()

        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        node = PatternNode("*.txt", wrapper, [], foo="bar")
        assert node.args['foo'] == 'bar'
        wrapper.run_docs(node)
        assert len(node.children) == 2

        for child in node.children:
            assert child.__class__.__name__ == "Doc"
            assert child.args['foo'] == 'bar'
            assert child.key_with_class() in ["doc:foo.txt", "doc:bar.txt"]
            assert child.filters == []
예제 #4
0
def test_text_parser():
    with wrap() as wrapper:
        with open("f1.py", "w") as f:
            f.write("print 'hello'")

        with open("f2.py", "w") as f:
            f.write("print 'hello'")

        with open("index.md", "w") as f:
            f.write("")

        wrapper = Wrapper()
        wrapper.to_valid()

        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = TextFile(wrapper, ast)
        parser.parse(
            ".", """
        *.py
        *.py|pyg
        *.md|jinja
        """)
        ast.walk()
        assert len(wrapper.nodes) == 8
예제 #5
0
파일: test_node.py 프로젝트: aioupload/dexy
def test_pattern_node_one_filter():
    with wrap() as wrapper:
        with open("foo.txt", "w") as f:
            f.write("foo!")

        wrapper = Wrapper(log_level='DEBUG')
        wrapper.to_valid()

        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        node = PatternNode("*.txt|dexy", wrapper=wrapper)
        doc = node.children[0]
        assert doc.key == "foo.txt|dexy"
        assert doc.filter_aliases == ['dexy']
        assert doc.parent == node
예제 #6
0
def test_pattern_node_one_filter():
    with wrap() as wrapper:
        with open("foo.txt", "w") as f:
            f.write("foo!")

        wrapper = Wrapper(log_level='DEBUG')
        wrapper.to_valid()

        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        node = PatternNode("*.txt|dexy", wrapper=wrapper)
        doc = node.children[0]
        assert doc.key == "foo.txt|dexy"
        assert doc.filter_aliases == ['dexy']
        assert doc.parent == node
예제 #7
0
def test_except_patterndoc_pattern():
    with wrap() as wrapper:
        with open("exceptme.abc", "w") as f:
            f.write("hello")

        wrapper = Wrapper()
        wrapper.to_valid()

        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', """.abc:\n  - except : 'exceptme.*' """)
        ast.walk()
        wrapper.transition('walked')
        wrapper.to_checked()

        wrapper.run()

        assert len(wrapper.nodes) == 1
예제 #8
0
def test_except_patterndoc_pattern():
    with wrap() as wrapper:
        with open("exceptme.abc", "w") as f:
            f.write("hello")

        wrapper = Wrapper()
        wrapper.to_valid()

        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', """.abc:\n  - except : 'exceptme.*' """)
        ast.walk()
        wrapper.transition('walked')
        wrapper.to_checked()

        wrapper.run()

        assert len(wrapper.nodes) == 1