Пример #1
0
def test_parse_default():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', YAML_WITH_DEFAULT_OFF)
        ast.walk()
        assert len(wrapper.nodes) == 0

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

        ast = AbstractSyntaxTree(wrapper)
        wrapper.full = True
        parser = Yaml(wrapper, ast)
        parser.parse('.', YAML_WITH_DEFAULT_OFF)
        ast.walk()
        assert len(wrapper.nodes) == 1
Пример #2
0
def test_single_bundle_doc_with_args_2():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse(
            '.', """

      -  hello:
            - foo: bar
            - filter_fruit: orange
            - args:
                - ping: pong
            - another-task:
                - foo: baz
                - yet-another-task:
                    - foo: bar
            - one-more-task

      -  more:
            - hello
            - one-more-task
            - foo: bar

        """)

        ast.walk()

        assert wrapper.roots[0].key_with_class() == "bundle:more"
        assert len(wrapper.nodes) == 5
Пример #3
0
def test_single_bundle_doc_with_args_2():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', """

      -  hello:
            - foo: bar
            - filter_fruit: orange
            - args:
                - ping: pong
            - another-task:
                - foo: baz
                - yet-another-task:
                    - foo: bar
            - one-more-task

      -  more:
            - hello
            - one-more-task
            - foo: bar

        """)

        ast.walk()

        assert wrapper.roots[0].key_with_class() == "bundle:more"
        assert len(wrapper.nodes) == 5
Пример #4
0
def test_parse_default():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', YAML_WITH_DEFAULT_OFF)
        ast.walk()
        assert len(wrapper.nodes) == 0

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

        ast = AbstractSyntaxTree(wrapper)
        wrapper.full = True
        parser = Yaml(wrapper, ast)
        parser.parse('.', YAML_WITH_DEFAULT_OFF)
        ast.walk()
        assert len(wrapper.nodes) == 1
Пример #5
0
def test_invalid_yaml():
    with wrap() as wrapper:
        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        try:
            parser.parse('.', INVALID_YAML)
            assert False, "should raise UserFeedback"
        except dexy.exceptions.UserFeedback as e:
            assert 'YAML' in e.message
Пример #6
0
def test_invalid_yaml():
    with wrap() as wrapper:
        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        try:
            parser.parse('.', INVALID_YAML)
            assert False, "should raise UserFeedback"
        except dexy.exceptions.UserFeedback as e:
            assert 'YAML' in e.message
Пример #7
0
def test_parse_inactive():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', YAML_WITH_INACTIVE)
        ast.walk()
        assert len(wrapper.nodes) == 0
Пример #8
0
def test_parse_inactive():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', YAML_WITH_INACTIVE)
        ast.walk()
        assert len(wrapper.nodes) == 0
Пример #9
0
def test_children_siblings_order():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', """
        p1:
            - c1
            - c2:
                - g1
                - g2
                - g3
            - c3
        """)
        ast.walk()
        wrapper.transition('walked')

        wrapper.to_checked()

        wrapper.run()

        p1 = wrapper.nodes['bundle:p1']
        assert [i.key_with_class() for i in p1.walk_inputs()] == [
                'bundle:c1',
                'bundle:c2',
                'bundle:g1',
                'bundle:g2',
                'bundle:g3',
                'bundle:c3'
                ]

        c1 = wrapper.nodes['bundle:c1']
        assert len(c1.inputs) == 0

        c2 = wrapper.nodes['bundle:c2']
        assert [i.key_with_class() for i in c2.walk_inputs()] == [
                'bundle:g1',
                'bundle:g2',
                'bundle:g3'
                ]

        c3 = wrapper.nodes['bundle:c3']
        assert len(c3.inputs) == 0

        g3 = wrapper.nodes['bundle:g3']
        assert len(g3.inputs) == 0
Пример #10
0
def test_single_bundle_doc():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', "hello")
        ast.walk()
        wrapper.transition('walked')
        wrapper.to_checked()
        assert "bundle:hello" in wrapper.nodes
Пример #11
0
def test_single_bundle_doc():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', "hello")
        ast.walk()
        wrapper.transition('walked')
        wrapper.to_checked()
        assert "bundle:hello" in wrapper.nodes
Пример #12
0
def test_yaml_parser():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', YAML)
        for doc in wrapper.roots:
            assert doc.__class__.__name__ == 'BundleNode'
            assert doc.key in ['code', 'wordpress']

        wrapper.run_docs()
Пример #13
0
def test_yaml_parser():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', YAML)
        for doc in wrapper.roots:
            assert doc.__class__.__name__ == 'BundleNode'
            assert doc.key in ['code', 'wordpress']

        wrapper.run_docs()
Пример #14
0
def test_except_patterndoc():
    with wrap() as wrapper:
        with open("exceptme.abc", "w") as f:
            f.write("hello")

        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.abc' """)
        ast.walk()

        assert len(wrapper.nodes) == 1
