示例#1
0
 def test_top_pos(self):
     """TestTreePlotTransform.incPhysicalChildPos(): top, +"""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='top',
                                                 sweepDir='+')
     childPhysicalPt = self._pt
     # Starting point
     self.assertEqual(myObj.pt(self._pt), childPhysicalPt)
     # First increment
     childPhysicalPt = myObj.incPhysicalChildPos(childPhysicalPt,
                                                 self._childIncS[0])
     self.assertEqual(
         childPhysicalPt,
         Coord.Pt(
             Coord.Dim(400 - 36, None),
             Coord.Dim(250, None),
         ))
     # Second increment
     childPhysicalPt = myObj.incPhysicalChildPos(childPhysicalPt,
                                                 self._childIncS[1])
     self.assertEqual(
         childPhysicalPt,
         Coord.Pt(
             Coord.Dim(400 - 36 - 101, None),
             Coord.Dim(250, None),
         ))
     # Third increment
     childPhysicalPt = myObj.incPhysicalChildPos(childPhysicalPt,
                                                 self._childIncS[2])
     self.assertEqual(
         childPhysicalPt,
         Coord.Pt(
             Coord.Dim(400 - 36 - 101 - 74, None),
             Coord.Dim(250, None),
         ))
示例#2
0
 def testPt_top(self):
     """TestTreePlotTransformPt.pt(): top."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='top')
     self.assertEqual(
         myObj.pt(self._pt),
         Coord.Pt(
             Coord.Dim(17, None),
             Coord.Dim(29, None),
         ),
     )
示例#3
0
 def testIncWD_right(self):
     """TestTreePlotTransformBoxDatumP.boxDatumP(): right."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='right')
     self.assertEqual(
         myObj.boxDatumP(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(451, None),
             Coord.Dim(17, None),
         ),
     )
示例#4
0
 def testIncWD_bottom(self):
     """TestTreePlotTransformBoxDatumP.boxDatumP(): bottom."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='bottom')
     self.assertEqual(
         myObj.boxDatumP(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(203, None),
             Coord.Dim(451, None),
         ),
     )
示例#5
0
 def testIncWD_top(self):
     """TestTreePlotTransformBoxDatumP.boxDatumP(): top."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='top')
     self.assertEqual(
         myObj.boxDatumP(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(17, None),
             Coord.Dim(29, None),
         ),
     )
示例#6
0
 def testIncWD_right(self):
     """TestTreePlotTransformBoxP.boxP(): right."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='right')
     self.assertEqual(
         myObj.boxP(self._box),
         Coord.Box(
             Coord.Dim(20, None),
             Coord.Dim(80, None),
         ),
     )
示例#7
0
 def testPt_right(self):
     """TestTreePlotTransformPt.pt(): right."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='right')
     self.assertEqual(
         myObj.pt(self._pt),
         Coord.Pt(
             Coord.Dim(500 - 29, None),
             Coord.Dim(17, None),
         ),
     )
示例#8
0
 def testPt_left(self):
     """TestTreePlotTransformPt.pt(): left."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='left')
     self.assertEqual(
         myObj.pt(self._pt),
         Coord.Pt(
             Coord.Dim(29, None),
             Coord.Dim(300 - 17, None),
         ),
     )
示例#9
0
 def testPt_bottom(self):
     """TestTreePlotTransformPt.pt(): bottom."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='bottom')
     self.assertEqual(
         myObj.pt(self._pt),
         Coord.Pt(
             Coord.Dim(300 - 17, None),
             Coord.Dim(500 - 29, None),
         ),
     )
示例#10
0
 def testCanvasP_left(self):
     """TestTreePlotTransformCanvas.canvasP(): left."""
     myO = TreePlotTransform.TreePlotTransform(self._boxDefault,
                                               rootPos='left')
     expValue = Coord.Box(
         Coord.Dim(500, None),
         Coord.Dim(300, None),
     )
     self.assertEqual(
         myO.canvasP(),
         expValue,
     )
