# Path: xtuml/meta.py
# def relate(from_instance, to_instance, rel_id, phrase=''):
#     '''
#     Relate *from_instance* to *to_instance* across *rel_id*. For reflexive
#     association, a *phrase* indicating the direction must also be provided.
#     
#     The two instances are related to each other by copying the identifying 
#     attributes from the instance on the TO side of a association to the instance
#     n the FROM side. Updated values which affect existing associations are 
#     propagated. A set of all affected instances will be returned.
#     '''
#     if None in [from_instance, to_instance]:
#         return False
# 
#     inst1, inst2, ass = _find_link(from_instance, to_instance, rel_id, phrase)
#     if not ass.source_link.connect(inst1, inst2):
#         raise RelateException(from_instance, to_instance, rel_id, phrase)
# 
#     if not ass.target_link.connect(inst2, inst1):
#         raise RelateException(from_instance, to_instance, rel_id, phrase)
#     
#     return True
# 
# Path: xtuml/meta.py
# def navigate_one(self, instance):
#     '''
#     Navigate from *instance* across the link.
#     '''
#     return next(iter(self.navigate(instance)), None)


import unittest
import xtuml
from xtuml import relate
from xtuml import navigate_one as one
        l = xtuml.ModelLoader()
        l.input(s1)
        s2 = xtuml.serialize(l.build_metamodel())
        self.assertTrue(s1 == s2)

    def test_relate_across_one(self):
        cls1 = self.m.new('Reflexive')
        cls2 = self.m.new('Reflexive')

        self.assertTrue(relate(cls1, cls2, 1, 'one'))
        self.assertEqual(cls1.Ref_ID, cls2.ID)

    def test_relate_across_other(self):
        cls1 = self.m.new('Reflexive')
        cls2 = self.m.new('Reflexive')

        self.assertTrue(relate(cls1, cls2, 1, 'other'))
        self.assertEqual(cls2.Ref_ID, cls1.ID)

    def test_navgate_across_one(self):
        cls1 = self.m.new('Reflexive')
        cls2 = self.m.new('Reflexive', Ref_ID=cls1.ID)

        self.assertEqual(one(cls1).Reflexive[1, 'one'](), cls2)
        self.assertFalse(one(cls2).Reflexive[1, 'one']())

    def test_navgate_across_other(self):
        cls1 = self.m.new('Reflexive')
        cls2 = self.m.new('Reflexive', Ref_ID=cls1.ID)


# Path: xtuml/meta.py
# def relate(from_instance, to_instance, rel_id, phrase=''):
#     '''
#     Relate *from_instance* to *to_instance* across *rel_id*. For reflexive
#     association, a *phrase* indicating the direction must also be provided.
#     
#     The two instances are related to each other by copying the identifying 
#     attributes from the instance on the TO side of a association to the instance
#     n the FROM side. Updated values which affect existing associations are 
#     propagated. A set of all affected instances will be returned.
#     '''
#     if None in [from_instance, to_instance]:
#         return False
# 
#     inst1, inst2, ass = _find_link(from_instance, to_instance, rel_id, phrase)
#     if not ass.source_link.connect(inst1, inst2):
#         raise RelateException(from_instance, to_instance, rel_id, phrase)
# 
#     if not ass.target_link.connect(inst2, inst1):
#         raise RelateException(from_instance, to_instance, rel_id, phrase)
#     
#     return True
# 
# Path: xtuml/meta.py
# def navigate_one(self, instance):
#     '''
#     Navigate from *instance* across the link.
#     '''
#     return next(iter(self.navigate(instance)), None)


# Path: tests/test_xtuml/test_phrase.py
import unittest
import xtuml
from xtuml import relate
from xtuml import navigate_one as one

        l = xtuml.ModelLoader()
        l.input(s1)
        s2 = xtuml.serialize(l.build_metamodel())
        self.assertTrue(s1 == s2)

    def test_relate_across_one(self):
        cls1 = self.m.new('Reflexive')
        cls2 = self.m.new('Reflexive')

        self.assertTrue(relate(cls1, cls2, 1, 'one'))
        self.assertEqual(cls1.Ref_ID, cls2.ID)

    def test_relate_across_other(self):
        cls1 = self.m.new('Reflexive')
        cls2 = self.m.new('Reflexive')

        self.assertTrue(relate(cls1, cls2, 1, 'other'))
        self.assertEqual(cls2.Ref_ID, cls1.ID)

    def test_navgate_across_one(self):
        cls1 = self.m.new('Reflexive')
        cls2 = self.m.new('Reflexive', Ref_ID=cls1.ID)

        self.assertEqual(one(cls1).Reflexive[1, 'one'](), cls2)
        self.assertFalse(one(cls2).Reflexive[1, 'one']())

    def test_navgate_across_other(self):
        cls1 = self.m.new('Reflexive')
        cls2 = self.m.new('Reflexive', Ref_ID=cls1.ID)


        self.assertEqual(one(cls2).Reflexive[1, 'other'](), cls1)