Пример #15
0
def test_except_patterndoc():
    with wrap() as wrapper:
        with open("exceptme.abc", "w") as f:
            f.write("hello")

        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.abc' """)
        ast.walk()

        assert len(wrapper.nodes) == 1
Пример #16
0
def test_yaml_with_defaults():
    with wrap() as wrapper:
        os.makedirs("s1/s2")

        with open("s1/s2/hello.txt", "w") as f:
            f.write("hello")

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

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', YAML_WITH_DEFAULTS)
        ast.walk()

        assert wrapper.roots[0].args['foo'] == 'bar'
Пример #17
0
def test_yaml_with_defaults():
    with wrap() as wrapper:
        os.makedirs("s1/s2")

        with open("s1/s2/hello.txt", "w") as f:
            f.write("hello")

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

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', YAML_WITH_DEFAULTS)
        ast.walk()

        assert wrapper.roots[0].args['foo'] == 'bar'
Пример #18
0
def test_children_siblings_order():
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse(
            '.', """
        p1:
            - c1
            - c2:
                - g1
                - g2
                - g3
            - c3
        """)
        ast.walk()
        wrapper.transition('walked')

        wrapper.to_checked()

        wrapper.run()

        p1 = wrapper.nodes['bundle:p1']
        assert [i.key_with_class() for i in p1.walk_inputs()] == [
            'bundle:c1', 'bundle:c2', 'bundle:g1', 'bundle:g2', 'bundle:g3',
            'bundle:c3'
        ]

        c1 = wrapper.nodes['bundle:c1']
        assert len(c1.inputs) == 0

        c2 = wrapper.nodes['bundle:c2']
        assert [i.key_with_class() for i in c2.walk_inputs()
                ] == ['bundle:g1', 'bundle:g2', 'bundle:g3']

        c3 = wrapper.nodes['bundle:c3']
        assert len(c3.inputs) == 0

        g3 = wrapper.nodes['bundle:g3']
        assert len(g3.inputs) == 0
Пример #19
0
def test_single_file_doc():
    with wrap() as wrapper:
        with open("hello.txt", "w") as f:
            f.write("hello")

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

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', "hello.txt")
        ast.walk()
        wrapper.transition('walked')

        wrapper.to_checked()

        wrapper.run()
        assert "doc:hello.txt" in wrapper.nodes
Пример #20
0
def test_single_file_doc():
    with wrap() as wrapper:
        with open("hello.txt", "w") as f:
            f.write("hello")

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

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', "hello.txt")
        ast.walk()
        wrapper.transition('walked')

        wrapper.to_checked()

        wrapper.run()
        assert "doc:hello.txt" in wrapper.nodes
Пример #21
0
def run_yaml_with_target(target):
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', YAML)
        ast.walk()

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

        assert len(wrapper.roots) == 3
        assert len(wrapper.nodes) == 8

        wrapper.target = target
        wrapper.run()

        yield wrapper
Пример #22
0
def run_yaml_with_target(target):
    with wrap() as wrapper:
        wrapper.nodes = {}
        wrapper.roots = []
        wrapper.batch = dexy.batch.Batch(wrapper)
        wrapper.filemap = wrapper.map_files()

        ast = AbstractSyntaxTree(wrapper)
        parser = Yaml(wrapper, ast)
        parser.parse('.', YAML)
        ast.walk()

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

        assert len(wrapper.roots) == 3
        assert len(wrapper.nodes) == 8

        wrapper.target = target
        wrapper.run()

        yield wrapper