Exemplo n.º 1
0
class TestCase01(unittest.TestCase):
    def setUp(self):
        self.p = PySourceAsText()

    def check01(self):
        """
        """
        FILE = 'python-in/testmodule67clippy.py'
        self.p.Parse(FILE)

        #print self.p

        # -------------------------------------------------------

        gotevent1 = 0
        gotevent2 = 0
        gotevent3 = 0
        gotevent4 = 0
        gotevent5 = 0
        gotevent6 = 0
        gotevent7 = 0

        for classname, classentry in self.p.classlist.items():
            if classname == 'Polygon':
                gotevent1 = 1
                assert classentry.classesinheritsfrom == []

                assert len(classentry.attrs) == 1, len(classentry.attrs)
                for attrobj in classentry.attrs:
                    attrname = attrobj.attrname

                    if attrname == 'verts':
                        gotevent2 = 1
                        compositescreatedforattr = self.p.GetCompositeClassesForAttr(
                            attrobj.attrname, classentry)
                        # 'flags is pointing at composite of Vert class'
                        assert len(compositescreatedforattr) == 1
                        assert compositescreatedforattr[0] == 'Vert'

                for adef in classentry.defs:
                    pass
                assert len(classentry.defs) == 2
                assert '__init__' in classentry.defs
                assert 'appendVert' in classentry.defs

            if classname == 'V':
                gotevent3 = False  # should not get this

            if classname == 'Vert':
                gotevent4 = 2
                assert classentry.classesinheritsfrom == []

        assert gotevent1
        assert gotevent2
        assert not gotevent3
        assert gotevent4
Exemplo n.º 2
0
class TestCase01(unittest.TestCase):
    def setUp(self):
        self.p = PySourceAsText()

    def checkNestedClasses01(self):
        """
        class ParseMeTest(undo.UndoItem):

            DEFAULT_ELEVATION = 30

            def __init__(self, map):
                self.map = map

            def PlaceTile(self, coord, terrainbmp):
                self.EnsureGraphicsSubDictAllocated(coord)
                newterraintype = self.bmpUtils.BmpToTerrainType(terrainbmp)


        """
        FILE = 'python-in/testmodule07.py'
        self.p.Parse(FILE)

        #print self.p

        # -------------------------------------------------------

        gotevent1 = 0
        gotevent2 = 0
        gotevent3 = 0

        for classname, classentry in self.p.classlist.items():
            if classname == 'ParseMeTest':
                gotevent1 = 1
                assert classentry.classesinheritsfrom == ['undo.UndoItem']

                assert len(classentry.attrs) == 2
                for attrobj in classentry.attrs:
                    attrname = attrobj.attrname
                    if attrname == 'map':
                        gotevent2 = 1
                    if attrname == 'DEFAULT_ELEVATION':
                        gotevent3 = 1
                        assert 'static' in attrobj.attrtype

                for adef in classentry.defs:
                    pass
                assert len(classentry.defs) == 2
                assert '__init__' in classentry.defs
                assert 'PlaceTile' in classentry.defs

        assert gotevent1
        assert gotevent2
        assert gotevent3
Exemplo n.º 3
0
class TestCase01(unittest.TestCase):
    def setUp(self):
        self.p = PySourceAsText()

    def checkParsesCorrectly01(self):
        """
        class ParseMeTest:
            ...
            ...
            def SetFlagsFromMemento(self, memento):
                if memento:
                    self.flagsdict = eval(memento)
                else:
                    self.flagsdict = {}
        """
        FILE = 'python-in/testmodule06.py'
        self.p.Parse(FILE)

        #print self.p
        #return

        # -------------------------------------------------------

        for classname, classentry in self.p.classlist.items():
            if classname == 'ParseMeTest':
                gotevent1 = 1
                assert classentry.classesinheritsfrom == ['undo.UndoItem']

                assert len(classentry.attrs) == 7
                attrnames = [a.attrname for a in classentry.attrs]
                assert 'scenario' in attrnames
                assert 'flagsdict' in attrnames
                assert 'pointsdict' in attrnames
                assert 'weatherdict' in attrnames
                assert 'flageditor' in attrnames
                assert 'weathereditor' in attrnames
                assert 'turnseditor' in attrnames

                for adef in classentry.defs:
                    pass
                assert len(classentry.defs) == 2
                assert '__init__' in classentry.defs
                assert 'SetFlagsFromMemento' in classentry.defs
Exemplo n.º 4
0
 def setUp(self):
     self.p = PySourceAsText()
