def test_with_3a(): dsl_contents = cleandoc(''' var = 3 with MissingClass: var = 4 ''') with pytest.raises(NameError): dsltool.parse_dsl(dsl_contents, BaseDsl)
def test_basic_1(): dsl_contents = cleandoc(''' var = 3 ''') result1 = dsltool.parse_dsl(dsl_contents, BasicDsl) assert result1.var == 3 result2 = dsltool.parse_dsl(dsl_contents, BasicPropertyDsl) assert result2.var == 3
def test_with_2a(): dsl_contents = cleandoc(''' var = 3 with ChildDsl: child_var = 4 with ChildDsl: child_var = 5 ''') with pytest.raises(AttributeError): dsltool.parse_dsl(dsl_contents, BaseDsl)
def test_basic_3(): dsl_contents = cleandoc(''' class Foo(object): def get_3(self): return 3 foo = Foo() var = foo.get_3() ''') result1 = dsltool.parse_dsl(dsl_contents, BasicDsl) assert result1.var == 3 result2 = dsltool.parse_dsl(dsl_contents, BasicPropertyDsl) assert result2.var == 3
def test_with_1a(): dsl_contents = cleandoc(''' ''') result = dsltool.parse_dsl(dsl_contents, BaseDsl) assert result.var == None assert result.child_dsl is None
def test_item_list_1(): dsl_contents = cleandoc(''' items += 1 items += 2 ''') result = dsltool.parse_dsl(dsl_contents, ItemListDsl) assert result.items == [1,2]
def test_item_list_1(): dsl_contents = cleandoc(''' items += 1 items += 2 ''') result = dsltool.parse_dsl(dsl_contents, ItemListDsl) assert result.items == [1, 2]
def test_listof_1b(): dsl_contents = cleandoc(''' with ChildDsl(): pass ''') result = dsltool.parse_dsl(dsl_contents, ListOfDsl) assert len(result.child_dsl) == 1 assert type(result.child_dsl[0]) is ChildDsl
def test_with_1c1(): dsl_contents = cleandoc(''' var = 3 with ChildDsl as c: c.child_var = 4 ''') result = dsltool.parse_dsl(dsl_contents, BaseDsl) assert result.var == 3 assert result.child_dsl.child_var == 4 assert result.child_dsl.grandchild_dsl is None
def test_with_0b1(): dsl_contents = cleandoc(''' var = 3 with ChildDsl() as c: c.child_var = 4 with GrandchildDsl() as g: g.grandchild_var = 5 ''') result = dsltool.parse_dsl(dsl_contents, BaseDsl) assert result.var == 3 assert result.child_dsl.child_var == 4 assert result.child_dsl.grandchild_dsl.grandchild_var == 5
def test_listof_2a(): dsl_contents = cleandoc(''' with ChildDsl: child_var = 0 with ChildDsl: child_var = 1 ''') result = dsltool.parse_dsl(dsl_contents, ListOfDsl) assert len(result.child_dsl) == 2 for i, child in enumerate(result.child_dsl): assert type(child) is ChildDsl assert child.child_var == i
def test_listof_0(): dsl_contents = cleandoc(''' ''') result = dsltool.parse_dsl(dsl_contents, ListOfDsl) assert result.child_dsl == []