00001 import unittest
00002 import os
00003 import os.path
00004 import GPyUnit.util
00005 from GPyUnit.util import DispatchEx
00006
00007 _filedir = os.path.dirname(os.path.abspath(__file__))
00008 def _adjacent_file(file):
00009 return os.path.join(_filedir, file)
00010
00011 class TestMetaInterpreter(unittest.TestCase):
00012 def test_AttributeOrdering(self):
00013 mga = GPyUnit.util.parse_xme(self.connstr)
00014 try:
00015 mga.Save()
00016 selectedobj = DispatchEx("Mga.MgaFCOs")
00017 launcher = DispatchEx("Mga.MgaLauncher")
00018 launcher.RunComponent("Mga.Interpreter.MetaInterpreter", mga, None, selectedobj, 128)
00019 finally:
00020 mga.Close()
00021
00022 with open(os.path.join(self.outdir(), "MetaGME.xmp")) as xmp:
00023 lines = xmp.readlines()
00024 atomattributes = "IsAbstract InRootFolder GeneralPreferences DisplayedName IsTypeShown Icon IsNameEnabled PortIcon SubTypeIcon NamePosition InstanceIcon Decorator NameWrapNum IsHotspotEnabled IsResizable AutoRouterPref HelpURL IsGradientFillEnabled GradientFillColor GradientFillDirection IsShadowCastEnabled ShadowColor ShadowThickness ShadowDirection IsRoundRectangleEnabled RoundRectangleRadius"
00025 self.assertTrue(atomattributes in "".join(lines), filter(lambda x: '<atom name = "Atom"' in x, lines))
00026
00027 metaproj = DispatchEx("Mga.MgaMetaProject")
00028 metaproj.Open("MGA=" + os.path.join(self.outdir(), "MetaGME.mta"))
00029 try:
00030 atomattrs = [attr.Name for attr in metaproj.RootFolder.DefinedFCOByName("Atom", True).Attributes]
00031 self.assertEqual(atomattrs, list(atomattributes.split()))
00032 finally:
00033 metaproj.Close()
00034
00035
00036 def tearDown(self):
00037 for file in ("MetaGME.xmp", "MetaGME.mta", "MetaGME.xmp.log"):
00038 if os.path.isfile(os.path.join(self.outdir(), file)):
00039 os.unlink(os.path.join(self.outdir(), file))
00040 registrar = DispatchEx("Mga.MgaRegistrar")
00041 registrar.RegisterParadigmFromData("XML=" + os.path.abspath(os.path.join(os.environ['GME_ROOT'], "Paradigms\\MetaGME\\MetaGME.xmp")), "MetaGME", 1)
00042 setUp = tearDown
00043
00044 @property
00045 def connstr(self):
00046 return "MGA=" + _adjacent_file("MetaInterpretertest.mga")
00047
00048 def outdir(self):
00049 return os.path.abspath(_adjacent_file('.'))
00050
00051 GPyUnit.util.MUGenerator(globals(), TestMetaInterpreter)
00052 def _muoutdir(self):
00053 return os.path.abspath(os.getcwd())
00054 try:
00055 TestMetaInterpreterMU.outdir = _muoutdir
00056 TestMetaInterpreterMUSVN.outdir = _muoutdir
00057 TestMetaInterpreterMUSVNHashed.outdir = _muoutdir
00058 except NameError:
00059 pass
00060
00061 class TestCSharpDSMLGenerator(unittest.TestCase):
00062 def test_run(self):
00063 mga = GPyUnit.util.parse_xme(self.connstr)
00064 try:
00065 mga.Save()
00066 selectedobj = DispatchEx("Mga.MgaFCOs")
00067 launcher = DispatchEx("Mga.MgaLauncher")
00068 launcher.RunComponent("Mga.Interpreter.MetaInterpreter", mga, None, selectedobj, 128)
00069 launcher.RunComponent("Mga.Interpreter.CSharpDSMLGenerator", mga, None, selectedobj, 128)
00070 finally:
00071 mga.Close()
00072 self.assertTrue(os.path.isfile(os.path.join(self.outdir(), "ISIS.GME.Dsml.MetaGME.Classes.cs")))
00073 self.assertTrue(os.path.isfile(os.path.join(self.outdir(), "ISIS.GME.Dsml.MetaGME.dll")))
00074
00075
00076 def tearDown(self):
00077 for file in ("MetaGME.xmp", "MetaGME.mta", "MetaGME.xmp.log"):
00078 if os.path.isfile(os.path.join(self.outdir(), file)):
00079 os.unlink(os.path.join(self.outdir(), file))
00080 registrar = DispatchEx("Mga.MgaRegistrar")
00081 registrar.RegisterParadigmFromData("XML=" + os.path.abspath(os.path.join(os.environ['GME_ROOT'], "Paradigms\\MetaGME\\MetaGME.xmp")), "MetaGME", 1)
00082 for filename in ("AssemblySignature.snk", "ISIS.GME.Dsml.MetaGME.Classes.cs", "ISIS.GME.Dsml.MetaGME.dll", "ISIS.GME.Dsml.MetaGME.Interfaces.cs", "ISIS.GME.Dsml.MetaGME.xml", "ISIS.GME.Dsml.pdb"):
00083 path = os.path.join(self.outdir(), filename)
00084 if os.path.isfile(path):
00085 os.unlink(path)
00086 setUp = tearDown
00087
00088 @property
00089 def connstr(self):
00090 return "MGA=" + _adjacent_file("MetaInterpretertest.mga")
00091
00092 def outdir(self):
00093 return os.path.abspath(_adjacent_file('.'))
00094
00095 if GPyUnit.util._opts.Dispatch_x64:
00096 del TestCSharpDSMLGenerator
00097
00098
00099 if __name__ == "__main__":
00100 unittest.main()