Exemplo n.º 5
0
class TestCase01(unittest.TestCase):
    def setUp(self):
        self.p = PySourceAsText()

    def checkNestedClasses01(self):
        """
        class ParseMeTest:
            a = 100
            class A:
                pass
            def __init__(self):
                self.b = []
                class B:
                    ba = 99
                    class C:
                        def __init__(self):
                            self.cc = 88
            def Hi(self):
                pass

        class D:
            pass
        """
        FILE = 'python-in/testmodule05.py'
        self.p.Parse(FILE)

        gotevent1 = 0
        gotevent2 = 0
        gotevent3 = 0
        gotevent4 = 0
        gotevent5 = 0
        gotevent6 = 0
        gotevent7 = 0
        for classname, classentry in self.p.classlist.items():
            if classname == 'ParseMeTest':
                gotevent1 = 1
                assert classentry.classesinheritsfrom == []

                assert len(classentry.attrs) == 2
                for attrobj in classentry.attrs:
                    attrname = attrobj.attrname
                    if attrname == 'a':
                        gotevent2 = 1
                    if attrname == 'b':
                        gotevent3 = 1

                for adef in classentry.defs:
                    pass
                assert len(classentry.defs) == 2
                assert '__init__' in classentry.defs
                assert 'Hi' in classentry.defs

            if classname == 'ParseMeTest_A':
                gotevent4 = 1
                assert len(classentry.attrs) == 0
                assert len(classentry.defs) == 0

            if classname == 'ParseMeTest_B':
                gotevent5 = 1
                assert len(classentry.attrs) == 1
                assert len(classentry.defs) == 0

            if classname == 'ParseMeTest_B_C':
                gotevent6 = 1
                assert len(classentry.attrs) == 1
                assert len(classentry.defs) == 1

                for attrobj in classentry.attrs:
                    attrname = attrobj.attrname
                    assert attrname == 'cc'

            if classname == 'D':
                gotevent7 = 1
                assert len(classentry.attrs) == 0
                assert len(classentry.defs) == 0

        assert gotevent1
        assert gotevent2
        assert gotevent3
        assert gotevent4
        assert gotevent5
        assert gotevent6
        assert gotevent7
Exemplo n.º 6
0
class TestCase01(unittest.TestCase):
    def setUp(self):
        self.p = PySourceAsText()

    def check01(self):
        """
        """
        FILE = 'python-in/testmodule66.py'
        self.p.Parse(FILE)

        #print self.p

        # -------------------------------------------------------

        gotevent1 = 0
        gotevent2 = 0
        gotevent3 = 0
        gotevent4 = 0
        gotevent5 = 0
        gotevent6 = 0
        gotevent7 = 0

        for classname, classentry in self.p.classlist.items():
            if classname == 'Flag':
                gotevent1 = 1
                assert classentry.classesinheritsfrom == []

                assert len(classentry.attrs) == 3, len(classentry.attrs)
                for attrobj in classentry.attrs:
                    attrname = attrobj.attrname
                    if attrname == 'flagx':
                        gotevent5 = 1
                    if attrname == 'flagy':
                        gotevent6 = 1
                    if attrname == 'owner':
                        gotevent7 = 1

                for adef in classentry.defs:
                    pass
                assert len(classentry.defs) == 3
                assert '__init__' in classentry.defs
                assert 'readflag' in classentry.defs
                assert '__repr__' in classentry.defs


            if classname == 'Flags':
                gotevent2 = 2
                assert classentry.classesinheritsfrom == []

                assert len(classentry.attrs) == 2
                for attrobj in classentry.attrs:
                    attrname = attrobj.attrname
                    if attrname == 'flags':
                        gotevent3 = 1
                        compositescreatedforattr = self.p.GetCompositeClassesForAttr(attrobj.attrname, classentry)
                        # 'flags is pointing at composite of flag'
                        assert len(compositescreatedforattr) == 1
                        assert compositescreatedforattr[0] == 'Flag'

                    if attrname == 'numberOfFlags':
                        gotevent4 = 1
                        assert not 'static' in attrobj.attrtype

                for adef in classentry.defs:
                    pass
                assert len(classentry.defs) == 4
                assert '__init__' in classentry.defs
                assert 'readFlags' in classentry.defs
                assert 'AddFlag' in classentry.defs
                assert '__repr__' in classentry.defs

        assert gotevent1
        assert gotevent2
        assert gotevent3
        assert gotevent4
        assert gotevent5
        assert gotevent6
        assert gotevent7
