mx_recursive.py :  » Parser » SimpleParse » SimpleParse-2.1.1a2 » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Parser » SimpleParse 
SimpleParse » SimpleParse 2.1.1a2 » tests » mx_recursive.py
"""Low-level matching tests for mx.TextTools"""
import unittest, pprint
from simpleparse.stt.TextTools import *

ab = (
  ( "ab", Word, "ab", 0 ),
)
cdef = (
  ( "cd", Word, "cd", 0 ),
  ( "ef", Word, "ef", 1,1 ),
)
tableList = [ ab, cdef ]
  

class MXRecursiveTests(unittest.TestCase):
  def doBasicTest(self, table, testvalue, expected, startPosition=0 ):
    result = tag( testvalue, table , startPosition)
    assert result == expected, '''\n\texpected:%s\n\tgot:%s\n'''%( expected, result )

  def testAB( self ):
    """Test AB testing command"""
    self.doBasicTest(
      ab,
      "abcdef",
      ( 1,[
        ("ab",0,2,None),
      ],2),
    )
  def testCDEF( self ):
    """Test CDEF testing command"""
    self.doBasicTest(
      cdef,
      "cdef",
      ( 1,[
        ("cd",0,2,None),
        ("ef",2,4,None),
      ],4),
    )
  def testABCDEF( self ):
    """Test abcdef all together"""
    self.doBasicTest(
      ab+cdef,
      "abcdef",
      ( 1,[
        ("ab",0,2,None),
        ("cd",2,4,None),
        ("ef",4,6,None),
      ],6),
    )
    
  def testTable1( self ):
    """Test Table command"""
    self.doBasicTest(
      (
        ("first", Table, ab),
        ("second", Table, cdef),
      ),
      "abcdef",
      ( 1,[
        ("first",0,2,[
          ("ab",0,2,None),
        ]),
        ("second",2,6,[
          ("cd",2,4,None),
          ("ef",4,6,None),
        ]),
      ],6),
    )
  def testTableInList1( self ):
    """Test TableInList command"""
    self.doBasicTest(
      (
        ("first", TableInList, (tableList,0)),
        ("second", TableInList,(tableList,1)),
      ),
      "abcdef",
      ( 1,[
        ("first",0,2,[
          ("ab",0,2,None),
        ]),
        ("second",2,6,[
          ("cd",2,4,None),
          ("ef",4,6,None),
        ]),
      ],6),
    )

  def testSubTable1( self ):
    """Test SubTable command"""
    self.doBasicTest(
      (
        ("first", SubTable, ab),
        ("second", SubTable, cdef),
      ),
      "abcdef",
      ( 1,[
        ("ab",0,2,None),
        ("first", 0,2, None),
        ("cd",2,4,None),
        ("ef",4,6,None),
        ("second", 2,6, None),
      ],6),
    )
  def testSubTable2( self ):
    """Test SubTable command with no reporting of st groups"""
    self.doBasicTest(
      (
        (None, SubTable, ab),
        (None, SubTable, cdef),
      ),
      "abcdef",
      ( 1,[
        ("ab",0,2,None),
        ("cd",2,4,None),
        ("ef",4,6,None),
      ],6),
    )
  def testSubTableInList1( self ):
    """Test SubTableInList command"""
    self.doBasicTest(
      (
        ("first", SubTableInList, (tableList,0)),
        ("second", SubTableInList, (tableList,1)),
      ),
      "abcdef",
      ( 1,[
        ("ab",0,2,None),
        ("first", 0,2, None),
        ("cd",2,4,None),
        ("ef",4,6,None),
        ("second", 2,6, None),
      ],6),
    )
  def testSubTableNotReturnRecursive( self ):
    """Test that SubTable calls don't return a recursive structure"""
    result = tag( "abcdef", (
      ("first", SubTableInList, (tableList,0)),
      ("second", SubTableInList, (tableList,1)),
    ), 0)
    assert result [1] is not result[1][1][3], """Subtable results list was the same list as the list enclosing it, looped data structure created"""
      
  def testSubTableInList2( self ):
    """Test SubTable command with no reporting of st groups"""
    self.doBasicTest(
      (
        (None, SubTableInList, (tableList,0)),
        (None, SubTableInList, (tableList,1)),
      ),
      "abcdef",
      ( 1,[
        ("ab",0,2,None),
        ("cd",2,4,None),
        ("ef",4,6,None),
      ],6),
    )

    
def getSuite():
  return unittest.makeSuite(MXRecursiveTests,'test')

if __name__ == "__main__":
  unittest.main(defaultTest="getSuite")
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.