Ejemplo n.º 1
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
Ejemplo n.º 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
Ejemplo n.º 3
0
def test_text_parser_invalid_json():
    with wrap() as wrapper:
        ast = AbstractSyntaxTree(wrapper)
        parser = TextFile(wrapper, ast)
        try:
            parser.parse('.', """
            doc.txt { "contents" : 123
            """)
            assert False, 'should raise UserFeedback'
        except dexy.exceptions.UserFeedback as e:
            assert 'unable to parse' in e.message
Ejemplo n.º 4
0
def test_text_parser_invalid_json():
    with wrap() as wrapper:
        ast = AbstractSyntaxTree(wrapper)
        parser = TextFile(wrapper, ast)
        try:
            parser.parse(
                '.', """
            doc.txt { "contents" : 123
            """)
            assert False, 'should raise UserFeedback'
        except dexy.exceptions.UserFeedback as e:
            assert 'unable to parse' in e.message
Ejemplo n.º 5
0
def test_text_parser_blank_lines():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = TextFile(wrapper, ast)
        parser.parse('.', "\n\n")
        ast.walk()
        docs = wrapper.roots
        assert len(docs) == 0
Ejemplo n.º 6
0
def test_text_parser_blank_lines():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = TextFile(wrapper, ast)
        parser.parse('.', "\n\n")
        ast.walk()
        docs = wrapper.roots
        assert len(docs) == 0
Ejemplo n.º 7
0
def test_text_parser_valid_json():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = TextFile(wrapper, ast)
        parser.parse('.', """
        doc.txt { "contents" : "123" }
        """)
        ast.walk()

        docs = wrapper.roots
        assert docs[0].key == "doc.txt"
        assert docs[0].args['contents'] == "123"
Ejemplo n.º 8
0
def test_text_parser_comments():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = TextFile(wrapper, ast)
        parser.parse('.', """
        valid.doc { "contents" : "foo" }
        # commented-out.doc
        """)
        ast.walk()

        assert len(wrapper.roots) == 1
        assert wrapper.roots[0].key == "valid.doc"
Ejemplo n.º 9
0
def test_text_parser_valid_json():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = TextFile(wrapper, ast)
        parser.parse('.', """
        doc.txt { "contents" : "123" }
        """)
        ast.walk()

        docs = wrapper.roots
        assert docs[0].key == "doc.txt"
        assert docs[0].args['contents'] == "123"
Ejemplo n.º 10
0
def test_text_parser_comments():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = TextFile(wrapper, ast)
        parser.parse(
            '.', """
        valid.doc { "contents" : "foo" }
        # commented-out.doc
        """)
        ast.walk()

        assert len(wrapper.roots) == 1
        assert wrapper.roots[0].key == "valid.doc"
Ejemplo n.º 11
0
def test_text_parser_virtual_file():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = TextFile(wrapper, ast)
        parser.parse('.', """
        virtual.txt { "contents" : "hello" }
        """)
        ast.walk()

        wrapper.transition('walked')
        wrapper.to_checked()

        wrapper.run()
        docs = wrapper.roots

        assert docs[0].key == "virtual.txt"
        assert str(docs[0].output_data()) == "hello"
Ejemplo n.º 12
0
def test_text_parser_virtual_file():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = TextFile(wrapper, ast)
        parser.parse(
            '.', """
        virtual.txt { "contents" : "hello" }
        """)
        ast.walk()

        wrapper.transition('walked')
        wrapper.to_checked()

        wrapper.run()
        docs = wrapper.roots

        assert docs[0].key == "virtual.txt"
        assert str(docs[0].output_data()) == "hello"