00001
00002 from __future__ import with_statement
00003
00004 import sys
00005 import os.path
00006 import unittest
00007 from GPyUnit.util import DispatchEx
00008
00009 class TestRefportConnectionInvariantUnderMoves(unittest.TestCase):
00010 def __init__(self, input_file, fco_to_move, destination_model, name=None, use_disp=None, **kwds):
00011 super(TestRefportConnectionInvariantUnderMoves, self).__init__('test', **kwds)
00012 self.input_file = input_file
00013 self.fco_to_move = fco_to_move
00014 self.destination_model = destination_model
00015 name = name if name else os.path.splitext(self.input_file)[0]
00016 self._testMethodDoc = name
00017 self.output_file = name + "-output.mga"
00018 self.correct_file = name + "-correct.mga"
00019 if use_disp:
00020 self._move_fcos = self._move_fcos_disp
00021
00022
00023 def test(self):
00024 """
00025 Regression test: given self.input_file, move self.fco_to_move to self.destination_model. Then check self.output_file against self.correct_file
00026 """
00027 def _adjacent_file(file):
00028 import os.path
00029 return os.path.join(os.path.dirname(os.path.abspath(__file__)), file)
00030 from GPyUnit import util
00031 util.register_xmp(_adjacent_file('GME297ModelRefportTest.xmp'))
00032 with util.disable_early_binding():
00033 self.project = DispatchEx("Mga.MgaProject")
00034 self.project.Open("MGA=" + _adjacent_file(self.input_file))
00035 self.territory = self.project.BeginTransactionInNewTerr()
00036
00037 fco_to_move = self.project.ObjectByPath(self.fco_to_move)
00038 OBJTYPE_FOLDER = 6
00039 if fco_to_move.ObjType == OBJTYPE_FOLDER:
00040 tomove = DispatchEx("Mga.MgaFolders")
00041 else:
00042 tomove = DispatchEx("Mga.MgaFCOs")
00043 tomove.Append(fco_to_move)
00044
00045 destination = self.project.ObjectByPath(self.destination_model)
00046 if destination.ObjType == OBJTYPE_FOLDER:
00047 destination.MoveFolderDisp(fco_to_move)
00048 else:
00049 self._move_fcos(destination, fco_to_move, tomove)
00050
00051
00052 self.project.CommitTransaction()
00053 self.project.Save("MGA=" + _adjacent_file(self.output_file))
00054 self.territory.Destroy()
00055 self.project.Close()
00056
00057 import GPyUnit.util.mgadiff as mgadiff
00058 if not mgadiff.compare(_adjacent_file(self.correct_file), _adjacent_file(self.output_file)):
00059 self.fail("Reference file '%s' does not match output '%s'" % (self.correct_file, self.output_file))
00060
00061
00062 def _move_fcos(self, destination, fco_to_move, col_to_move):
00063 import platform
00064 if platform.system() == 'Java':
00065 import org.isis.jaut.Variant
00066 destination.MoveFCODisp(fco_to_move, org.isis.jaut.Variant.create(org.isis.jaut.Variant.VT_UNKNOWN))
00067 else:
00068 destination.MoveFCOs(col_to_move, None, None)
00069
00070 def _move_fcos_disp(self, destination, fco_to_move, col_to_move):
00071 import platform
00072 if platform.system() == 'Java':
00073 import org.isis.jaut.Variant
00074 destination.MoveFCODisp(fco_to_move, org.isis.jaut.Variant.create(org.isis.jaut.Variant.VT_UNKNOWN))
00075 else:
00076 destination.MoveFCODisp(fco_to_move, None)
00077
00078 def suite():
00079 suite = unittest.TestSuite()
00080 suite.addTest(TestRefportConnectionInvariantUnderMoves(input_file="test1.mga", fco_to_move="/Test1/Folder1/A/B", destination_model="/Test1/Folder2/C"))
00081 suite.addTest(TestRefportConnectionInvariantUnderMoves(input_file="test2.mga", fco_to_move="/Test2/Subtypes/A/BSubtypeRef", destination_model="/Test2/Destination/Destination"))
00082 suite.addTest(TestRefportConnectionInvariantUnderMoves(input_file="test1.mga", fco_to_move="/Test1/Folder1/A/RefB", destination_model="/Test1/Folder2/C", name="test3"))
00083 suite.addTest(TestRefportConnectionInvariantUnderMoves(input_file="test4.mga", fco_to_move="/Test4/Folder1/A/RefRefB", destination_model="/Test4/Folder2/C"))
00084 suite.addTest(TestRefportConnectionInvariantUnderMoves(input_file="test5.mga", fco_to_move="/Test4/Folder2", destination_model="/Test4/Folder3"))
00085 suite.addTest(TestRefportConnectionInvariantUnderMoves(input_file="test4.mga", fco_to_move="/Test4/Folder1/A/RefRefB", destination_model="/Test4/Folder2/C", name="test6", use_disp=True))
00086 return suite
00087
00088 if __name__ == "__main__":
00089 runner = unittest.TextTestRunner()
00090 runner.run(suite())