def testConstructor(self): source = """ class First field primary: int constructor autoinit primary class Second extends First field secondary: double constructor param primary: int autoinit secondary super(primary) """ expected = """ class First: __slots__ = ('primary') def __init__(self, primary): self.primary = primary class Second(First): __slots__ = ('secondary') def __init__(self, primary, secondary): super().__init__(primary) self.secondary = secondary """ module = PyCore.createModuleFromWpp(source, 'superInCon.wpp') out = OutContextMemoryStream() module.exportContext(out, style) self.assertEqual(str(out), PyCore.strPack(expected))
def testStatic(self): source = """ class public static Hello field static public first: int = 123 field static private second: bool """ expected = """ class Hello: first = 123 second = False """ module = PyCore.createModuleFromWpp(source, 'ststic.wpp') out = OutContextMemoryStream() module.exportContext(out, style) self.assertEqual(str(out), PyCore.strPack(expected))
def testSimple(self): source = """ class public static Hello field public first: int = 123 field private second: bool """ expected = """ class Hello: __slots__ = ('first', 'second') def __init__(self): self.first = 123 self.second = False """ module = PyCore.createModuleFromWpp(source, 'simple.wpp') out = OutContextMemoryStream() module.exportContext(out, style) self.assertEqual(str(out), PyCore.strPack(expected))
def testSimple(self): source = """ class public static Hello method getCount: unsigned int return 1234 method setCount param count: unsigned int param bUpdate: bool = false """ expected = """ class Hello: def getCount(self): return 1234 def setCount(self, count, bUpdate = False): pass """ module = PyCore.createModuleFromWpp(source, 'simple.wpp') out = OutContextMemoryStream() module.exportContext(out, style) self.assertEqual(str(out), PyCore.strPack(expected))
def testExtends(self): source = """ class Top class Middle extends Top class Bottom extends Middle """ expect = """ class Top: pass class Middle(Top): pass class Bottom(Middle): pass """ module = PyCore.createModuleFromWpp(source, 'extends.wpp') out = OutContextMemoryStream() module.exportContext(out, style) self.assertEqual(str(out), PyCore.strPack(expect))
def testOverride(self): source = """ class First method virtual getValue: int param id: int return id * 2 class Second extends First method override getValue: int param id: int return super(id) + 1 """ expected = """ class First: def getValue(self, id): return id * 2 class Second(First): def getValue(self, id): return super().getValue(id) + 1 """ module = PyCore.createModuleFromWpp(source, 'superInOver.wpp') out = OutContextMemoryStream() module.exportContext(out, style) self.assertEqual(str(out), PyCore.strPack(expected))