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
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
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
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
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
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
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
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()
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
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'
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
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
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