def test_delete_link_no_matching_link(self): a = self.c1.association(self.c2, "l: 0..1 -> *") o1 = CObject(self.c1, "o1") o2 = CObject(self.c1, "o2") o3 = CObject(self.c2, "o3") o4 = CObject(self.c2, "o4") o5 = CObject(self.c2, "o5") add_links({o1: [o3, o4], o2: [o5]}, association=a) try: delete_links({o1: o5}) exception_expected_() except CException as e: eq_(e.value, "no link found for 'o1 -> o5' in delete links") b = self.c1.association(self.c2, "l: 0..1 -> *") try: delete_links({o1: o5}) exception_expected_() except CException as e: eq_(e.value, "no link found for 'o1 -> o5' in delete links") try: o4.delete_links([o1], association=b) exception_expected_() except CException as e: eq_( e.value, "no link found for 'o4 -> o1' in delete links for given association" )
def test_delete_one_to_n_links(self): self.c1.association(self.c2, "l: 0..1 -> *") o1 = CObject(self.c1, "o1") o2 = CObject(self.c1, "o2") o3 = CObject(self.c2, "o3") o4 = CObject(self.c2, "o4") o5 = CObject(self.c2, "o5") add_links({o1: [o3, o4], o2: [o5]}) o4.delete_links([o1]) eq_(o1.linked, [o3]) eq_(o2.linked, [o5]) eq_(o3.linked, [o1]) eq_(o4.linked, []) eq_(o5.linked, [o2]) o4.add_links([o2]) eq_(o2.linked, [o5, o4]) delete_links({o1: o3, o2: o2.linked}) eq_(o1.linked, []) eq_(o2.linked, []) eq_(o3.linked, []) eq_(o4.linked, []) eq_(o5.linked, [])
def test_delete_n_to_n_links(self): self.c1.association(self.c2, "l: * -> *") o1 = CObject(self.c1, "o1") o2 = CObject(self.c1, "o2") o3 = CObject(self.c2, "o3") o4 = CObject(self.c2, "o4") o5 = CObject(self.c2, "o5") o6 = CObject(self.c2, "o6") add_links({o1: [o3, o4], o2: [o4, o5]}) o4.delete_links([o1, o2]) eq_(o1.linked, [o3]) eq_(o2.linked, [o5]) eq_(o3.linked, [o1]) eq_(o4.linked, []) eq_(o5.linked, [o2]) add_links({o4: [o1, o2], o6: [o2, o1]}) delete_links({o1: o6, o2: [o4, o5]}) eq_(o1.linked, [o3, o4]) eq_(o2.linked, [o6]) eq_(o3.linked, [o1]) eq_(o4.linked, [o1]) eq_(o5.linked, []) eq_(o6.linked, [o2])
def test_delete_one_to_one_link(self): self.m1.association(self.m2, "l: 1 -> [c2] 0..1") c1 = CClass(self.m1, "c1") c2 = CClass(self.m2, "c2") c3 = CClass(self.m1, "c3") c4 = CClass(self.m2, "c4") links = add_links({c1: c2, c3: c4}) c1.delete_links(c2) eq_(c1.linked, []) eq_(c2.linked, []) eq_(c3.linked, [c4]) eq_(c4.linked, [c3]) eq_(c1.links, []) eq_(c2.links, []) eq_(c3.links, [links[1]]) eq_(c4.links, [links[1]]) delete_links({c3: c4}) eq_(c1.linked, []) eq_(c2.linked, []) eq_(c3.linked, []) eq_(c4.linked, []) eq_(c1.links, []) eq_(c2.links, []) eq_(c3.links, []) eq_(c4.links, [])
def test_delete_one_to_one_link(self): self.c1.association(self.c2, "l: 1 -> [c2] 0..1") o1 = CObject(self.c1, "o1") o2 = CObject(self.c2, "o2") o3 = CObject(self.c1, "o3") o4 = CObject(self.c2, "o4") links = add_links({o1: o2, o3: o4}) o1.delete_links(o2) eq_(o1.linked, []) eq_(o2.linked, []) eq_(o3.linked, [o4]) eq_(o4.linked, [o3]) eq_(o1.links, []) eq_(o2.links, []) eq_(o3.links, [links[1]]) eq_(o4.links, [links[1]]) delete_links({o3: o4}) eq_(o1.linked, []) eq_(o2.linked, []) eq_(o3.linked, []) eq_(o4.linked, []) eq_(o1.links, []) eq_(o2.links, []) eq_(o3.links, []) eq_(o4.links, [])
def test_delete_one_to_n_links(self): self.m1.association(self.m2, "l: 0..1 -> *") c1 = CClass(self.m1, "c1") c2 = CClass(self.m1, "c2") c3 = CClass(self.m2, "c3") c4 = CClass(self.m2, "c4") c5 = CClass(self.m2, "c5") add_links({c1: [c3, c4], c2: [c5]}) c4.delete_links([c1]) eq_(c1.linked, [c3]) eq_(c2.linked, [c5]) eq_(c3.linked, [c1]) eq_(c4.linked, []) eq_(c5.linked, [c2]) c4.add_links([c2]) eq_(c2.linked, [c5, c4]) delete_links({c1: c3, c2: c2.linked}) eq_(c1.linked, []) eq_(c2.linked, []) eq_(c3.linked, []) eq_(c4.linked, []) eq_(c5.linked, [])
def test_delete_link_no_matching_link(self): a = self.m1.association(self.m2, "l: 0..1 -> *") c1 = CClass(self.m1, "c1") c2 = CClass(self.m1, "c2") c3 = CClass(self.m2, "c3") c4 = CClass(self.m2, "c4") c5 = CClass(self.m2, "c5") add_links({c1: [c3, c4], c2: [c5]}, association=a) try: delete_links({c1: c5}) exception_expected_() except CException as e: eq_(e.value, "no link found for 'c1 -> c5' in delete links") b = self.m1.association(self.m2, "l: 0..1 -> *") try: delete_links({c1: c5}) exception_expected_() except CException as e: eq_(e.value, "no link found for 'c1 -> c5' in delete links") try: c4.delete_links([c1], association=b) exception_expected_() except CException as e: eq_(e.value, "no link found for 'c4 -> c1' in delete links for given association")
def test_delete_n_to_n_links(self): self.m1.association(self.m2, "l: * -> *") c1 = CClass(self.m1, "c1") c2 = CClass(self.m1, "c2") c3 = CClass(self.m2, "c3") c4 = CClass(self.m2, "c4") c5 = CClass(self.m2, "c5") c6 = CClass(self.m2, "c6") add_links({c1: [c3, c4], c2: [c4, c5]}) c4.delete_links([c1, c2]) eq_(c1.linked, [c3]) eq_(c2.linked, [c5]) eq_(c3.linked, [c1]) eq_(c4.linked, []) eq_(c5.linked, [c2]) add_links({c4: [c1, c2], c6: [c2, c1]}) delete_links({c1: c6, c2: [c4, c5]}) eq_(c1.linked, [c3, c4]) eq_(c2.linked, [c6]) eq_(c3.linked, [c1]) eq_(c4.linked, [c1]) eq_(c5.linked, []) eq_(c6.linked, [c2])
def run(): print( "***************** Shopping Model Instance Model 1 (Using Shopping Model 4) *****************" ) print("*** Attribute Getting / Setting") print_attribute_getting_setting_examples() print("*** Link Introspection") print_link_introspection_examples() print('*** Plant UML Generation') generator = PlantUMLGenerator() generator.generate_object_models("shopping_instance1", [ shopping_instance1_order_model, { "render_association_names_when_no_label_is_given": True }, shopping_instance1_staff_model, { "render_association_names_when_no_label_is_given": True } ]) # change links to generate the "wrong" staff model as well delete_links({manager: [crm1, crm2]}) add_links({manager: [crm1, crm2]}, association=staff_reports_to_relation) shopping_instance1_staff_model.name = shopping_instance1_staff_model.name + "_wrong" generator.generate_object_models("shopping_instance1", [ shopping_instance1_staff_model, { "render_association_names_when_no_label_is_given": True } ]) # correct the links again delete_links({manager: [crm1, crm2]}) add_links({manager: [crm1, crm2]}, role_name="managed") print( f"... Generated models in {generator.directory!s}/shopping_instance1")
def test_link_methods_wrong_keyword_args(self): c1 = CClass(self.m1, "C1") try: add_links({c1: c1}, associationX=None) exception_expected_() except CException as e: eq_(e.value, "unknown keywords argument") try: c1.add_links(c1, associationX=None) exception_expected_() except CException as e: eq_(e.value, "unknown keywords argument") try: set_links({c1: c1}, associationX=None) exception_expected_() except CException as e: eq_(e.value, "unknown keywords argument") try: c1.delete_links(c1, associationX=None) exception_expected_() except CException as e: eq_(e.value, "unknown keywords argument") try: delete_links({c1: c1}, associationX=None) exception_expected_() except CException as e: eq_(e.value, "unknown keywords argument") try: c1.get_linked(associationX=None) exception_expected_() except CException as e: eq_(e.value, "unknown keywords argument") try: delete_links({c1: c1}, stereotype_instances=None) exception_expected_() except CException as e: eq_(e.value, "unknown keywords argument")
def test_delete_link_select_by_association(self): a = self.c1.association(self.c2, "a: * -> *") b = self.c1.association(self.c2, "b: * -> *") o1 = CObject(self.c1, "o1") o2 = CObject(self.c1, "o2") o3 = CObject(self.c2, "o3") o4 = CObject(self.c2, "o4") add_links({o1: [o3], o2: [o3, o4]}, association=b) delete_links({o2: o3}) eq_(o1.linked, [o3]) eq_(o2.linked, [o4]) eq_(o3.linked, [o1]) eq_(o4.linked, [o2]) add_links({o1: [o3], o2: [o3, o4]}, association=a) try: delete_links({o1: o3}) exception_expected_() except CException as e: eq_( e.value, "link definition in delete links ambiguous for link 'o1->o3': found multiple matches" ) delete_links({o1: o3, o2: o4}, association=b) eq_(o1.linked, [o3]) eq_(o2.linked, [o3, o4]) eq_(o3.linked, [o1, o2]) eq_(o4.linked, [o2]) for o in [o1, o2, o3, o4]: for lo in o.links: eq_(lo.association, a) o1.add_links(o3, association=b) try: o1.delete_links(o3) exception_expected_() except CException as e: eq_( e.value, "link definition in delete links ambiguous for link 'o1->o3': found multiple matches" ) eq_(o1.linked, [o3, o3]) eq_(o2.linked, [o3, o4]) eq_(o3.linked, [o1, o2, o1]) eq_(o4.linked, [o2]) o1.delete_links(o3, association=a) eq_(o1.linked, [o3]) eq_(o2.linked, [o3, o4]) eq_(o3.linked, [o2, o1]) eq_(o4.linked, [o2])
def test_delete_link_select_by_association(self): a = self.m1.association(self.m2, "a: * -> *") b = self.m1.association(self.m2, "b: * -> *") c1 = CClass(self.m1, "c1") c2 = CClass(self.m1, "c2") c3 = CClass(self.m2, "c3") c4 = CClass(self.m2, "c4") add_links({c1: [c3], c2: [c3, c4]}, association=b) delete_links({c2: c3}) eq_(c1.linked, [c3]) eq_(c2.linked, [c4]) eq_(c3.linked, [c1]) eq_(c4.linked, [c2]) add_links({c1: [c3], c2: [c3, c4]}, association=a) try: delete_links({c1: c3}) exception_expected_() except CException as e: eq_(e.value, "link definition in delete links ambiguous for link 'c1->c3': found multiple matches") delete_links({c1: c3, c2: c4}, association=b) eq_(c1.linked, [c3]) eq_(c2.linked, [c3, c4]) eq_(c3.linked, [c1, c2]) eq_(c4.linked, [c2]) for o in [c1, c2, c3, c4]: for lo in o.links: eq_(lo.association, a) c1.add_links(c3, association=b) try: c1.delete_links(c3) exception_expected_() except CException as e: eq_(e.value, "link definition in delete links ambiguous for link 'c1->c3': found multiple matches") eq_(c1.linked, [c3, c3]) eq_(c2.linked, [c3, c4]) eq_(c3.linked, [c1, c2, c1]) eq_(c4.linked, [c2]) c1.delete_links(c3, association=a) eq_(c1.linked, [c3]) eq_(c2.linked, [c3, c4]) eq_(c3.linked, [c2, c1]) eq_(c4.linked, [c2])
def test_link_methods_wrong_keyword_args(self): o1 = CObject(self.c1, "o1") try: add_links({o1: o1}, associationX=None) exception_expected_() except CException as e: eq_(e.value, "unknown keywords argument") try: o1.add_links(o1, associationX=None) exception_expected_() except CException as e: eq_(e.value, "unknown keywords argument") try: set_links({o1: o1}, associationX=None) exception_expected_() except CException as e: eq_(e.value, "unknown keywords argument") try: delete_links({o1: o1}, associationX=None) exception_expected_() except CException as e: eq_(e.value, "unknown keywords argument") try: o1.delete_links(o1, associationX=None) exception_expected_() except CException as e: eq_(e.value, "unknown keywords argument") try: o1.get_linked(associationX=None) exception_expected_() except CException as e: eq_(e.value, "unknown keywords argument") try: delete_links({o1: o1}, stereotype_instances=None) exception_expected_() except CException as e: eq_(e.value, "unknown keywords argument") try: delete_links({o1: o1}, tagged_values=None) exception_expected_() except CException as e: eq_(e.value, "unknown keywords argument")
def test_delete_link_select_by_role_name(self): a = self.c1.association(self.c2, "a: [sourceA] * -> [targetA] *") self.c1.association(self.c2, "b: [sourceB] * -> [targetB] *") o1 = CObject(self.c1, "o1") o2 = CObject(self.c1, "o2") o3 = CObject(self.c2, "o3") o4 = CObject(self.c2, "o4") add_links({o1: [o3], o2: [o3, o4]}, role_name="targetB") delete_links({o2: o3}) eq_(o1.linked, [o3]) eq_(o2.linked, [o4]) eq_(o3.linked, [o1]) eq_(o4.linked, [o2]) add_links({o1: [o3], o2: [o3, o4]}, role_name="targetA") delete_links({o1: o3, o2: o4}, role_name="targetB") eq_(o1.linked, [o3]) eq_(o2.linked, [o3, o4]) eq_(o3.linked, [o1, o2]) eq_(o4.linked, [o2]) for o in [o1, o2, o3, o4]: for lo in o.links: eq_(lo.association, a) add_links({o1: [o3], o2: [o3, o4]}, role_name="targetB") o3.delete_links([o1, o2], role_name="sourceB") delete_links({o4: o2}, role_name="sourceB") eq_(o1.linked, [o3]) eq_(o2.linked, [o3, o4]) eq_(o3.linked, [o1, o2]) eq_(o4.linked, [o2]) for o in [o1, o2, o3, o4]: for lo in o.links: eq_(lo.association, a)
def test_delete_link_select_by_role_name(self): a = self.m1.association(self.m2, "a: [sourceA] * -> [targetA] *") self.m1.association(self.m2, "b: [sourceB] * -> [targetB] *") c1 = CClass(self.m1, "c1") c2 = CClass(self.m1, "c2") c3 = CClass(self.m2, "c3") c4 = CClass(self.m2, "c4") add_links({c1: [c3], c2: [c3, c4]}, role_name="targetB") delete_links({c2: c3}) eq_(c1.linked, [c3]) eq_(c2.linked, [c4]) eq_(c3.linked, [c1]) eq_(c4.linked, [c2]) add_links({c1: [c3], c2: [c3, c4]}, role_name="targetA") delete_links({c1: c3, c2: c4}, role_name="targetB") eq_(c1.linked, [c3]) eq_(c2.linked, [c3, c4]) eq_(c3.linked, [c1, c2]) eq_(c4.linked, [c2]) for o in [c1, c2, c3, c4]: for lo in o.links: eq_(lo.association, a) add_links({c1: [c3], c2: [c3, c4]}, role_name="targetB") c3.delete_links([c1, c2], role_name="sourceB") delete_links({c4: c2}, role_name="sourceB") eq_(c1.linked, [c3]) eq_(c2.linked, [c3, c4]) eq_(c3.linked, [c1, c2]) eq_(c4.linked, [c2]) for o in [c1, c2, c3, c4]: for lo in o.links: eq_(lo.association, a)
def test_wrong_types_delete_links(self): self.c1.association(self.c2, name="l", multiplicity="1") o1 = CObject(self.c1, "o1") o2 = CObject(self.c2, "o2") try: # noinspection PyTypeChecker delete_links(o1) exception_expected_() except CException as e: eq_( e.value, "link definitions should be of the form " + "{<link source 1>: <link target(s) 1>, ..., <link source n>: <link target(s) n>}" ) try: delete_links({o1: self.mcl}) exception_expected_() except CException as e: eq_(e.value, "link target 'MCL' is not an object, class, or link") try: delete_links({o1: [o2, self.mcl]}) exception_expected_() except CException as e: eq_(e.value, "link target 'MCL' is not an object, class, or link") try: delete_links({o1: [o2, None]}) exception_expected_() except CException as e: eq_(e.value, "link target 'None' is not an object, class, or link") try: delete_links({self.mcl: o2}) exception_expected_() except CException as e: eq_(e.value, "link source 'MCL' is not an object, class, or link") try: delete_links({None: o2}) exception_expected_() except CException as e: eq_(e.value, "link should not contain an empty source")