# 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
    '''
    CREATE TABLE Reflexive (
        ID UNIQUE_ID,
        Ref_ID UNIQUE_ID
    );

    CREATE ROP REF_ID R1
        FROM 1C Reflexive (Ref_ID) PHRASE 'one'
        TO 1C Reflexive (ID) PHRASE 'other';
    '''

    def setUp(self):
        l = xtuml.ModelLoader()
        l.input(self.__class__.__doc__)
        self.m = l.build_metamodel()
        
    def tearDown(self):
        del self.m

    def test_serialize(self):
        s1 = xtuml.serialize(self.m)
        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')


# 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

    '''
    CREATE TABLE Reflexive (
        ID UNIQUE_ID,
        Ref_ID UNIQUE_ID
    );

    CREATE ROP REF_ID R1
        FROM 1C Reflexive (Ref_ID) PHRASE 'one'
        TO 1C Reflexive (ID) PHRASE 'other';
    '''

    def setUp(self):
        l = xtuml.ModelLoader()
        l.input(self.__class__.__doc__)
        self.m = l.build_metamodel()
        
    def tearDown(self):
        del self.m

    def test_serialize(self):
        s1 = xtuml.serialize(self.m)
        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'))