Exemplo n.º 7
0
class TestCase01(unittest.TestCase):
    def setUp(self):
        self.p = PySourceAsText()

    def checkBasics01(self):
        """
        --------------------
        ParseMeTest  --------|> []
        --------------------
        a
        b  <@>----> ['Blah']
        d  static
        e  1..*         // interpreted as array of numbers
        e2  1..*        // interpreted as array of strings
        f  <@>----> ['Blah'] 1..*
        --------------------
        __init__
        IsInBattle
        DoA
        --------------------


        --------------------
        ParseMeTest2  --------|> ['ParseMeTest']
        --------------------
        _secretinfo
        --------------------
        DoB
        --------------------
        """
        FILE = 'python-in/testmodule01.py'
        self.p.Parse(FILE)

        #print self.p

        assert len(self.p.classlist) == 2

        gotevent1 = 0
        gotevent2 = 0
        gotevents = 0
        for classname, classentry in self.p.classlist.items():
            if classname == 'ParseMeTest':
                gotevent1 = 1
                assert classentry.classesinheritsfrom == []

                assert len(classentry.attrs) == 6
                for attrobj in classentry.attrs:
                    attrname = attrobj.attrname
                    compositescreatedforattr = self.p.GetCompositeClassesForAttr(attrobj.attrname, classentry)

                    if attrname == 'a':
                        gotevents += 1
                        assert not compositescreatedforattr

                    if attrname == 'b':
                        gotevents += 1
                        assert len(compositescreatedforattr) == 1
                        assert compositescreatedforattr[0] == 'Blah'
                        
                    if attrname == 'c':
                        assert 0, 'Should not get attribute c cos it is setting a sub.sub.sub object'

                    if attrname == 'd':
                        gotevents += 1
                        assert 'static' in attrobj.attrtype
                        assert not compositescreatedforattr

                    if attrname == 'e':
                        gotevents += 1
                        assert 'many' in attrobj.attrtype
                        assert not compositescreatedforattr

                    if attrname == 'e2':
                        gotevents += 1
                        assert 'many' in attrobj.attrtype
                        assert not compositescreatedforattr

                    if attrname == 'f':
                        gotevents += 1
                        assert 'many' in attrobj.attrtype
                        assert len(compositescreatedforattr) == 1
                        assert compositescreatedforattr[0] == 'Blah'
                        
                for adef in classentry.defs:
                    pass
                assert len(classentry.defs) == 3
                assert '__init__' in classentry.defs
                assert 'IsInBattle' in classentry.defs
                assert 'DoA' in classentry.defs
                
            if classname == 'ParseMeTest2':
                gotevent2 = 1
                assert classentry.classesinheritsfrom == ['ParseMeTest']

                assert len(classentry.attrs) == 1
                
                assert len(classentry.defs) == 1
                assert 'DoB' in classentry.defs
                
        assert gotevent1
        assert gotevent2 
        assert gotevents == 6

    def checkBasicsCommentGlitch01(self):
        FILE = 'python-in/testmodule02.py'
        self.p.Parse(FILE)

        #print self.p

        gotevent1 = 0
        gotevent2 = 0
        gotevent3 = 0
        gotevent4 = 0
        for classname, classentry in self.p.classlist.items():
            if classname == 'ParseMeTest':
                gotevent1 = 1
                assert classentry.classesinheritsfrom == []

                assert len(classentry.attrs) == 3
                for attrobj in classentry.attrs:
                    attrname = attrobj.attrname
                    if attrname == 'timejoinedbattle':
                        gotevent2 = 1
                    if attrname == 'fightingvalue':
                        gotevent3 = 1
                    if attrname == 'damagepointsincurred':
                        gotevent4 = 1
        assert gotevent1
        assert gotevent2 
        assert gotevent3 
        assert gotevent4 