示例#11
0
 def test_bdcL_bdcP_left(self):
     """TreePlotTransform.bdcL()/.bdcP(): left."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='left')
     self.assertEqual(
         myObj.bdcL(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(17, None),
             Coord.Dim(39, None),
         ),
     )
     self.assertEqual(
         myObj.bdcP(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(39, None),
             Coord.Dim(283, None),
         ),
     )
示例#12
0
 def testIncWD_bottom(self):
     """TreePlotTransform.tdcL()/.tdcP(): bottom."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='bottom')
     self.assertEqual(
         myObj.tdcL(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(57, None),
             Coord.Dim(49, None),
         ),
     )
     self.assertEqual(
         myObj.tdcP(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(243, None),
             Coord.Dim(451, None),
         ),
     )
示例#13
0
 def testIncWD_right(self):
     """TreePlotTransform.tdcL()/.tdcP(): right."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='right')
     self.assertEqual(
         myObj.tdcL(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(17, None),
             Coord.Dim(39, None),
         ),
     )
     self.assertEqual(
         myObj.tdcP(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(461, None),
             Coord.Dim(17, None),
         ),
     )
示例#14
0
 def testIncWD_top(self):
     """TreePlotTransform.tdcL()/.tdcP(): top."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='top')
     self.assertEqual(
         myObj.tdcL(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(57, None),
             Coord.Dim(29, None),
         ),
     )
     self.assertEqual(
         myObj.tdcP(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(57, None),
             Coord.Dim(29, None),
         ),
     )
