Exemple #1
0
    def test_computeDataMembers_error_2(self):
        class E2:
            def __init__(*args):
                self.x = 0

        with self.assertRaises(Exceptions.PythonToForaConversionError):
            PyAstUtil.computeDataMembers(E2)
Exemple #2
0
    def test_computeDataMembers_error_2(self):
        class E2:
            def __init__(*args):
                self.x = 0

        with self.assertRaises(Exceptions.PythonToForaConversionError):
            PyAstUtil.computeDataMembers(E2)
Exemple #3
0
    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)
Exemple #4
0
    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)
Exemple #5
0
    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)
Exemple #6
0
    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)
Exemple #7
0
    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']))
Exemple #8
0
    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']))
Exemple #9
0
    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']))
Exemple #10
0
    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']))
Exemple #11
0
    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'])
            )
Exemple #12
0
    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'])
            )
Exemple #13
0
    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'])
            )
Exemple #14
0
    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'])
            )
Exemple #15
0
    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
Exemple #16
0
    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