test_pyformatsupport.py :  » Database » PyTable » pytable-0.8.20a » pytable » 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 » Database » PyTable 
PyTable » pytable 0.8.20a » pytable » tests » test_pyformatsupport.py
import unittest, traceback
from pytable import dbspecifier,dbschema,sqlquery,specifierfromoptions,pyformatsupport

testSpec = specifierfromoptions.specifierFromOptions()

primarySpecifiers = specifiers = [
  testSpec,
]

class PyFormatTest( unittest.TestCase ):
  def testQmark1( self ):
    """Does qmark support produce expected result"""
    query = """SELECT * FROM x WHERE this = %(this)s
    AND that = %(that)s"""
    values = { 'this': 23, 'that': 24 }
    pf = pyformatsupport.PyFormatSupport( values, 'qmark' )
    newQuery = query%pf
    assert newQuery == """SELECT * FROM x WHERE this = ?
    AND that = ?"""
    assert len(pf.sequential) == 2
    assert pf.sequential == [23,24]
    pf.finishBuilding()
    result = newQuery%pf
    assert len(pf.sequential) == 2
  def testQmark2( self ):
    """Does support for multiple refs to same value"""
    query = """SELECT * FROM x WHERE this = %(this)s
    AND that = %(this)s"""
    values = { 'this': 23, 'that': 24 }
    pf = pyformatsupport.PyFormatSupport( values, 'qmark' )
    newQuery = query%pf
    assert newQuery == """SELECT * FROM x WHERE this = ?
    AND that = ?"""
    assert len(pf.sequential) == 2
    assert pf.sequential == [23,23]
    pf.finishBuilding()
    result = newQuery%pf
    assert len(pf.sequential) == 2
  def testFormat( self ):
    """Does format support produce expected result"""
    query = """SELECT * FROM x WHERE this = %(this)s
    AND that = %(that)s AND this2 = %(this)s"""
    values = { 'this': 23, 'that': 24 }
    pf = pyformatsupport.PyFormatSupport( values, 'format' )
    newQuery = query%pf
    assert newQuery == """SELECT * FROM x WHERE this = %s
    AND that = %s AND this2 = %s""", newQuery
    assert len(pf.sequential) == 3
    assert pf.sequential == [23,24,23]
    pf.finishBuilding()
    result = newQuery%tuple(pf)
    assert len(pf.sequential) == 3
    assert result == """SELECT * FROM x WHERE this = 23
    AND that = 24 AND this2 = 23""", result
  def testNumeric( self ):
    """Does numeric support produce expected result"""
    query = """SELECT * FROM x WHERE this = %(this)s
    AND that = %(that)s AND this2 = %(this)s"""
    values = { 'this': 23, 'that': 24 }
    pf = pyformatsupport.PyFormatSupport( values, 'numeric' )
    newQuery = query%pf
    assert newQuery == """SELECT * FROM x WHERE this = :0
    AND that = :1 AND this2 = :2""", newQuery
    assert len(pf.sequential) == 3
    assert pf.sequential == [23,24,23]
    pf.finishBuilding()
    result = newQuery%pf
    assert len(pf.sequential) == 3
  def testNamed( self ):
    """Does named support produce expected result"""
    query = """SELECT * FROM x WHERE this = %(this)s
    AND that = %(that)s AND this2 = %(this)s"""
    values = { 'this': 23, 'that': 24 }
    pf = pyformatsupport.PyFormatSupport( values, 'named' )
    newQuery = query%pf
    assert newQuery == """SELECT * FROM x WHERE this = :this
    AND that = :that AND this2 = :this""", newQuery
    assert len(pf.sequential) == 3
    assert pf.sequential == [23,24,23]
    pf.finishBuilding()
    result = newQuery%pf
    assert len(pf.sequential) == 3

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