示例#15
0
 def testIncWD_left(self):
     """TreePlotTransform.tdcL()/.tdcP(): left."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='left')
     self.assertEqual(
         myObj.tdcL(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(97, None),
             Coord.Dim(39, None),
         ),
     )
     self.assertEqual(
         myObj.tdcP(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(39, None),
             Coord.Dim(203, None),
         ),
     )
示例#16
0
def processIncGraphToSvg(theLex, theFilePath, theClass, tptPos, tptSweep):
    """Convert a Include graph from a PpLexer to SVG in theFilePath."""
    myVis = FileIncludeGraph.FigVisitorTree(theClass)
    theLex.fileIncludeGraphRoot.acceptVisitor(myVis)
    # Tree is now a graph of: theClass
    myIgs = myVis.tree()
    # Pad the canvass
    myWidth = CANVAS_PADDING.prev \
                + myIgs.plotCanvas.width \
                + CANVAS_PADDING.next
    myDepth = CANVAS_PADDING.parent \
                + myIgs.plotCanvas.depth \
                + CANVAS_PADDING.child
    # Round up
    myWidth = Coord.Dim(int(myWidth.value+0.5), myWidth.units)
    myDepth = Coord.Dim(int(myDepth.value+0.5), myDepth.units)
    myCanvas = Coord.Box(myWidth, myDepth)
    #Create a plot configuration
    myTpt = TreePlotTransform.TreePlotTransform(myCanvas, tptPos, tptSweep)
    # Write to file
    myIgs.plotToFilePath(theFilePath, myTpt)
示例#17
0
 def test_right_neg(self):
     """TestTreePlotTransform.incPhysicalChildPos(): right, -"""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='right',
                                                 sweepDir='-')
     childPhysicalPt = Coord.Pt(
         Coord.Dim(550, None),
         Coord.Dim(400, None),
     )
     #print myObj.pt(self._pt)
     # Starting point
     self.assertEqual(myObj.pt(self._pt), childPhysicalPt)
     #return
     # First increment
     childPhysicalPt = myObj.incPhysicalChildPos(childPhysicalPt,
                                                 self._childIncS[0])
     self.assertEqual(
         childPhysicalPt,
         Coord.Pt(
             Coord.Dim(550, None),
             Coord.Dim(400 + 36, None),
         ))
     # Second increment
     childPhysicalPt = myObj.incPhysicalChildPos(childPhysicalPt,
                                                 self._childIncS[1])
     self.assertEqual(
         childPhysicalPt,
         Coord.Pt(
             Coord.Dim(550, None),
             Coord.Dim(400 + 36 + 101, None),
         ))
     # Third increment
     childPhysicalPt = myObj.incPhysicalChildPos(childPhysicalPt,
                                                 self._childIncS[2])
     self.assertEqual(
         childPhysicalPt,
         Coord.Pt(
             Coord.Dim(550, None),
             Coord.Dim(400 + 36 + 101 + 74, None),
         ))
示例#18
0
 def testCtorMt(self):
     """TreePlotTransform() constructor defaults."""
     myO = TreePlotTransform.TreePlotTransform(Coord.zeroBaseUnitsBox())
     self.assertEqual(myO.rootPos, 'top')
     self.assertEqual(myO.sweepDir, '-')
示例#19
0
    def test_10(self):
        """TestIncGraphSVGVisitor: Two pre-includes and a graph."""
        return
        # First create an include graph
        myFigr = FileIncludeGraph.FileIncludeGraphRoot()
        myTcs = PpTokenCount.PpTokenCountStack()
        myFs = []
        # push PreInclude_00
        myFigr.addGraph(
            FileIncludeGraph.FileIncludeGraph('PreInclude_00', True,
                                              'a >= b+2',
                                              'Forced PreInclude_00'))
        myTcs.push()
        myFs.append('PreInclude_00')
        myTcs.counter().inc(PpToken.PpToken('PreInclude_00', 'identifier'),
                            True, 8)
        myTcs.counter().inc(PpToken.PpToken('PreInclude_00', 'identifier'),
                            False, 148)
        # pop PreInclude_00
        myFigr.graph.retLatestNode(myFs).setTokenCounter(myTcs.pop())
        myFs.pop()
        self.assertEqual(len(myFs), 0)
        # push PreInclude_01
        myFigr.addGraph(
            FileIncludeGraph.FileIncludeGraph('PreInclude_01', True, 'x > 1',
                                              'Forced PreInclude_00'))
        myTcs.push()
        myFs.append('PreInclude_01')
        myTcs.counter().inc(PpToken.PpToken('PreInclude_01', 'identifier'),
                            True, 7)
        myTcs.counter().inc(PpToken.PpToken('PreInclude_01', 'identifier'),
                            False, 76)
        # pop PreInclude_01
        myFigr.graph.retLatestNode(myFs).setTokenCounter(myTcs.pop())
        myFs.pop()
        self.assertEqual(len(myFs), 0)
        # push ITU.h
        myFigr.addGraph(
            FileIncludeGraph.FileIncludeGraph('ITU.h', True, '', 'CP=.'))
        myTcs.push()
        myFs.append('ITU.h')
        self.assertEqual(3, myFigr.numTrees())
        # push ITU.h/a.h
        myFigr.graph.addBranch([
            'ITU.h',
        ], 15, 'a.h', True, '', 'CP=.')
        myTcs.push()
        myFs.append('a.h')
        myTcs.counter().inc(PpToken.PpToken('a.h', 'identifier'), True, 1)
        myTcs.counter().inc(PpToken.PpToken('a.h', 'identifier'), False, 1)
        # push ITU.h/a.h/aa.h
        myFigr.graph.addBranch(['ITU.h', 'a.h'], 17, 'aa.h', True, '', 'CP=.')
        myTcs.push()
        myFs.append('aa.h')
        myTcs.counter().inc(PpToken.PpToken('aa.h', 'identifier'), True, 2)
        myTcs.counter().inc(PpToken.PpToken('aa.h', 'identifier'), False, 2)
        # pop ITU.h/a.h/aa.h
        myFigr.graph.retLatestNode(myFs).setTokenCounter(myTcs.pop())
        myFs.pop()
        self.assertEqual(len(myFs), 2)
        # push ITU.h/a.h/ab.h
        myFigr.graph.addBranch(['ITU.h', 'a.h'], 19, 'ab.h', True, '', 'CP=.')
        myTcs.push()
        myFs.append('ab.h')
        myTcs.counter().inc(PpToken.PpToken('ab.h', 'identifier'), True, 4)
        myTcs.counter().inc(PpToken.PpToken('ab.h', 'identifier'), False, 4)
        # pop ITU.h/a.h/ab.h
        myFigr.graph.retLatestNode(myFs).setTokenCounter(myTcs.pop())
        myFs.pop()
        self.assertEqual(len(myFs), 2)
        # pop ITU.h/a.h
        myFigr.graph.retLatestNode(myFs).setTokenCounter(myTcs.pop())
        myFs.pop()
        self.assertEqual(len(myFs), 1)
        # push ITU.h/b.h
        myFigr.graph.addBranch([
            'ITU.h',
        ], 115, 'b.h', True, '', 'CP=.')
        myTcs.push()
        myFs.append('b.h')
        myTcs.counter().inc(PpToken.PpToken('b.h', 'identifier'), True, 8)
        myTcs.counter().inc(PpToken.PpToken('b.h', 'identifier'), False, 8)
        # push ITU.h/b.h/ba.h
        myFigr.graph.addBranch(['ITU.h', 'b.h'], 117, 'ba.h', True, '', 'CP=.')
        myTcs.push()
        myFs.append('ba.h')
        myTcs.counter().inc(PpToken.PpToken('ba.h', 'identifier'), True, 16)
        myTcs.counter().inc(PpToken.PpToken('ba.h', 'identifier'), False, 16)
        # pop ITU.h/b.h/ba.h
        myFigr.graph.retLatestNode(myFs).setTokenCounter(myTcs.pop())
        myFs.pop()
        self.assertEqual(len(myFs), 2)
        # push ITU.h/b.h/bb.h
        myFigr.graph.addBranch(['ITU.h', 'b.h'], 119, 'bb.h', True, '', 'CP=.')
        myTcs.push()
        myFs.append('bb.h')
        myTcs.counter().inc(PpToken.PpToken('bb.h', 'identifier'), True, 32)
        myTcs.counter().inc(PpToken.PpToken('bb.h', 'identifier'), False, 32)
        # pop ITU.h/b.h/bb.h
        myFigr.graph.retLatestNode(myFs).setTokenCounter(myTcs.pop())
        myFs.pop()
        self.assertEqual(len(myFs), 2)
        # pop ITU.h/b.h
        myFigr.graph.retLatestNode(myFs).setTokenCounter(myTcs.pop())
        myFs.pop()
        self.assertEqual(len(myFs), 1)
        # ITU.h
        myTcs.counter().inc(PpToken.PpToken('ITU.h', 'identifier'), True, 70)
        myTcs.counter().inc(PpToken.PpToken('ITU.h', 'identifier'), False, 70)
        myFigr.graph.retLatestNode(myFs).setTokenCounter(myTcs.pop())
        myFs.pop()
        self.assertEqual(len(myFs), 0)
        myTcs.close()
        expGraph = """PreInclude_00 [156, 8]:  True "a >= b+2" "Forced PreInclude_00"
