示例#1
0
 def test_duplicate_field_subclass_attribute_3(self):
     with self.assertRaisesRegexp(KeyError, "Redefinition of field"):
         metamodel.MetaModel(
             'root = MetaModel()\n'
             'el = Element(of=root, name="Test")\n'
             'Attribute(of=el, name="duplicate")\n'
             'subel = Element(of=root, name="SubTest", extends=el)\n'
             'Attribute(of=subel, name="duplicate")\n')
示例#2
0
 def test_unsatisfiable_self_association_constraint(self):
     with self.assertRaisesRegexp(AttributeError,
                                  "Self-associations must be optional"):
         metamodel.MetaModel(
             'root = MetaModel()\n'
             'el = el2 = Element(of=root, name="Test")\n'
             'Association(parent=el, child=el2, parentname="a", childname="b", optional=False)\n'
         )
示例#3
0
 def test_association_limit_as_string(self):
     with self.assertRaisesRegexp(AttributeError,
                                  "Limit '.*' must be a positive integer"):
         metamodel.MetaModel(
             'root = MetaModel()\n'
             'el = Element(of=root, name="Test")\n'
             'el2 = Element(of=root, name="Test2")\n'
             'Association(parent=el, child=el2, parentname="a", childname="b", limit="2")\n'
         )
示例#4
0
 def test_underscore_field_child_list(self):
     with self.assertRaisesRegexp(
             AttributeError,
             "Association child names can not start with an underscore"):
         metamodel.MetaModel(
             'root = MetaModel()\n'
             'el = Element(of=root, name="Test")\n'
             'Association(parent=el, child=el, parentname="good", childname="_wrong", optional=True)\n'
         )
示例#5
0
 def test_duplicate_field_self_reference(self):
     with self.assertRaisesRegexp(
             AttributeError,
             "Can't use the same names when defining a self-association"):
         metamodel.MetaModel(
             'root = MetaModel()\n'
             'el = Element(of=root, name="Test")\n'
             'Association(parent=el, child=el, parentname="duplicate", childname="duplicate", optional=True)\n'
         )
示例#6
0
 def test_duplicate_field_childlist(self):
     with self.assertRaisesRegexp(KeyError, "Redefinition of field"):
         metamodel.MetaModel(
             'root = MetaModel()\n'
             'el = Element(of=root, name="Test")\n'
             'el2 = Element(of=root, name="Test2")\n'
             'Association(parent=el, child=el2, parentname="dummy1", childname="duplicate")\n'
             'Association(parent=el, child=el2, parentname="dummy2", childname="duplicate")\n'
         )
示例#7
0
 def test_unsatisfiable_cyclic_association_constraint(self):
     with self.assertRaisesRegexp(
             AttributeError, "Required associations can not be cyclic"):
         metamodel.MetaModel(
             'root = MetaModel()\n'
             'el = Element(of=root, name="Test")\n'
             'el2 = Element(of=root, name="Test2")\n'
             'Association(parent=el, child=el2, parentname="a", childname="b", optional=False)\n'
             'Association(parent=el2, child=el, parentname="c", childname="d", optional=False)\n'
         )
示例#8
0
 def setUp(self):
     self.instance = metamodel.MetaModel(
         'root = MetaModel()\n'
         'el = Element(of=root, name="Test")\n'
         'ab = Element(of=root, name="Abstract", extends=el, abstract=True)\n'
         'Element(of=root, name="SubTest", extends=ab)\n'
         'el2 = Element(of=root, name="Test2")\n'
         'Element(of=root, name="SubTest2", extends=el2)\n'
         'Attribute(of=el, name="attr")\n'
         'Association(parent=el, child=el2, parentname="a", childname="a", limit=2)\n'
         'Association(parent=el, child=el2, parentname="b", childname="b", optional=True)\n'
     ).instance()
示例#9
0
    def test_mof(self):
        mof = metamodel.load("mof.m3")
        modeldesc = str(mof).split("\n")
        self.assertTrue("    Element extends (optional)" in modeldesc)
        self.assertTrue("  Element MetaModel" in modeldesc)
        self.assertTrue("    <attribute> limit" in modeldesc)

        net = mof.instance().load("petrinets.m2")
        repr(net)
        mofi = mof.instance().load("mof.m3")
        mofdesc = repr(mofi)

        mof2 = metamodel.MetaModel(mofdesc)
        mofi2 = mof2.instance().parse(mofdesc)
示例#10
0
 def test_keyword_attribute(self):
     with self.assertRaisesRegexp(SyntaxError,
                                  "Python keywords are not allowed"):
         metamodel.MetaModel('root = MetaModel()\n'
                             'el = Element(of=root, name="Test")\n'
                             'Attribute(of=el, name="import")\n')
示例#11
0
 def test_duplicate_element(self):
     with self.assertRaisesRegexp(KeyError, "Redefinition of Element"):
         metamodel.MetaModel('root = MetaModel()\n'
                             'Element(of=root, name="Duplicate")\n'
                             'Element(of=root, name="Duplicate")\n')
示例#12
0
 def test_underscore_field_attribute(self):
     with self.assertRaisesRegexp(
             AttributeError, "Attributes can not start with an underscore"):
         metamodel.MetaModel('root = MetaModel()\n'
                             'el = Element(of=root, name="Test")\n'
                             'Attribute(of=el, name="_duplicate")\n')