Exemplo n.º 8
0
class TestCase01(unittest.TestCase):
    def setUp(self):
        self.p = PySourceAsText()

    def checkModuleVarsAndFunctions01(self):
        """
        class ParseMeTest:
            def __init__(self):
                self.a = None
                self.b = None
        x=20

        class ParseMeTest2:
            pass

        def y(): pass

        class ParseMeTest3:
            pass

        if __name__ == '__main__':
            y()

        class ParseMeTest4:
            pass

        """        
        CHECK_MODULE_LEVEL_PARSING = 1

        FILE = 'python-in/testmodule03.py'
        self.p.optionModuleAsClass = CHECK_MODULE_LEVEL_PARSING
        self.p.Parse(FILE)

        gotevent1 = 0
        gotevent2 = 0
        gotevent3 = 0
        gotevent4 = 0
        gotevent5 = 0
        gotevent6 = 0
        gotevent7 = 0
        gotevent8 = 0
        for classname, classentry in self.p.classlist.items():
            if classname == 'ParseMeTest':
                gotevent1 = 1
                assert classentry.classesinheritsfrom == []

                assert len(classentry.attrs) == 2
                for attrobj in classentry.attrs:
                    attrname = attrobj.attrname
                    if attrname == 'a':
                        gotevent2 = 1
                    if attrname == 'b':
                        gotevent3 = 1

                for adef in classentry.defs:
                    pass
                assert len(classentry.defs) == 1
                assert '__init__' in classentry.defs

            if classname == 'ParseMeTest2':
                gotevent4 = 1
                assert len(classentry.attrs) == 0
                assert len(classentry.defs) == 0

            if classname == 'ParseMeTest3':
                gotevent5 = 1
                assert len(classentry.attrs) == 0
                assert len(classentry.defs) == 0

            if classname == 'ParseMeTest4':
                gotevent6 = 1
                assert len(classentry.attrs) == 0
                assert len(classentry.defs) == 0


            # module level extra logic
            if CHECK_MODULE_LEVEL_PARSING:

                if classname == 'Module_'+os.path.splitext(os.path.basename(FILE))[0]:
                    gotevent7 = 1
                    assert classentry.classesinheritsfrom == []

                    for adef in classentry.defs:
                        pass
                    assert len(classentry.defs) == 1
                    assert 'y' in classentry.defs

                    assert len(classentry.attrs) == 1
                    for attrobj in classentry.attrs:
                        attrname = attrobj.attrname
                        if attrname == 'x':
                            gotevent8 = 1



        assert gotevent1
        assert gotevent2 
        assert gotevent3 
        assert gotevent4 
        assert gotevent5 
        assert gotevent6
        if CHECK_MODULE_LEVEL_PARSING:
            assert gotevent7 
            assert gotevent8 
        

    def checkModuleVarsAndFunctions02(self):
        """
        class ParseMeTest:
            a = 100
            b = [1,2,3]
            def __init__(self):
                self.c = []
                self.d = [1,2,3]
                self.e = (1,2,3)
                self.f = (1*10)
                
        x=[1,2]
        y=[]
        """        
        CHECK_MODULE_LEVEL_PARSING = 1

        FILE = 'python-in/testmodule04.py'
        self.p.optionModuleAsClass = CHECK_MODULE_LEVEL_PARSING
        self.p.Parse(FILE)

        gotevent1 = 0
        gotevent2 = 0
        gotevent3 = 0
        gotevent4 = 0
        gotevent5 = 0
        gotevent6 = 0
        gotevent7 = 0
        gotevent8 = 0
        gotevent9 = 0
        for classname, classentry in self.p.classlist.items():
            if classname == 'ParseMeTest':
                gotevent1 = 1
                assert classentry.classesinheritsfrom == []
                assert classentry.ismodulenotrealclass == 0

                for attrobj in classentry.attrs:
                    attrname = attrobj.attrname
                    #print attrname
                    if attrname == 'a':
                        gotevent2 = 1
                        assert 'static' in attrobj.attrtype
                    if attrname == 'b':
                        gotevent3 = 1
                        assert 'static' in attrobj.attrtype
                    if attrname == 'c':
                        gotevent4 = 1
                        assert 'static' not in attrobj.attrtype
                    if attrname == 'd':
                        gotevent3 = 1
                        assert 'static' not in attrobj.attrtype
                    if attrname == 'e':
                        gotevent5 = 1
                        assert 'static' not in attrobj.attrtype
                    if attrname == 'f':
                        gotevent6 = 1
                        assert 'static' not in attrobj.attrtype
                assert len(classentry.attrs) == 6, 'Only got ' + `len(classentry.attrs)` + ' attributes'

                for adef in classentry.defs:
                    pass
                assert len(classentry.defs) == 1
                assert '__init__' in classentry.defs

            # module level extra logic
            if CHECK_MODULE_LEVEL_PARSING:
                if classname == 'Module_'+os.path.splitext(os.path.basename(FILE))[0]:
                    gotevent7 = 1
                    assert classentry.classesinheritsfrom == []
                    assert classentry.ismodulenotrealclass

                    for adef in classentry.defs:
                        pass
                    assert len(classentry.defs) == 0

                    for attrobj in classentry.attrs:
                        attrname = attrobj.attrname
                        #print 'attr', attrname
                        if attrname == 'x':
                            gotevent8 = 1
                        if attrname == 'y':
                            gotevent9 = 1
                    assert len(classentry.attrs) == 2, 'Only got ' + `len(classentry.attrs)` + ' attributes'



        assert gotevent1
        assert gotevent2 
        assert gotevent3 
        assert gotevent4 
        assert gotevent5 
        assert gotevent6
        if CHECK_MODULE_LEVEL_PARSING:
            assert gotevent7 
            assert gotevent8 
            assert gotevent9