PreInclude_01 [83, 7]:  True "x > 1" "Forced PreInclude_00"
ITU.h [140, 70]:  True "" "CP=."
000015: #include a.h
        a.h [2, 1]:  True "" "CP=."
        000017: #include aa.h
                aa.h [4, 2]:  True "" "CP=."
        000019: #include ab.h
                ab.h [8, 4]:  True "" "CP=."
000115: #include b.h
        b.h [16, 8]:  True "" "CP=."
        000117: #include ba.h
                ba.h [32, 16]:  True "" "CP=."
        000119: #include bb.h
                bb.h [64, 32]:  True "" "CP=.\""""
        print()
        print(expGraph)
        print()
        print(str(myFigr))
        print()
        myFigr.dumpGraph()
        self.assertEqual(expGraph, str(myFigr))
        # Now visit the graph
        myVis = FileIncludeGraph.FigVisitorTree(IncGraphSVG.SVGTreeNode)
        myFigr.acceptVisitor(myVis)
        # Tree is now a graph of IncGraphSVG.SVGTreeNode
        myIgs = myVis.tree()
        print()
        print('myIgs')
        #print myIgs
        myIgs.dumpToStream()
        print()
        # Create a plot configuration
        myTpt = TreePlotTransform.TreePlotTransform(myIgs.plotCanvas, 'top',
                                                    '-')
        mySvg = io.StringIO()
        myIgs.plotToFileObj(mySvg, myTpt)
        print()
        print(mySvg.getvalue())
