Simplify test suite by combining Python 2 and 3 scripts into one script that
runs on both without changes; rename ArrayDMLBatchError to Features12_1 in preparation for adding additional 12.1 features.
This commit is contained in:
parent
f745c1eb08
commit
8584a5d5f8
7
setup.py
7
setup.py
@ -307,11 +307,8 @@ class test(distutils.core.Command):
|
||||
buildCommand = self.distribution.get_command_obj("build")
|
||||
sys.path.insert(0, os.path.abspath("test"))
|
||||
sys.path.insert(0, os.path.abspath(buildCommand.build_lib))
|
||||
if sys.version_info[0] < 3:
|
||||
execfile(os.path.join("test", "test.py"))
|
||||
else:
|
||||
fileName = os.path.join("test", "test3k.py")
|
||||
exec(open(fileName).read())
|
||||
fileName = os.path.join("test", "test.py")
|
||||
exec(open(fileName).read())
|
||||
|
||||
commandClasses = dict(build = build, bdist_rpm = bdist_rpm, test = test)
|
||||
|
||||
|
||||
@ -1,165 +0,0 @@
|
||||
"""Module for testing row count per iteration for DML Array and Batch errors"""
|
||||
|
||||
class TestArrayDMLBatchError(BaseTestCase):
|
||||
|
||||
def testArrayDMLRowCountsOff(self):
|
||||
"test executing with arraydmlrowcounts mode disabled"
|
||||
self.cursor.execute("truncate table TestArrayDML")
|
||||
rows = [ (1, "First"),
|
||||
(2, "Second") ]
|
||||
sql = "insert into TestArrayDML (IntCol,StringCol) values (:1,:2)"
|
||||
self.cursor.executemany(sql, rows, arraydmlrowcounts = False)
|
||||
self.assertRaises(cx_Oracle.DatabaseError,
|
||||
self.cursor.getarraydmlrowcounts)
|
||||
rows = [ (3, "Third"),
|
||||
(4, "Fourth") ]
|
||||
self.cursor.executemany(sql, rows)
|
||||
self.assertRaises(cx_Oracle.DatabaseError,
|
||||
self.cursor.getarraydmlrowcounts)
|
||||
|
||||
def testArrayDMLRowCountsOn(self):
|
||||
"test executing with arraydmlrowcounts mode enabled"
|
||||
self.cursor.execute("truncate table TestArrayDML")
|
||||
rows = [ ( 1, "First", 100),
|
||||
( 2, "Second", 200),
|
||||
( 3, "Third", 300),
|
||||
( 4, "Fourth", 300),
|
||||
( 5, "Fifth", 300) ]
|
||||
sql = "insert into TestArrayDML (IntCol,StringCol,IntCol2) " \
|
||||
"values (:1,:2,:3)"
|
||||
self.cursor.executemany(sql, rows, arraydmlrowcounts = True)
|
||||
self.connection.commit()
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(),
|
||||
[1, 1, 1, 1, 1])
|
||||
self.cursor.execute("select count(*) from TestArrayDML")
|
||||
count, = self.cursor.fetchone()
|
||||
self.assertEqual(count, len(rows))
|
||||
|
||||
def testExceptionInIteration(self):
|
||||
"test executing with arraydmlrowcounts with exception"
|
||||
self.cursor.execute("truncate table TestArrayDML")
|
||||
rows = [ (1, "First"),
|
||||
(2, "Second"),
|
||||
(2, "Third"),
|
||||
(4, "Fourth") ]
|
||||
sql = "insert into TestArrayDML (IntCol,StringCol) values (:1,:2)"
|
||||
self.assertRaises(cx_Oracle.DatabaseError, self.cursor.executemany,
|
||||
sql, rows, arraydmlrowcounts = True)
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 1])
|
||||
|
||||
def testExecutingDelete(self):
|
||||
"test executing delete statement with arraydmlrowcount mode"
|
||||
self.cursor.execute("truncate table TestArrayDML")
|
||||
rows = [ (1, "First", 100),
|
||||
(2, "Second", 200),
|
||||
(3, "Third", 300),
|
||||
(4, "Fourth", 300),
|
||||
(5, "Fifth", 300),
|
||||
(6, "Sixth", 400),
|
||||
(7, "Seventh", 400),
|
||||
(8, "Eighth", 500) ]
|
||||
sql = "insert into TestArrayDML (IntCol,StringCol,IntCol2) " \
|
||||
"values (:1, :2, :3)"
|
||||
self.cursor.executemany(sql, rows)
|
||||
rows = [ (200,), (300,), (400,) ]
|
||||
statement = "delete from TestArrayDML where IntCol2 = :1"
|
||||
self.cursor.executemany(statement, rows, arraydmlrowcounts = True)
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 3, 2])
|
||||
|
||||
def testExecutingUpdate(self):
|
||||
"test executing update statement with arraydmlrowcount mode"
|
||||
self.cursor.execute("truncate table TestArrayDML")
|
||||
rows = [ (1, "First",100),
|
||||
(2, "Second",200),
|
||||
(3, "Third",300),
|
||||
(4, "Fourth",300),
|
||||
(5, "Fifth",300),
|
||||
(6, "Sixth",400),
|
||||
(7, "Seventh",400),
|
||||
(8, "Eighth",500) ]
|
||||
sql = "insert into TestArrayDML (IntCol,StringCol,IntCol2) " \
|
||||
"values (:1, :2, :3)"
|
||||
self.cursor.executemany(sql, rows)
|
||||
rows = [ ("One", 100),
|
||||
("Two", 200),
|
||||
("Three", 300),
|
||||
("Four", 400) ]
|
||||
sql = "update TestArrayDML set StringCol = :1 where IntCol2 = :2"
|
||||
self.cursor.executemany(sql, rows, arraydmlrowcounts = True)
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 1, 3, 2])
|
||||
|
||||
def testInsertWithBatchError(self):
|
||||
"test executing insert with multiple distinct batch errors"
|
||||
self.cursor.execute("truncate table TestArrayDML")
|
||||
rows = [ (1, "First", 100),
|
||||
(2, "Second", 200),
|
||||
(2, "Third", 300),
|
||||
(4, "Fourth", 400),
|
||||
(5, "Fourth", 1000)]
|
||||
sql = "insert into TestArrayDML (IntCol, StringCol, IntCol2) " \
|
||||
"values (:1, :2, :3)"
|
||||
self.cursor.executemany(sql, rows, batcherrors = True,
|
||||
arraydmlrowcounts = True)
|
||||
expectedErrors = [
|
||||
( 4, 1438, "ORA-01438: value larger than specified " \
|
||||
"precision allowed for this column\n" ),
|
||||
( 2, 1, "ORA-00001: unique constraint " \
|
||||
"(CX_ORACLE.TESTARRAYDML_PK) violated\n")
|
||||
]
|
||||
actualErrors = [(e.offset, e.code, e.message) \
|
||||
for e in self.cursor.getbatcherrors()]
|
||||
self.assertEqual(actualErrors, expectedErrors)
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(),
|
||||
[1, 1, 0, 1, 0])
|
||||
|
||||
def testBatchErrorFalse(self):
|
||||
"test batcherrors mode set to False"
|
||||
self.cursor.execute("truncate table TestArrayDML")
|
||||
rows = [ (1, "First", 100),
|
||||
(2, "Second", 200),
|
||||
(2, "Third", 300) ]
|
||||
sql = "insert into TestArrayDML (IntCol, StringCol, IntCol2) " \
|
||||
"values (:1, :2, :3)"
|
||||
self.assertRaises(cx_Oracle.IntegrityError,
|
||||
self.cursor.executemany, sql, rows, batcherrors = False)
|
||||
|
||||
def testUpdatewithBatchError(self):
|
||||
"test executing in succession with batch error"
|
||||
self.cursor.execute("truncate table TestArrayDML")
|
||||
rows = [ (1, "First", 100),
|
||||
(2, "Second", 200),
|
||||
(3, "Third", 300),
|
||||
(4, "Second", 300),
|
||||
(5, "Fifth", 300),
|
||||
(6, "Sixth", 400),
|
||||
(6, "Seventh", 400),
|
||||
(8, "Eighth", 100) ]
|
||||
sql = "insert into TestArrayDML (IntCol, StringCol, IntCol2) " \
|
||||
"values (:1, :2, :3)"
|
||||
self.cursor.executemany(sql, rows, batcherrors = True)
|
||||
expectedErrors = [
|
||||
( 6, 1, "ORA-00001: unique constraint " \
|
||||
"(CX_ORACLE.TESTARRAYDML_PK) violated\n")
|
||||
]
|
||||
actualErrors = [(e.offset, e.code, e.message) \
|
||||
for e in self.cursor.getbatcherrors()]
|
||||
self.assertEqual(actualErrors, expectedErrors)
|
||||
rows = [ (101, "First"),
|
||||
(201, "Second"),
|
||||
(3000, "Third"),
|
||||
(900, "Ninth"),
|
||||
(301, "Third") ]
|
||||
sql = "update TestArrayDML set IntCol2 = :1 where StringCol = :2"
|
||||
self.cursor.executemany(sql, rows, arraydmlrowcounts = True,
|
||||
batcherrors = True)
|
||||
expectedErrors = [
|
||||
( 2, 1438, "ORA-01438: value larger than specified " \
|
||||
"precision allowed for this column\n" )
|
||||
]
|
||||
actualErrors = [(e.offset, e.code, e.message) \
|
||||
for e in self.cursor.getbatcherrors()]
|
||||
self.assertEqual(actualErrors, expectedErrors)
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(),
|
||||
[1, 2, 0, 0, 1])
|
||||
self.assertEqual(self.cursor.rowcount, 4)
|
||||
|
||||
@ -1,254 +0,0 @@
|
||||
"""Module for testing number variables."""
|
||||
|
||||
import cx_Oracle
|
||||
import decimal
|
||||
|
||||
class TestNumberVar(BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
BaseTestCase.setUp(self)
|
||||
self.rawData = []
|
||||
self.dataByKey = {}
|
||||
for i in range(1, 11):
|
||||
numberCol = i + i * 0.25
|
||||
floatCol = i + i * 0.75
|
||||
unconstrainedCol = i ** 3 + i * 0.5
|
||||
if i % 2:
|
||||
nullableCol = 143 ** i
|
||||
else:
|
||||
nullableCol = None
|
||||
dataTuple = (i, numberCol, floatCol, unconstrainedCol, nullableCol)
|
||||
self.rawData.append(dataTuple)
|
||||
self.dataByKey[i] = dataTuple
|
||||
|
||||
def testBindDecimal(self):
|
||||
"test binding in a decimal.Decimal"
|
||||
self.cursor.execute("""
|
||||
select * from TestNumbers
|
||||
where NumberCol - :value1 - :value2 = trunc(NumberCol)""",
|
||||
value1 = decimal.Decimal("0.20"),
|
||||
value2 = decimal.Decimal("0.05"))
|
||||
self.assertEqual(self.cursor.fetchall(),
|
||||
[self.dataByKey[1], self.dataByKey[5], self.dataByKey[9]])
|
||||
|
||||
def testBindFloat(self):
|
||||
"test binding in a float"
|
||||
self.cursor.execute("""
|
||||
select * from TestNumbers
|
||||
where NumberCol - :value = trunc(NumberCol)""",
|
||||
value = 0.25)
|
||||
self.assertEqual(self.cursor.fetchall(),
|
||||
[self.dataByKey[1], self.dataByKey[5], self.dataByKey[9]])
|
||||
|
||||
def testBindSmallLong(self):
|
||||
"test binding in a small long integer"
|
||||
self.cursor.execute("""
|
||||
select * from TestNumbers
|
||||
where IntCol = :value""",
|
||||
value = 3)
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[3]])
|
||||
|
||||
def testBindLargeLong(self):
|
||||
"test binding in a large long integer"
|
||||
valueVar = self.cursor.var(cx_Oracle.NUMBER)
|
||||
valueVar.setvalue(0, 6088343244)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value + 5;
|
||||
end;""",
|
||||
value = valueVar)
|
||||
value = valueVar.getvalue()
|
||||
self.assertEqual(value, 6088343249)
|
||||
|
||||
def testBindIntegerAfterString(self):
|
||||
"test binding in an number after setting input sizes to a string"
|
||||
self.cursor.setinputsizes(value = 15)
|
||||
self.cursor.execute("""
|
||||
select * from TestNumbers
|
||||
where IntCol = :value""",
|
||||
value = 3)
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[3]])
|
||||
|
||||
def testBindNull(self):
|
||||
"test binding in a null"
|
||||
self.cursor.execute("""
|
||||
select * from TestNumbers
|
||||
where IntCol = :value""",
|
||||
value = None)
|
||||
self.assertEqual(self.cursor.fetchall(), [])
|
||||
|
||||
def testBindNumberArrayDirect(self):
|
||||
"test binding in a number array"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
array = [r[1] for r in self.rawData]
|
||||
statement = """
|
||||
begin
|
||||
:returnValue := pkg_TestNumberArrays.TestInArrays(
|
||||
:startValue, :array);
|
||||
end;"""
|
||||
self.cursor.execute(statement,
|
||||
returnValue = returnValue,
|
||||
startValue = 5,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 73.75)
|
||||
array = list(range(15))
|
||||
self.cursor.execute(statement,
|
||||
startValue = 10,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 115.0)
|
||||
|
||||
def testBindNumberArrayBySizes(self):
|
||||
"test binding in a number array (with setinputsizes)"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
self.cursor.setinputsizes(array = [cx_Oracle.NUMBER, 10])
|
||||
array = [r[1] for r in self.rawData]
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:returnValue := pkg_TestNumberArrays.TestInArrays(
|
||||
:startValue, :array);
|
||||
end;""",
|
||||
returnValue = returnValue,
|
||||
startValue = 6,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 74.75)
|
||||
|
||||
def testBindNumberArrayByVar(self):
|
||||
"test binding in a number array (with arrayvar)"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
array = self.cursor.arrayvar(cx_Oracle.NUMBER,
|
||||
[r[1] for r in self.rawData])
|
||||
array.setvalue(0, [r[1] for r in self.rawData])
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:returnValue := pkg_TestNumberArrays.TestInArrays(
|
||||
:integerValue, :array);
|
||||
end;""",
|
||||
returnValue = returnValue,
|
||||
integerValue = 7,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 75.75)
|
||||
|
||||
def testBindZeroLengthNumberArrayByVar(self):
|
||||
"test binding in a zero length number array (with arrayvar)"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
array = self.cursor.arrayvar(cx_Oracle.NUMBER, 0)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:returnValue := pkg_TestNumberArrays.TestInArrays(
|
||||
:integerValue, :array);
|
||||
end;""",
|
||||
returnValue = returnValue,
|
||||
integerValue = 8,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 8.0)
|
||||
self.assertEqual(array.getvalue(), [])
|
||||
|
||||
def testBindInOutNumberArrayByVar(self):
|
||||
"test binding in/out a number array (with arrayvar)"
|
||||
array = self.cursor.arrayvar(cx_Oracle.NUMBER, 10)
|
||||
originalData = [r[1] for r in self.rawData]
|
||||
expectedData = [originalData[i - 1] * 10 for i in range(1, 6)] + \
|
||||
originalData[5:]
|
||||
array.setvalue(0, originalData)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
pkg_TestNumberArrays.TestInOutArrays(:numElems, :array);
|
||||
end;""",
|
||||
numElems = 5,
|
||||
array = array)
|
||||
self.assertEqual(array.getvalue(), expectedData)
|
||||
|
||||
def testBindOutNumberArrayByVar(self):
|
||||
"test binding out a Number array (with arrayvar)"
|
||||
array = self.cursor.arrayvar(cx_Oracle.NUMBER, 6)
|
||||
expectedData = [i * 100 for i in range(1, 7)]
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
pkg_TestNumberArrays.TestOutArrays(:numElems, :array);
|
||||
end;""",
|
||||
numElems = 6,
|
||||
array = array)
|
||||
self.assertEqual(array.getvalue(), expectedData)
|
||||
|
||||
def testBindOutSetInputSizes(self):
|
||||
"test binding out with set input sizes defined"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.NUMBER)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := 5;
|
||||
end;""")
|
||||
self.assertEqual(vars["value"].getvalue(), 5)
|
||||
|
||||
def testBindInOutSetInputSizes(self):
|
||||
"test binding in/out with set input sizes defined"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.NUMBER)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value + 5;
|
||||
end;""",
|
||||
value = 1.25)
|
||||
self.assertEqual(vars["value"].getvalue(), 6.25)
|
||||
|
||||
def testBindOutVar(self):
|
||||
"test binding out with cursor.var() method"
|
||||
var = self.cursor.var(cx_Oracle.NUMBER)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := 5;
|
||||
end;""",
|
||||
value = var)
|
||||
self.assertEqual(var.getvalue(), 5)
|
||||
|
||||
def testBindInOutVarDirectSet(self):
|
||||
"test binding in/out with cursor.var() method"
|
||||
var = self.cursor.var(cx_Oracle.NUMBER)
|
||||
var.setvalue(0, 2.25)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value + 5;
|
||||
end;""",
|
||||
value = var)
|
||||
self.assertEqual(var.getvalue(), 7.25)
|
||||
|
||||
def testCursorDescription(self):
|
||||
"test cursor description is accurate"
|
||||
self.cursor.execute("select * from TestNumbers")
|
||||
self.assertEqual(self.cursor.description,
|
||||
[ ('INTCOL', cx_Oracle.NUMBER, 10, 22, 9, 0, 0),
|
||||
('NUMBERCOL', cx_Oracle.NUMBER, 13, 22, 9, 2, 0),
|
||||
('FLOATCOL', cx_Oracle.NUMBER, 127, 22, 126, -127, 0),
|
||||
('UNCONSTRAINEDCOL', cx_Oracle.NUMBER, 127, 22, 0, -127, 0),
|
||||
('NULLABLECOL', cx_Oracle.NUMBER, 39, 22, 38, 0, 1) ])
|
||||
|
||||
def testFetchAll(self):
|
||||
"test that fetching all of the data returns the correct results"
|
||||
self.cursor.execute("select * From TestNumbers order by IntCol")
|
||||
self.assertEqual(self.cursor.fetchall(), self.rawData)
|
||||
self.assertEqual(self.cursor.fetchall(), [])
|
||||
|
||||
def testFetchMany(self):
|
||||
"test that fetching data in chunks returns the correct results"
|
||||
self.cursor.execute("select * From TestNumbers order by IntCol")
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.rawData[0:3])
|
||||
self.assertEqual(self.cursor.fetchmany(2), self.rawData[3:5])
|
||||
self.assertEqual(self.cursor.fetchmany(4), self.rawData[5:9])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:])
|
||||
self.assertEqual(self.cursor.fetchmany(3), [])
|
||||
|
||||
def testFetchOne(self):
|
||||
"test that fetching a single row returns the correct results"
|
||||
self.cursor.execute("""
|
||||
select *
|
||||
from TestNumbers
|
||||
where IntCol in (3, 4)
|
||||
order by IntCol""")
|
||||
self.assertEqual(self.cursor.fetchone(), self.dataByKey[3])
|
||||
self.assertEqual(self.cursor.fetchone(), self.dataByKey[4])
|
||||
self.assertEqual(self.cursor.fetchone(), None)
|
||||
|
||||
def testReturnAsFloat(self):
|
||||
"test that fetching a floating point number returns such in Python"
|
||||
self.cursor.execute("select 1.25 from dual")
|
||||
result, = self.cursor.fetchone()
|
||||
self.assertEqual(result, 1.25)
|
||||
|
||||
@ -1,273 +0,0 @@
|
||||
"""Module for testing string variables."""
|
||||
|
||||
class TestStringVar(BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
BaseTestCase.setUp(self)
|
||||
self.rawData = []
|
||||
self.dataByKey = {}
|
||||
for i in range(1, 11):
|
||||
stringCol = "String %d" % i
|
||||
fixedCharCol = ("Fixed Char %d" % i).ljust(40)
|
||||
rawCol = ("Raw %d" % i).encode("ascii")
|
||||
if i % 2:
|
||||
nullableCol = "Nullable %d" % i
|
||||
else:
|
||||
nullableCol = None
|
||||
dataTuple = (i, stringCol, rawCol, fixedCharCol, nullableCol)
|
||||
self.rawData.append(dataTuple)
|
||||
self.dataByKey[i] = dataTuple
|
||||
|
||||
def testBindString(self):
|
||||
"test binding in a string"
|
||||
self.cursor.execute("""
|
||||
select * from TestStrings
|
||||
where StringCol = :value""",
|
||||
value = "String 5")
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[5]])
|
||||
|
||||
def testBindDifferentVar(self):
|
||||
"test binding a different variable on second execution"
|
||||
retval_1 = self.cursor.var(cx_Oracle.STRING, 30)
|
||||
retval_2 = self.cursor.var(cx_Oracle.STRING, 30)
|
||||
self.cursor.execute("begin :retval := 'Called'; end;",
|
||||
retval = retval_1)
|
||||
self.assertEqual(retval_1.getvalue(), "Called")
|
||||
self.cursor.execute("begin :retval := 'Called'; end;",
|
||||
retval = retval_2)
|
||||
self.assertEqual(retval_2.getvalue(), "Called")
|
||||
|
||||
def testBindStringAfterNumber(self):
|
||||
"test binding in a string after setting input sizes to a number"
|
||||
self.cursor.setinputsizes(value = cx_Oracle.NUMBER)
|
||||
self.cursor.execute("""
|
||||
select * from TestStrings
|
||||
where StringCol = :value""",
|
||||
value = "String 6")
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[6]])
|
||||
|
||||
def testBindStringArrayDirect(self):
|
||||
"test binding in a string array"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
array = [r[1] for r in self.rawData]
|
||||
statement = """
|
||||
begin
|
||||
:returnValue := pkg_TestStringArrays.TestInArrays(
|
||||
:integerValue, :array);
|
||||
end;"""
|
||||
self.cursor.execute(statement,
|
||||
returnValue = returnValue,
|
||||
integerValue = 5,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 86)
|
||||
array = [ "String - %d" % i for i in range(15) ]
|
||||
self.cursor.execute(statement,
|
||||
integerValue = 8,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 163)
|
||||
|
||||
def testBindStringArrayBySizes(self):
|
||||
"test binding in a string array (with setinputsizes)"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
self.cursor.setinputsizes(array = [cx_Oracle.STRING, 10])
|
||||
array = [r[1] for r in self.rawData]
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:returnValue := pkg_TestStringArrays.TestInArrays(
|
||||
:integerValue, :array);
|
||||
end;""",
|
||||
returnValue = returnValue,
|
||||
integerValue = 6,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 87)
|
||||
|
||||
def testBindStringArrayByVar(self):
|
||||
"test binding in a string array (with arrayvar)"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
array = self.cursor.arrayvar(cx_Oracle.STRING, 10, 20)
|
||||
array.setvalue(0, [r[1] for r in self.rawData])
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:returnValue := pkg_TestStringArrays.TestInArrays(
|
||||
:integerValue, :array);
|
||||
end;""",
|
||||
returnValue = returnValue,
|
||||
integerValue = 7,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 88)
|
||||
|
||||
def testBindInOutStringArrayByVar(self):
|
||||
"test binding in/out a string array (with arrayvar)"
|
||||
array = self.cursor.arrayvar(cx_Oracle.STRING, 10, 100)
|
||||
originalData = [r[1] for r in self.rawData]
|
||||
expectedData = ["Converted element # %d originally had length %d" % \
|
||||
(i, len(originalData[i - 1])) for i in range(1, 6)] + \
|
||||
originalData[5:]
|
||||
array.setvalue(0, originalData)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
pkg_TestStringArrays.TestInOutArrays(:numElems, :array);
|
||||
end;""",
|
||||
numElems = 5,
|
||||
array = array)
|
||||
self.assertEqual(array.getvalue(), expectedData)
|
||||
|
||||
def testBindOutStringArrayByVar(self):
|
||||
"test binding out a string array (with arrayvar)"
|
||||
array = self.cursor.arrayvar(cx_Oracle.STRING, 6, 100)
|
||||
expectedData = ["Test out element # %d" % i for i in range(1, 7)]
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
pkg_TestStringArrays.TestOutArrays(:numElems, :array);
|
||||
end;""",
|
||||
numElems = 6,
|
||||
array = array)
|
||||
self.assertEqual(array.getvalue(), expectedData)
|
||||
|
||||
def testBindRaw(self):
|
||||
"test binding in a raw"
|
||||
self.cursor.setinputsizes(value = cx_Oracle.BINARY)
|
||||
self.cursor.execute("""
|
||||
select * from TestStrings
|
||||
where RawCol = :value""",
|
||||
value = b"Raw 4")
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[4]])
|
||||
|
||||
def testBindAndFetchRowid(self):
|
||||
"test binding (and fetching) a rowid"
|
||||
self.cursor.execute("""
|
||||
select rowid
|
||||
from TestStrings
|
||||
where IntCol = 3""")
|
||||
rowid, = self.cursor.fetchone()
|
||||
self.cursor.execute("""
|
||||
select *
|
||||
from TestStrings
|
||||
where rowid = :value""",
|
||||
value = rowid)
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[3]])
|
||||
|
||||
def testBindNull(self):
|
||||
"test binding in a null"
|
||||
self.cursor.execute("""
|
||||
select * from TestStrings
|
||||
where StringCol = :value""",
|
||||
value = None)
|
||||
self.assertEqual(self.cursor.fetchall(), [])
|
||||
|
||||
def testBindOutSetInputSizesByType(self):
|
||||
"test binding out with set input sizes defined (by type)"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.STRING)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := 'TSI';
|
||||
end;""")
|
||||
self.assertEqual(vars["value"].getvalue(), "TSI")
|
||||
|
||||
def testBindOutSetInputSizesByInteger(self):
|
||||
"test binding out with set input sizes defined (by integer)"
|
||||
vars = self.cursor.setinputsizes(value = 30)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := 'TSI (I)';
|
||||
end;""")
|
||||
self.assertEqual(vars["value"].getvalue(), "TSI (I)")
|
||||
|
||||
def testBindInOutSetInputSizesByType(self):
|
||||
"test binding in/out with set input sizes defined (by type)"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.STRING)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value || ' TSI';
|
||||
end;""",
|
||||
value = "InVal")
|
||||
self.assertEqual(vars["value"].getvalue(), "InVal TSI")
|
||||
|
||||
def testBindInOutSetInputSizesByInteger(self):
|
||||
"test binding in/out with set input sizes defined (by integer)"
|
||||
vars = self.cursor.setinputsizes(value = 30)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value || ' TSI (I)';
|
||||
end;""",
|
||||
value = "InVal")
|
||||
self.assertEqual(vars["value"].getvalue(), "InVal TSI (I)")
|
||||
|
||||
def testBindOutVar(self):
|
||||
"test binding out with cursor.var() method"
|
||||
var = self.cursor.var(cx_Oracle.STRING)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := 'TSI (VAR)';
|
||||
end;""",
|
||||
value = var)
|
||||
self.assertEqual(var.getvalue(), "TSI (VAR)")
|
||||
|
||||
def testBindInOutVarDirectSet(self):
|
||||
"test binding in/out with cursor.var() method"
|
||||
var = self.cursor.var(cx_Oracle.STRING)
|
||||
var.setvalue(0, "InVal")
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value || ' TSI (VAR)';
|
||||
end;""",
|
||||
value = var)
|
||||
self.assertEqual(var.getvalue(), "InVal TSI (VAR)")
|
||||
|
||||
def testBindLongString(self):
|
||||
"test that binding a long string succeeds"
|
||||
self.cursor.setinputsizes(bigString = cx_Oracle.LONG_STRING)
|
||||
self.cursor.execute("""
|
||||
declare
|
||||
t_Temp varchar2(10000);
|
||||
begin
|
||||
t_Temp := :bigString;
|
||||
end;""",
|
||||
bigString = "X" * 10000)
|
||||
|
||||
def testBindLongStringAfterSettingSize(self):
|
||||
"test that setinputsizes() returns a long variable"
|
||||
var = self.cursor.setinputsizes(test = 90000)["test"]
|
||||
inString = "1234567890" * 9000
|
||||
var.setvalue(0, inString)
|
||||
outString = var.getvalue()
|
||||
self.assertEqual(inString, outString,
|
||||
"output does not match: in was %d, out was %d" % \
|
||||
(len(inString), len(outString)))
|
||||
|
||||
def testCursorDescription(self):
|
||||
"test cursor description is accurate"
|
||||
self.cursor.execute("select * from TestStrings")
|
||||
self.assertEqual(self.cursor.description,
|
||||
[ ('INTCOL', cx_Oracle.NUMBER, 10, 22, 9, 0, 0),
|
||||
('STRINGCOL', cx_Oracle.STRING, 20, 20, 0, 0, 0),
|
||||
('RAWCOL', cx_Oracle.BINARY, 30, 30, 0, 0, 0),
|
||||
('FIXEDCHARCOL', cx_Oracle.FIXED_CHAR, 40, 40, 0, 0, 0),
|
||||
('NULLABLECOL', cx_Oracle.STRING, 50, 50, 0, 0, 1) ])
|
||||
|
||||
def testFetchAll(self):
|
||||
"test that fetching all of the data returns the correct results"
|
||||
self.cursor.execute("select * From TestStrings order by IntCol")
|
||||
self.assertEqual(self.cursor.fetchall(), self.rawData)
|
||||
self.assertEqual(self.cursor.fetchall(), [])
|
||||
|
||||
def testFetchMany(self):
|
||||
"test that fetching data in chunks returns the correct results"
|
||||
self.cursor.execute("select * From TestStrings order by IntCol")
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.rawData[0:3])
|
||||
self.assertEqual(self.cursor.fetchmany(2), self.rawData[3:5])
|
||||
self.assertEqual(self.cursor.fetchmany(4), self.rawData[5:9])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:])
|
||||
self.assertEqual(self.cursor.fetchmany(3), [])
|
||||
|
||||
def testFetchOne(self):
|
||||
"test that fetching a single row returns the correct results"
|
||||
self.cursor.execute("""
|
||||
select *
|
||||
from TestStrings
|
||||
where IntCol in (3, 4)
|
||||
order by IntCol""")
|
||||
self.assertEqual(self.cursor.fetchone(), self.dataByKey[3])
|
||||
self.assertEqual(self.cursor.fetchone(), self.dataByKey[4])
|
||||
self.assertEqual(self.cursor.fetchone(), None)
|
||||
|
||||
@ -1,6 +1,11 @@
|
||||
"""Module for testing row count per iteration for DML Array and Batch errors"""
|
||||
"""Module for testing features introduced in 12.1"""
|
||||
|
||||
class TestArrayDMLBatchError(BaseTestCase):
|
||||
import sys
|
||||
|
||||
if sys.version_info > (3,):
|
||||
long = int
|
||||
|
||||
class TestFeatures12_1(BaseTestCase):
|
||||
|
||||
def testArrayDMLRowCountsOff(self):
|
||||
"test executing with arraydmlrowcounts mode disabled"
|
||||
@ -30,7 +35,7 @@ class TestArrayDMLBatchError(BaseTestCase):
|
||||
self.cursor.executemany(sql, rows, arraydmlrowcounts = True)
|
||||
self.connection.commit()
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(),
|
||||
[1L, 1L, 1L, 1L, 1L])
|
||||
[long(1), long(1), long(1), long(1), long(1)])
|
||||
self.cursor.execute("select count(*) from TestArrayDML")
|
||||
count, = self.cursor.fetchone()
|
||||
self.assertEqual(count, len(rows))
|
||||
@ -45,7 +50,8 @@ class TestArrayDMLBatchError(BaseTestCase):
|
||||
sql = "insert into TestArrayDML (IntCol,StringCol) values (:1,:2)"
|
||||
self.assertRaises(cx_Oracle.DatabaseError, self.cursor.executemany,
|
||||
sql, rows, arraydmlrowcounts = True)
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(), [1L, 1L])
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(),
|
||||
[long(1), long(1)])
|
||||
|
||||
def testExecutingDelete(self):
|
||||
"test executing delete statement with arraydmlrowcount mode"
|
||||
@ -64,7 +70,8 @@ class TestArrayDMLBatchError(BaseTestCase):
|
||||
rows = [ (200,), (300,), (400,) ]
|
||||
statement = "delete from TestArrayDML where IntCol2 = :1"
|
||||
self.cursor.executemany(statement, rows, arraydmlrowcounts = True)
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(), [1L, 3L, 2L])
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(),
|
||||
[long(1), long(3), long(2)])
|
||||
|
||||
def testExecutingUpdate(self):
|
||||
"test executing update statement with arraydmlrowcount mode"
|
||||
@ -87,7 +94,7 @@ class TestArrayDMLBatchError(BaseTestCase):
|
||||
sql = "update TestArrayDML set StringCol = :1 where IntCol2 = :2"
|
||||
self.cursor.executemany(sql, rows, arraydmlrowcounts = True)
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(),
|
||||
[1L, 1L, 3L, 2L])
|
||||
[long(1), long(1), long(3), long(2)])
|
||||
|
||||
def testInsertWithBatchError(self):
|
||||
"test executing insert with multiple distinct batch errors"
|
||||
@ -111,7 +118,7 @@ class TestArrayDMLBatchError(BaseTestCase):
|
||||
for e in self.cursor.getbatcherrors()]
|
||||
self.assertEqual(actualErrors, expectedErrors)
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(),
|
||||
[1L, 1L, 0L, 1L, 0L])
|
||||
[long(1), long(1), long(0), long(1), long(0)])
|
||||
|
||||
def testBatchErrorFalse(self):
|
||||
"test batcherrors mode set to False"
|
||||
@ -161,6 +168,6 @@ class TestArrayDMLBatchError(BaseTestCase):
|
||||
for e in self.cursor.getbatcherrors()]
|
||||
self.assertEqual(actualErrors, expectedErrors)
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(),
|
||||
[1L, 2L, 0L, 0L, 1L])
|
||||
[long(1), long(2), long(0), long(0), long(1)])
|
||||
self.assertEqual(self.cursor.rowcount, 4)
|
||||
|
||||
@ -60,6 +60,7 @@ class TestNCharVar(BaseTestCase):
|
||||
"test binding in a unicode array"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
array = [r[1] for r in self.rawData]
|
||||
arrayVar = self.cursor.arrayvar(cx_Oracle.NCHAR, array)
|
||||
statement = """
|
||||
begin
|
||||
:retval := pkg_TestUnicodeArrays.TestInArrays(
|
||||
@ -68,12 +69,13 @@ class TestNCharVar(BaseTestCase):
|
||||
self.cursor.execute(statement,
|
||||
retval = returnValue,
|
||||
integerValue = 5,
|
||||
array = array)
|
||||
array = arrayVar)
|
||||
self.assertEqual(returnValue.getvalue(), 116)
|
||||
array = [ u"Unicode - \u3042 %d" % i for i in range(15) ]
|
||||
arrayVar = self.cursor.arrayvar(cx_Oracle.NCHAR, array)
|
||||
self.cursor.execute(statement,
|
||||
integerValue = 8,
|
||||
array = array)
|
||||
array = arrayVar)
|
||||
self.assertEqual(returnValue.getvalue(), 208)
|
||||
|
||||
def testBindUnicodeArrayBySizes(self):
|
||||
|
||||
@ -2,6 +2,10 @@
|
||||
|
||||
import cx_Oracle
|
||||
import decimal
|
||||
import sys
|
||||
|
||||
if sys.version_info > (3,):
|
||||
long = int
|
||||
|
||||
class TestNumberVar(BaseTestCase):
|
||||
|
||||
@ -14,7 +18,7 @@ class TestNumberVar(BaseTestCase):
|
||||
floatCol = i + i * 0.75
|
||||
unconstrainedCol = i ** 3 + i * 0.5
|
||||
if i % 2:
|
||||
nullableCol = 143L ** i
|
||||
nullableCol = long(143) ** i
|
||||
else:
|
||||
nullableCol = None
|
||||
dataTuple = (i, numberCol, floatCol, unconstrainedCol, nullableCol)
|
||||
@ -53,7 +57,7 @@ class TestNumberVar(BaseTestCase):
|
||||
self.cursor.execute("""
|
||||
select * from TestNumbers
|
||||
where IntCol = :value""",
|
||||
value = 3L)
|
||||
value = long(3))
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[3]])
|
||||
|
||||
def testBindLargeLong(self):
|
||||
@ -99,7 +103,7 @@ class TestNumberVar(BaseTestCase):
|
||||
startValue = 5,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 73.75)
|
||||
array = range(15)
|
||||
array = list(range(15))
|
||||
self.cursor.execute(statement,
|
||||
startValue = 10,
|
||||
array = array)
|
||||
|
||||
@ -9,7 +9,7 @@ class TestStringVar(BaseTestCase):
|
||||
for i in range(1, 11):
|
||||
stringCol = "String %d" % i
|
||||
fixedCharCol = ("Fixed Char %d" % i).ljust(40)
|
||||
rawCol = "Raw %d" % i
|
||||
rawCol = ("Raw %d" % i).encode("ascii")
|
||||
if i % 2:
|
||||
nullableCol = "Nullable %d" % i
|
||||
else:
|
||||
@ -130,7 +130,7 @@ class TestStringVar(BaseTestCase):
|
||||
self.cursor.execute("""
|
||||
select * from TestStrings
|
||||
where RawCol = :value""",
|
||||
value = "Raw 4")
|
||||
value = "Raw 4".encode("ascii"))
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[4]])
|
||||
|
||||
def testBindAndFetchRowid(self):
|
||||
|
||||
60
test/test.py
60
test/test.py
@ -1,60 +1,66 @@
|
||||
"""Runs all defined unit tests."""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import cx_Oracle
|
||||
import imp
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
print "Running tests for cx_Oracle version", cx_Oracle.version,
|
||||
print cx_Oracle.buildtime
|
||||
print "File:", cx_Oracle.__file__
|
||||
inSetup = (os.path.basename(sys.argv[0]).lower() == "setup.py")
|
||||
|
||||
print("Running tests for cx_Oracle version", cx_Oracle.version,
|
||||
cx_Oracle.buildtime)
|
||||
print("File:", cx_Oracle.__file__)
|
||||
sys.stdout.flush()
|
||||
|
||||
import TestEnv
|
||||
|
||||
inSetup = (os.path.basename(sys.argv[0]).lower() == "setup.py")
|
||||
|
||||
if len(sys.argv) > 1 and not inSetup:
|
||||
moduleNames = [os.path.splitext(v)[0] for v in sys.argv[1:]]
|
||||
else:
|
||||
moduleNames = [
|
||||
"Connection",
|
||||
"uConnection",
|
||||
"Cursor",
|
||||
"uCursor",
|
||||
"CursorVar",
|
||||
"uCursorVar",
|
||||
"DateTimeVar",
|
||||
"uDateTimeVar",
|
||||
"Error",
|
||||
"IntervalVar",
|
||||
"uIntervalVar",
|
||||
"LobVar",
|
||||
"uLobVar",
|
||||
"LongVar",
|
||||
"uLongVar",
|
||||
"NCharVar",
|
||||
"NumberVar",
|
||||
"uNumberVar",
|
||||
"ObjectVar",
|
||||
"uObjectVar",
|
||||
"SessionPool",
|
||||
"uSessionPool",
|
||||
"StringVar",
|
||||
"uStringVar",
|
||||
"TimestampVar",
|
||||
"uTimestampVar"
|
||||
"TimestampVar"
|
||||
]
|
||||
if cx_Oracle.clientversion()[0] >= 12:
|
||||
moduleNames.insert(0, "uArrayDMLBatchError")
|
||||
moduleNames.insert(0, "ArrayDMLBatchError")
|
||||
if sys.version_info[0] < 3:
|
||||
moduleNames.extend([
|
||||
"uConnection",
|
||||
"uCursor",
|
||||
"uCursorVar",
|
||||
"uDateTimeVar",
|
||||
"uIntervalVar",
|
||||
"uLobVar",
|
||||
"uLongVar",
|
||||
"uNumberVar",
|
||||
"uObjectVar",
|
||||
"uSessionPool",
|
||||
"uStringVar",
|
||||
"uTimestampVar"
|
||||
])
|
||||
clientVersion = cx_Oracle.clientversion()
|
||||
if clientVersion[:2] >= (12, 1):
|
||||
moduleNames.append("BooleanVar")
|
||||
moduleNames.append("Features12_1")
|
||||
|
||||
class BaseTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
global cx_Oracle, TestEnv
|
||||
import cx_Oracle
|
||||
import TestEnv
|
||||
self.connection = cx_Oracle.connect(TestEnv.USERNAME,
|
||||
TestEnv.PASSWORD, TestEnv.TNSENTRY)
|
||||
self.cursor = self.connection.cursor()
|
||||
@ -70,8 +76,8 @@ runner = unittest.TextTestRunner(verbosity = 2)
|
||||
failures = []
|
||||
for name in moduleNames:
|
||||
fileName = name + ".py"
|
||||
print
|
||||
print "Running tests in", fileName
|
||||
print()
|
||||
print("Running tests in", fileName)
|
||||
if inSetup:
|
||||
fileName = os.path.join("test", fileName)
|
||||
module = imp.new_module(name)
|
||||
@ -82,14 +88,14 @@ for name in moduleNames:
|
||||
setattr(module, "TestCase", unittest.TestCase)
|
||||
setattr(module, "BaseTestCase", BaseTestCase)
|
||||
setattr(module, "cx_Oracle", cx_Oracle)
|
||||
execfile(fileName, module.__dict__)
|
||||
exec(open(fileName).read(), module.__dict__)
|
||||
tests = loader.loadTestsFromModule(module)
|
||||
result = runner.run(tests)
|
||||
if not result.wasSuccessful():
|
||||
failures.append(name)
|
||||
if failures:
|
||||
print "***** Some tests in the following modules failed. *****"
|
||||
print("***** Some tests in the following modules failed. *****")
|
||||
for name in failures:
|
||||
print " %s" % name
|
||||
print(" %s" % name)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@ -1,82 +0,0 @@
|
||||
"""Runs all defined unit tests."""
|
||||
|
||||
import cx_Oracle
|
||||
import imp
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
inSetup = (os.path.basename(sys.argv[0]).lower() == "setup.py")
|
||||
|
||||
print("Running tests for cx_Oracle version", cx_Oracle.version,
|
||||
cx_Oracle.buildtime)
|
||||
print("File:", cx_Oracle.__file__)
|
||||
sys.stdout.flush()
|
||||
|
||||
import TestEnv
|
||||
|
||||
if len(sys.argv) > 1 and not inSetup:
|
||||
moduleNames = [os.path.splitext(v)[0] for v in sys.argv[1:]]
|
||||
else:
|
||||
moduleNames = [
|
||||
"Connection",
|
||||
"Cursor",
|
||||
"CursorVar",
|
||||
"DateTimeVar",
|
||||
"Error",
|
||||
"LobVar",
|
||||
"LongVar",
|
||||
"3kNumberVar",
|
||||
"ObjectVar",
|
||||
"SessionPool",
|
||||
"3kStringVar",
|
||||
"TimestampVar"
|
||||
]
|
||||
if cx_Oracle.clientversion()[0] >= 12:
|
||||
moduleNames.insert(0, "3kArrayDMLBatchError")
|
||||
moduleNames.append("BooleanVar")
|
||||
|
||||
class BaseTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
import cx_Oracle
|
||||
import TestEnv
|
||||
self.connection = cx_Oracle.connect(TestEnv.USERNAME,
|
||||
TestEnv.PASSWORD, TestEnv.TNSENTRY)
|
||||
self.cursor = self.connection.cursor()
|
||||
self.cursor.arraysize = TestEnv.ARRAY_SIZE
|
||||
|
||||
def tearDown(self):
|
||||
del self.cursor
|
||||
del self.connection
|
||||
|
||||
|
||||
loader = unittest.TestLoader()
|
||||
runner = unittest.TextTestRunner(verbosity = 2)
|
||||
failures = []
|
||||
for name in moduleNames:
|
||||
fileName = name + ".py"
|
||||
print()
|
||||
print("Running tests in", fileName)
|
||||
if inSetup:
|
||||
fileName = os.path.join("test", fileName)
|
||||
module = imp.new_module(name)
|
||||
import cx_Oracle
|
||||
setattr(module, "USERNAME", TestEnv.USERNAME)
|
||||
setattr(module, "PASSWORD", TestEnv.PASSWORD)
|
||||
setattr(module, "TNSENTRY", TestEnv.TNSENTRY)
|
||||
setattr(module, "ARRAY_SIZE", TestEnv.ARRAY_SIZE)
|
||||
setattr(module, "TestCase", unittest.TestCase)
|
||||
setattr(module, "BaseTestCase", BaseTestCase)
|
||||
setattr(module, "cx_Oracle", cx_Oracle)
|
||||
exec(open(fileName).read(), module.__dict__)
|
||||
tests = loader.loadTestsFromModule(module)
|
||||
result = runner.run(tests)
|
||||
if not result.wasSuccessful():
|
||||
failures.append(name)
|
||||
if failures:
|
||||
print("***** Some tests in the following modules failed. *****")
|
||||
for name in failures:
|
||||
print(" %s" % name)
|
||||
sys.exit(1)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user