def test_computeDataMembers_error_2(self): class E2: def __init__(*args): self.x = 0 with self.assertRaises(Exceptions.PythonToForaConversionError): PyAstUtil.computeDataMembers(E2)
def test_computeDataMembers_error_3(self): class E3: def __init__(self): self.x = 0 def f(x): return x with self.assertRaises(Exceptions.PythonToForaConversionError): PyAstUtil.computeDataMembers(E3)
def test_computeDataMembers_error_4(self): class E4: def __init__(self): self.x = 0 class c(object): def __init__(self): self.z = 0 with self.assertRaises(Exceptions.PythonToForaConversionError): PyAstUtil.computeDataMembers(E4)
def test_computeDataMembers_4(self): class C4: def __init__(self, arg): (self.x, self.y), self.z = arg dataMembers = PyAstUtil.computeDataMembers(C4) self.assertEqual(dataMembers, set(['x', 'y', 'z']))
def test_computeDataMembers_3(self): class C3: def __init__(self): self.x = self.y = 0 dataMembers = PyAstUtil.computeDataMembers(C3) self.assertEqual(dataMembers, set(['x', 'y']))
def test_computeDataMembers_1(self): class C: def __init__(self, x): self.x = x self.y = x**2.0 dataMembers = PyAstUtil.computeDataMembers(C) self.assertEqual(dataMembers, set(['x', 'y']))
def test_computeDataMembers_2(self): class C2: def __init__(self, x): if x > 0: self.x = x dataMembers = PyAstUtil.computeDataMembers(C2) # in our translation, we're _always_ producing an x member self.assertEqual(dataMembers, set(['x']))
def test_computeDataMembers_4(self): class C4: def __init__(self, arg): (self.x, self.y), self.z = arg dataMembers = PyAstUtil.computeDataMembers(C4) self.assertEqual( dataMembers, set(['x', 'y', 'z']) )
def test_computeDataMembers_3(self): class C3: def __init__(self): self.x = self.y = 0 dataMembers = PyAstUtil.computeDataMembers(C3) self.assertEqual( dataMembers, set(['x', 'y']) )
def test_computeDataMembers_1(self): class C: def __init__(self, x): self.x = x self.y = x ** 2.0 dataMembers = PyAstUtil.computeDataMembers(C) self.assertEqual( dataMembers, set(['x', 'y']) )
def test_computeDataMembers_2(self): class C2: def __init__(self, x): if x > 0: self.x = x dataMembers = PyAstUtil.computeDataMembers(C2) # in our translation, we're _always_ producing an x member self.assertEqual( dataMembers, set(['x']) )
def _classInstanceDescriptionFromClassInstance(self, pyObject): try: classObject = pyObject.__class__ dataMemberNames = PyAstUtil.computeDataMembers(classObject) classMemberNameToMemberValue = {} for dataMemberName in dataMemberNames: memberValue = getattr(pyObject, dataMemberName) classMemberNameToMemberValue[dataMemberName] = memberValue return PyObjectNodes.ClassInstanceDescription( pyObject, classObject, classMemberNameToMemberValue) except: logging.error('Failed on %s (of type %s)', pyObject, type(pyObject)) raise
def _classInstanceDescriptionFromClassInstance(self, pyObject): try: classObject = pyObject.__class__ dataMemberNames = PyAstUtil.computeDataMembers(classObject) classMemberNameToMemberValue = {} for dataMemberName in dataMemberNames: memberValue = getattr(pyObject, dataMemberName) classMemberNameToMemberValue[dataMemberName] = memberValue return PyObjectNodes.ClassInstanceDescription( pyObject, classObject, classMemberNameToMemberValue ) except: logging.error('Failed on %s (of type %s)', pyObject, type(pyObject)) raise