示例#20
0
    def test_00(self):
        _pathsUsr = [
            os.path.join('usr'),
            os.path.join('usr', 'inc'),
        ]
        _pathsSys = [
            os.path.join('sys'),
            os.path.join('sys', 'inc'),
        ]
        _initialTuContents = u"""Include usr/spam:
#include "spam.h"
Include usr/inc/eggs:
#include "inc/eggs.h"
Include sys/chips:
#include <chips.h>
Include sys/inc/beans:
#include <inc/beans.h>
"""
        _incFileMap = {
            os.path.join('usr', 'spam.h'):
            u"""Content of: user, spam.h
""",
            os.path.join('usr', 'inc', 'eggs.h'):
            u"""Content of: user, include, eggs.h
Which is much bigger.""",
            os.path.join('sys', 'chips.h'):
            u"""chips.h
""",
            os.path.join('sys', 'inc', 'beans.h'):
            u"""Content of: system, include, beans.h
Which is very big, 1, def, 345,
and loads of other things.
""",
        }
        _incSim = CppIncludeStringIO(
            _pathsUsr,
            _pathsSys,
            _initialTuContents,
            _incFileMap,
        )
        _incSim.validateCpStack()
        self.assertEqual([], _incSim.cpStack)
        self.assertEqual(0, _incSim.cpStackSize)
        myLexer = PpLexer.PpLexer('src/spam.c', _incSim)
        result = ''.join([t.t for t in myLexer.ppTokens()])
        #        print('Result:')
        #        print(result)
        expectedResult = """Include usr/spam:
Content of: user, spam.h

Include usr/inc/eggs:
Content of: user, include, eggs.h
Which is much bigger.
Include sys/chips:
chips.h

Include sys/inc/beans:
Content of: system, include, beans.h
Which is very big, 1, def, 345,
and loads of other things.

"""
        self.assertEqual(result, expectedResult)
        myLexer.finalise()
        myFigr = myLexer.fileIncludeGraphRoot
        #         print('FileIncludeGraph:')
        #         print(myFigr)
        # WARN: excape \b (two places on last two lines
        expGraph = """src/spam.c [32, 24]:  True "" ""
000002: #include usr/spam.h
  usr/spam.h [12, 8]:  True "" "['"spam.h"', 'CP=None', 'usr=usr']"
000004: #include usr/inc/eggs.h
  usr/inc/eggs.h [23, 15]:  True "" "['"inc/eggs.h"', 'CP=None', 'usr=usr']"
000006: #include sys/chips.h
  sys/chips.h [4, 3]:  True "" "['<chips.h>', 'sys=sys']"
000008: #include sys/inc/beans.h
  sys/inc/beans.h [44, 27]:  True "" "['<inc/beans.h>', 'sys=sys']\""""
        #         print('Exp FileIncludeGraph:')
        #         print(expGraph)
        #         self.maxDiff = None
        #for i, c in enumerate(str(myFigr)):
        #    if c != expGraph[i]:
        #        print '[%d] %s != %s' % (i, c, expGraph[i])
        self.assertEqual(expGraph, str(myFigr))
        #         print()
        #         myFigr.dumpGraph()
        self.assertEqual(expGraph, str(myFigr))
        # Now visit the graph
        myVis = FileIncludeGraph.FigVisitorTree(IncGraphSVG.SVGTreeNodeMain)
        myFigr.acceptVisitor(myVis)
        # Tree is now a graph of IncGraphSVG.SVGTreeNode
        myIgs = myVis.tree()
        #         print()
        #         print('myIgs')
        #print myIgs
        #         myIgs.dumpToStream()
        #         print()
        # Create a plot configuration
        myTpt = TreePlotTransform.TreePlotTransform(myIgs.plotCanvas, 'left',
                                                    '+')
        mySvg = io.StringIO()
        myIgs.plotToFileObj(mySvg, myTpt)
        #         print()
        #         print(mySvg.getvalue())
        for aPos in myTpt.genRootPos():
            for aDir in myTpt.genSweepDir():
                aTpt = TreePlotTransform.TreePlotTransform(
                    myIgs.plotCanvas, aPos, aDir)
                mySvg = io.StringIO()
                myIgs.plotToFileObj(mySvg, aTpt)