test_crash.py :  » Database » PyDB2 » PyDB2_1.1.1 » test » 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 » PyDB2 
PyDB2 » PyDB2_1.1.1 » test » test_crash.py
import unittest
import DB2
import Config

import sys
wait_for_keypress = 1

if not "python_d" in sys.executable:
    sys.exit("ERROR: Must run in debug mode (build with debug flag and run with python_d.exe)")
if wait_for_keypress:
    raw_input("Press Enter when you've set up debugging")
    
class SimpleDB2Test_Crash(unittest.TestCase):
    def setUp(self):
        self.db = DB2.connect(**Config.ConnDict)
        self.tableName = 'PYDB2TEST_0'
        self.cs = self.db.cursor()

    def tearDown(self):
        self.cs.close()
        self.db.close()

    def _createTable(self):
        self.cs.execute( """CREATE TABLE %s
                (
                    C1 INTEGER,
                    C2 VARCHAR(3),
                    C3 TIMESTAMP
                )
            """ % self.tableName)

    def _insertData(self, valTuple):
        self.cs.execute( """INSERT INTO %s
                    VALUES (?, ?, ?)
            """ % self.tableName,
            valTuple)

    def _insertDataList(self, valList):
        self.cs.executemany( """INSERT INTO %s
                    VALUES (?, ?, ?)
            """ % self.tableName,
            valList)


    def test_0001_string_parameter_overflow(self):
        """String parameter overflow"""
        self._createTable()
        self.assertRaises(
            DB2.ProgrammingError,
            self._insertData,
            (1, 'XXXX', '2006-08-16 22.33.44.000000')
            )

    def test_0002_refcount_wrong_on_error(self):
        """refcount wrong on cursor error"""
        self._createTable()
        self.assertRaises(
            DB2.ProgrammingError,
            self._insertData,
            (1, 'XXX', '2006-08-16.00.00.00.000000')
            )

    def test_0003_refcount_wrong_on_connection_error(self):
        """refcount wrong on connection error"""
        self.assertRaises(
            DB2.DatabaseError,
            DB2.connect,
            "no_database_here", "sdfds", "sfsdf"
            )
        self.db.close()

    def test_0004_refcount_wrong_on_closed_connection_error(self):
        """refcount wrong on closed connection error"""
        self.db.close()
        self.assertRaises(
            DB2.Error,
            self._createTable
            )
           
if __name__ == '__main__':
    suite = unittest.TestSuite()

    for t in [
            SimpleDB2Test_Crash,
        ]:
        suite.addTest(unittest.makeSuite(t))

    unittest.TextTestRunner(verbosity=2).run(suite)

# FIN
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.