Rework build to use setuptools exclusively and enable use of pyproject.toml;

rework test suite to use tox and simplify test suite (also added a test number
to each test case for easier reference).
This commit is contained in:
Anthony Tuininga 2020-11-02 15:21:52 -07:00
parent 2194d81965
commit d242bc716d
36 changed files with 1065 additions and 1119 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
*.pyc *.pyc
.tox/
build/ build/
dist/ dist/
doc/build doc/build

View File

@ -7,7 +7,7 @@ of exclusions. See the
[homepage](https://oracle.github.io/python-cx_Oracle/index.html) for a [homepage](https://oracle.github.io/python-cx_Oracle/index.html) for a
feature list. feature list.
cx_Oracle 8 has been tested with Python versions 3.5 through 3.8. You can use cx_Oracle 8 has been tested with Python versions 3.6 through 3.9. You can use
cx_Oracle with Oracle 11.2, 12c, 18c and 19c client libraries. Oracle's cx_Oracle with Oracle 11.2, 12c, 18c and 19c client libraries. Oracle's
standard client-server version interoperability allows connection to both older standard client-server version interoperability allows connection to both older
and newer databases. For example Oracle 19c client libraries can connect to and newer databases. For example Oracle 19c client libraries can connect to

View File

@ -11,12 +11,18 @@ Version 8.1 (TBD)
#) Updated embedded ODPI-C to `version 4.1.0 #) Updated embedded ODPI-C to `version 4.1.0
<https://oracle.github.io/odpi/doc/releasenotes.html# <https://oracle.github.io/odpi/doc/releasenotes.html#
version-4-1-0-tbd>`__. version-4-1-0-tbd>`__.
#) Dropped support for Python 3.5. Added support for Python 3.9.
#) Added internal methods for getting/setting OCI attributes that are #) Added internal methods for getting/setting OCI attributes that are
otherwise not supported by cx_Oracle. These methods should only be used as otherwise not supported by cx_Oracle. These methods should only be used as
directed by Oracle. directed by Oracle.
#) Minor code improvement supplied by Alex Henrie #) Minor code improvement supplied by Alex Henrie
(`PR 472 <https://github.com/oracle/python-cx_Oracle/pull/472>`__). (`PR 472 <https://github.com/oracle/python-cx_Oracle/pull/472>`__).
#) Improved documentation. #) Builds are now done with setuptools and most metadata has moved from
`setup.py` to `setup.cfg` in order to take advantage of Python packaging
improvements.
#) Tests can now be run with tox in order to automate testing of the different
environments that are supported.
#) Improved documentation and test suite.
Version 8.0.1 (August 2020) Version 8.0.1 (August 2020)

3
pyproject.toml Normal file
View File

@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools >= 40.6.0", "wheel"]
build-backend = "setuptools.build_meta"

27
setup.cfg Normal file
View File

@ -0,0 +1,27 @@
[metadata]
name = cx_Oracle
description = Python interface to Oracle
long_description = file: README.md
long_description_content_type = text/markdown
keywords = Oracle, database
author = "Anthony Tuininga",
author_email = "anthony.tuininga@gmail.com",
license = BSD License
url = https://oracle.github.io/python-cx_Oracle
project_urls =
Installation = https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html
Samples = https://github.com/oracle/python-cx_Oracle/tree/master/samples
Documentation = http://cx-oracle.readthedocs.io
Release Notes = https://cx-oracle.readthedocs.io/en/latest/release_notes.html#releasenotes
Issues = https://github.com/oracle/python-cx_Oracle/issues
Source = https://github.com/oracle/python-cx_Oracle
python_requires = >=3.6
classifiers =
Development Status :: 6 - Mature
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Natural Language :: English
Operating System :: OS Independent
Programming Language :: C
Programming Language :: Python :: 3 :: Only
Topic :: Database

View File

@ -1,4 +1,4 @@
"""Distutils script for cx_Oracle. """Setup script for cx_Oracle.
Windows platforms: Windows platforms:
python setup.py build --compiler=mingw32 install python setup.py build --compiler=mingw32 install
@ -8,21 +8,18 @@ Unix platforms
""" """
import distutils.core
import os import os
import pkg_resources
import setuptools
import sys import sys
# check minimum supported Python version # check minimum supported Python version
if sys.version_info[:2] < (3, 5): if sys.version_info[:2] < (3, 6):
raise Exception("Python 3.5 or higher is required. " + raise Exception("Python 3.6 or higher is required. " +
"For python 2, use 'pip install cx_Oracle==7.3'") "For python 2, use 'pip install cx_Oracle==7.3'")
# if setuptools is detected, use it to add support for eggs # check minimum supported version of setuptools
try: pkg_resources.require("setuptools>=40.6.0")
from setuptools import setup, Extension
except:
from distutils.core import setup
from distutils.extension import Extension
# define build constants # define build constants
BUILD_VERSION = "8.1.0-dev" BUILD_VERSION = "8.1.0-dev"
@ -39,43 +36,12 @@ elif sys.platform == "cygwin":
elif sys.platform == "darwin": elif sys.platform == "darwin":
extraLinkArgs.append("-shared-libgcc") extraLinkArgs.append("-shared-libgcc")
class test(distutils.core.Command):
description = "run the test suite for the extension"
user_options = []
def finalize_options(self):
pass
def initialize_options(self):
pass
def run(self):
self.run_command("build")
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))
fileName = os.path.join("test", "test.py")
exec(open(fileName).read())
# define classifiers for the package index
classifiers = [
"Development Status :: 6 - Mature",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: C",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Database"
]
# define cx_Oracle sources # define cx_Oracle sources
sourceDir = "src" sourceDir = "src"
sources = [os.path.join(sourceDir, n) \ sources = [os.path.join(sourceDir, n) \
for n in sorted(os.listdir(sourceDir)) if n.endswith(".c")] for n in sorted(os.listdir(sourceDir)) if n.endswith(".c")]
depends = ["src/cxoModule.h"] depends = ["src/cxoModule.h"]
# define ODPI-C sources, libraries and include directories; if the environment # define ODPI-C sources, libraries and include directories; if the environment
# variables ODPIC_INC_DIR and ODPIC_LIB_DIR are both set, assume these # variables ODPIC_INC_DIR and ODPIC_LIB_DIR are both set, assume these
# locations contain a compiled installation of ODPI-C; otherwise, use the # locations contain a compiled installation of ODPI-C; otherwise, use the
@ -98,7 +64,7 @@ else:
libraryDirs = [] libraryDirs = []
# setup the extension # setup the extension
extension = Extension( extension = setuptools.Extension(
name = "cx_Oracle", name = "cx_Oracle",
include_dirs = includeDirs, include_dirs = includeDirs,
extra_compile_args = extraCompileArgs, extra_compile_args = extraCompileArgs,
@ -110,22 +76,7 @@ extension = Extension(
library_dirs = libraryDirs) library_dirs = libraryDirs)
# perform the setup # perform the setup
setup( setuptools.setup(
name = "cx_Oracle",
version = BUILD_VERSION, version = BUILD_VERSION,
description = "Python interface to Oracle",
cmdclass = dict(test = test),
data_files = [ ("cx_Oracle-doc", ["LICENSE.txt", "README.txt"]) ], data_files = [ ("cx_Oracle-doc", ["LICENSE.txt", "README.txt"]) ],
long_description = \ ext_modules = [extension])
"Python interface to Oracle Database conforming to the Python DB "
"API 2.0 specification.\n"
"See http://www.python.org/topics/database/DatabaseAPI-2.0.html.",
author = "Anthony Tuininga",
author_email = "anthony.tuininga@gmail.com",
url = "https://oracle.github.io/python-cx_Oracle",
python_requires = ">=3.5",
ext_modules = [extension],
keywords = "Oracle",
license = "BSD License",
classifiers = classifiers)

View File

@ -2,10 +2,10 @@ This directory contains the test suite for cx_Oracle.
1. The schemas and SQL objects that are referenced in the test suite can be 1. The schemas and SQL objects that are referenced in the test suite can be
created by running the Python script [SetupTest.py][1]. The script requires created by running the Python script [SetupTest.py][1]. The script requires
SYSDBA privileges and will prompt for these credentials as well as the administrative privileges and will prompt for these credentials as well as
names of the schemas that will be created, unless a number of environment the names of the schemas that will be created, unless a number of
variables are set as documented in the Python script [TestEnv.py][2]. Run environment variables are set as documented in the Python script
the script using the following command: [TestEnv.py][2]. Run the script using the following command:
python SetupTest.py python SetupTest.py
@ -13,23 +13,23 @@ This directory contains the test suite for cx_Oracle.
will always prompt for the names of the schemas that will be created. Run will always prompt for the names of the schemas that will be created. Run
the script using the following command: the script using the following command:
sqlplus sys/syspassword@hostname/servicename @sql/SetupTest.sql sqlplus system/systempassword@hostname/servicename @sql/SetupTest.sql
2. Run the test suite by issuing the following command in the top-level 2. Run the test suite by issuing the following command in the top-level
directory of your cx_Oracle installation: directory of your cx_Oracle installation:
python setup.py test tox
Alternatively, you can run the test suite directly within this directory: Alternatively, you can run the test suite directly within this directory:
python test.py python TestEnv.py
3. After running the test suite, the schemas can be dropped by running the 3. After running the test suite, the schemas can be dropped by running the
Python script [DropTest.py][4]. The script requires SYSDBA privileges and Python script [DropTest.py][4]. The script requires administrative
will prompt for these credentials as well as the names of the schemas privileges and will prompt for these credentials as well as the names of the
that will be dropped, unless a number of environment variables are set as schemas that will be dropped, unless a number of environment variables are
documented in the Python script [TestEnv.py][2]. Run the script using the set as documented in the Python script [TestEnv.py][2]. Run the script using
following command: the following command:
python DropTest.py python DropTest.py
@ -37,11 +37,10 @@ This directory contains the test suite for cx_Oracle.
will always prompt for the names of the schemas that will be dropped. Run will always prompt for the names of the schemas that will be dropped. Run
the script using the following command: the script using the following command:
sqlplus sys/syspassword@hostname/servicename @sql/DropTest.sql sqlplus system/systempassword@hostname/servicename @sql/DropTest.sql
[1]: https://github.com/oracle/python-cx_Oracle/blob/master/test/SetupTest.py [1]: https://github.com/oracle/python-cx_Oracle/blob/master/test/SetupTest.py
[2]: https://github.com/oracle/python-cx_Oracle/blob/master/test/TestEnv.py [2]: https://github.com/oracle/python-cx_Oracle/blob/master/test/TestEnv.py
[3]: https://github.com/oracle/python-cx_Oracle/blob/master/test/sql/SetupTest.sql [3]: https://github.com/oracle/python-cx_Oracle/blob/master/test/sql/SetupTest.sql
[4]: https://github.com/oracle/python-cx_Oracle/blob/master/test/DropTest.py [4]: https://github.com/oracle/python-cx_Oracle/blob/master/test/DropTest.py
[5]: https://github.com/oracle/python-cx_Oracle/blob/master/test/sql/DropTest.sql [5]: https://github.com/oracle/python-cx_Oracle/blob/master/test/sql/DropTest.sql

View File

@ -1,5 +1,5 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
# #
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -146,6 +146,14 @@ def RunSqlScript(conn, scriptName, **kwargs):
print(" %s/%s %s" % (lineNum, position, text)) print(" %s/%s %s" % (lineNum, position, text))
def RunTestCases(): def RunTestCases():
print("Running tests for cx_Oracle version", cx_Oracle.version,
"built at", cx_Oracle.buildtime)
print("File:", cx_Oracle.__file__)
print("Client Version:",
".".join(str(i) for i in cx_Oracle.clientversion()))
with GetConnection() as connection:
print("Server Version:", connection.version)
print()
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2)) unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
def GetConnection(**kwargs): def GetConnection(**kwargs):
@ -161,7 +169,32 @@ def GetPool(user=None, password=None, **kwargs):
encoding="UTF-8", nencoding="UTF-8", **kwargs) encoding="UTF-8", nencoding="UTF-8", **kwargs)
def GetClientVersion(): def GetClientVersion():
return cx_Oracle.clientversion() name = "CLIENT_VERSION"
value = PARAMETERS.get(name)
if value is None:
value = cx_Oracle.clientversion()[:2]
PARAMETERS[name] = value
return value
def GetServerVersion():
name = "SERVER_VERSION"
value = PARAMETERS.get(name)
if value is None:
conn = GetConnection()
value = tuple(int(s) for s in conn.version.split("."))[:2]
PARAMETERS[name] = value
return value
def SkipSodaTests():
client = GetClientVersion()
if client < (18, 3):
return True
server = GetServerVersion()
if server < (18, 0):
return True
if server > (20, 1) and client < (20, 1):
return True
return False
class RoundTripInfo: class RoundTripInfo:
@ -225,3 +258,9 @@ class BaseTestCase(unittest.TestCase):
del self.cursor del self.cursor
del self.connection del self.connection
def load_tests(loader, standard_tests, pattern):
return loader.discover(os.path.dirname(__file__))
if __name__ == "__main__":
RunTestCases()

View File

@ -1,77 +0,0 @@
#------------------------------------------------------------------------------
# Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
#
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
#
# Portions Copyright 2001-2007, Computronix (Canada) Ltd., Edmonton, Alberta,
# Canada. All rights reserved.
#------------------------------------------------------------------------------
"""Runs all defined unit tests."""
import cx_Oracle
import os
import sys
import TestEnv
import unittest
# display version of cx_Oracle and Oracle client for which tests are being run
print("Running tests for cx_Oracle version", cx_Oracle.version,
"built at", cx_Oracle.buildtime)
print("File:", cx_Oracle.__file__)
print("Client Version:", ".".join(str(i) for i in cx_Oracle.clientversion()))
sys.stdout.flush()
# verify that we can connect to the database and display database version
connection = TestEnv.GetConnection()
print("Server Version:", connection.version)
sys.stdout.flush()
# define test cases to run
moduleNames = [
"Module",
"Connection",
"Cursor",
"CursorVar",
"DateTimeVar",
"DbTypes",
"DMLReturning",
"Error",
"IntervalVar",
"LobVar",
"LongVar",
"NCharVar",
"NumberVar",
"ObjectVar",
"SessionPool",
"StringVar",
"TimestampVar",
"AQ",
"BulkAQ",
"Rowid",
"Subscription"
]
clientVersion = cx_Oracle.clientversion()
if clientVersion[:2] >= (12, 1):
moduleNames.append("BooleanVar")
moduleNames.append("Features12_1")
if clientVersion[:2] >= (18, 3):
moduleNames.append("SodaDatabase")
moduleNames.append("SodaCollection")
# run all test cases
failures = []
loader = unittest.TestLoader()
runner = unittest.TextTestRunner(verbosity = 2)
for name in moduleNames:
print()
print("Running tests in", name)
tests = loader.loadTestsFromName(name + ".TestCase")
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)

View File

@ -1,8 +1,10 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing module methods.""" """
1000 - Module for testing top-level module methods
"""
import TestEnv import TestEnv
@ -12,28 +14,28 @@ import time
class TestCase(TestEnv.BaseTestCase): class TestCase(TestEnv.BaseTestCase):
def testDateFromTicks(self): def test_1000_DateFromTicks(self):
"test DateFromTicks()" "1000 - test DateFromTicks()"
today = datetime.datetime.today() today = datetime.datetime.today()
timestamp = time.mktime(today.timetuple()) timestamp = time.mktime(today.timetuple())
date = cx_Oracle.DateFromTicks(timestamp) date = cx_Oracle.DateFromTicks(timestamp)
self.assertEqual(date, today.date()) self.assertEqual(date, today.date())
def testFutureObj(self): def test_1001_FutureObj(self):
"test management of __future__ object" "1001 - test management of __future__ object"
self.assertEqual(cx_Oracle.__future__.dummy, None) self.assertEqual(cx_Oracle.__future__.dummy, None)
cx_Oracle.__future__.dummy = "Unimportant" cx_Oracle.__future__.dummy = "Unimportant"
self.assertEqual(cx_Oracle.__future__.dummy, None) self.assertEqual(cx_Oracle.__future__.dummy, None)
def testTimestampFromTicks(self): def test_1002_TimestampFromTicks(self):
"test TimestampFromTicks()" "1002 - test TimestampFromTicks()"
timestamp = time.mktime(datetime.datetime.today().timetuple()) timestamp = time.mktime(datetime.datetime.today().timetuple())
today = datetime.datetime.fromtimestamp(timestamp) today = datetime.datetime.fromtimestamp(timestamp)
date = cx_Oracle.TimestampFromTicks(timestamp) date = cx_Oracle.TimestampFromTicks(timestamp)
self.assertEqual(date, today) self.assertEqual(date, today)
def testUnsupportedFunctions(self): def test_1003_UnsupportedFunctions(self):
"test unsupported time functions" "1003 - test unsupported time functions"
self.assertRaises(cx_Oracle.NotSupportedError, cx_Oracle.Time, self.assertRaises(cx_Oracle.NotSupportedError, cx_Oracle.Time,
12, 0, 0) 12, 0, 0)
self.assertRaises(cx_Oracle.NotSupportedError, cx_Oracle.TimeFromTicks, self.assertRaises(cx_Oracle.NotSupportedError, cx_Oracle.TimeFromTicks,
@ -41,4 +43,3 @@ class TestCase(TestEnv.BaseTestCase):
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -1,5 +1,5 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
# #
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -7,7 +7,9 @@
# Canada. All rights reserved. # Canada. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing connections.""" """
1100 - Module for testing connections
"""
import TestEnv import TestEnv
@ -22,7 +24,7 @@ class TestCase(TestEnv.BaseTestCase):
"""Connect to the database, perform a query and drop the connection.""" """Connect to the database, perform a query and drop the connection."""
connection = TestEnv.GetConnection(threaded=True) connection = TestEnv.GetConnection(threaded=True)
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute(u"select count(*) from TestNumbers") cursor.execute("select count(*) from TestNumbers")
count, = cursor.fetchone() count, = cursor.fetchone()
self.assertEqual(count, 10) self.assertEqual(count, 10)
@ -47,13 +49,13 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(connection.dsn, TestEnv.GetConnectString(), self.assertEqual(connection.dsn, TestEnv.GetConnectString(),
"dsn differs") "dsn differs")
def testAllArgs(self): def test_1100_AllArgs(self):
"connection to database with user, password, TNS separate" "1100 - connection to database with user, password, TNS separate"
connection = TestEnv.GetConnection() connection = TestEnv.GetConnection()
self.verifyArgs(connection) self.verifyArgs(connection)
def testAppContext(self): def test_1101_AppContext(self):
"test use of application context" "1101 - test use of application context"
namespace = "CLIENTCONTEXT" namespace = "CLIENTCONTEXT"
appContextEntries = [ appContextEntries = [
( namespace, "ATTR1", "VALUE1" ), ( namespace, "ATTR1", "VALUE1" ),
@ -68,14 +70,14 @@ class TestCase(TestEnv.BaseTestCase):
actualValue, = cursor.fetchone() actualValue, = cursor.fetchone()
self.assertEqual(actualValue, value) self.assertEqual(actualValue, value)
def testAppContextNegative(self): def test_1102_AppContextNegative(self):
"test invalid use of application context" "1102 - test invalid use of application context"
self.assertRaises(TypeError, cx_Oracle.connect, TestEnv.GetMainUser(), self.assertRaises(TypeError, cx_Oracle.connect, TestEnv.GetMainUser(),
TestEnv.GetMainPassword(), TestEnv.GetConnectString(), TestEnv.GetMainPassword(), TestEnv.GetConnectString(),
appcontext=[('userenv', 'action')]) appcontext=[('userenv', 'action')])
def testAttributes(self): def test_1103_Attributes(self):
"test connection end-to-end tracing attributes" "1103 - test connection end-to-end tracing attributes"
connection = TestEnv.GetConnection() connection = TestEnv.GetConnection()
if TestEnv.GetClientVersion() >= (12, 1) \ if TestEnv.GetClientVersion() >= (12, 1) \
and not self.isOnOracleCloud(connection): and not self.isOnOracleCloud(connection):
@ -94,8 +96,8 @@ class TestCase(TestEnv.BaseTestCase):
"cx_OracleTest_CID", "cx_OracleTest_CID",
"select sys_context('userenv', 'client_identifier') from dual") "select sys_context('userenv', 'client_identifier') from dual")
def testAutoCommit(self): def test_1104_AutoCommit(self):
"test use of autocommit" "1104 - test use of autocommit"
connection = TestEnv.GetConnection() connection = TestEnv.GetConnection()
cursor = connection.cursor() cursor = connection.cursor()
otherConnection = TestEnv.GetConnection() otherConnection = TestEnv.GetConnection()
@ -111,24 +113,24 @@ class TestCase(TestEnv.BaseTestCase):
rows = otherCursor.fetchall() rows = otherCursor.fetchall()
self.assertEqual(rows, [(1,), (2,)]) self.assertEqual(rows, [(1,), (2,)])
def testBadConnectString(self): def test_1105_BadConnectString(self):
"connection to database with bad connect string" "1105 - connection to database with bad connect string"
self.assertRaises(cx_Oracle.DatabaseError, cx_Oracle.connect, self.assertRaises(cx_Oracle.DatabaseError, cx_Oracle.connect,
TestEnv.GetMainUser()) TestEnv.GetMainUser())
self.assertRaises(cx_Oracle.DatabaseError, cx_Oracle.connect, self.assertRaises(cx_Oracle.DatabaseError, cx_Oracle.connect,
TestEnv.GetMainUser() + u"@" + TestEnv.GetConnectString()) TestEnv.GetMainUser() + "@" + TestEnv.GetConnectString())
self.assertRaises(cx_Oracle.DatabaseError, cx_Oracle.connect, self.assertRaises(cx_Oracle.DatabaseError, cx_Oracle.connect,
TestEnv.GetMainUser() + "@" + \ TestEnv.GetMainUser() + "@" + \
TestEnv.GetConnectString() + "/" + TestEnv.GetMainPassword()) TestEnv.GetConnectString() + "/" + TestEnv.GetMainPassword())
def testBadPassword(self): def test_1106_BadPassword(self):
"connection to database with bad password" "1106 - connection to database with bad password"
self.assertRaises(cx_Oracle.DatabaseError, cx_Oracle.connect, self.assertRaises(cx_Oracle.DatabaseError, cx_Oracle.connect,
TestEnv.GetMainUser(), TestEnv.GetMainPassword() + "X", TestEnv.GetMainUser(), TestEnv.GetMainPassword() + "X",
TestEnv.GetConnectString()) TestEnv.GetConnectString())
def testChangePassword(self): def test_1107_ChangePassword(self):
"test changing password" "1107 - test changing password"
connection = TestEnv.GetConnection() connection = TestEnv.GetConnection()
if self.isOnOracleCloud(connection): if self.isOnOracleCloud(connection):
self.skipTest("passwords on Oracle Cloud are strictly controlled") self.skipTest("passwords on Oracle Cloud are strictly controlled")
@ -140,8 +142,8 @@ class TestCase(TestEnv.BaseTestCase):
TestEnv.GetConnectString()) TestEnv.GetConnectString())
connection.changepassword(newPassword, TestEnv.GetMainPassword()) connection.changepassword(newPassword, TestEnv.GetMainPassword())
def testChangePasswordNegative(self): def test_1108_ChangePasswordNegative(self):
"test changing password to an invalid value" "1108 - test changing password to an invalid value"
connection = TestEnv.GetConnection() connection = TestEnv.GetConnection()
if self.isOnOracleCloud(connection): if self.isOnOracleCloud(connection):
self.skipTest("passwords on Oracle Cloud are strictly controlled") self.skipTest("passwords on Oracle Cloud are strictly controlled")
@ -149,8 +151,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertRaises(cx_Oracle.DatabaseError, connection.changepassword, self.assertRaises(cx_Oracle.DatabaseError, connection.changepassword,
TestEnv.GetMainPassword(), newPassword) TestEnv.GetMainPassword(), newPassword)
def testParsePassword(self): def test_1109_ParsePassword(self):
"test connecting with password containing / and @ symbols" "1109 - test connecting with password containing / and @ symbols"
connection = TestEnv.GetConnection() connection = TestEnv.GetConnection()
if self.isOnOracleCloud(connection): if self.isOnOracleCloud(connection):
self.skipTest("passwords on Oracle Cloud are strictly controlled") self.skipTest("passwords on Oracle Cloud are strictly controlled")
@ -167,8 +169,8 @@ class TestCase(TestEnv.BaseTestCase):
finally: finally:
connection.changepassword(newPassword, TestEnv.GetMainPassword()) connection.changepassword(newPassword, TestEnv.GetMainPassword())
def testEncodings(self): def test_1110_Encodings(self):
"connection with only encoding or nencoding specified should work" "1110 - connection with only encoding/nencoding specified should work"
connection = cx_Oracle.connect(TestEnv.GetMainUser(), connection = cx_Oracle.connect(TestEnv.GetMainUser(),
TestEnv.GetMainPassword(), TestEnv.GetConnectString()) TestEnv.GetMainPassword(), TestEnv.GetConnectString())
encoding = connection.encoding encoding = connection.encoding
@ -185,11 +187,12 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(connection.encoding, encoding) self.assertEqual(connection.encoding, encoding)
self.assertEqual(connection.nencoding, altEncoding) self.assertEqual(connection.nencoding, altEncoding)
def testDifferentEncodings(self): def test_1111_DifferentEncodings(self):
"1111 - different encodings can be specified for encoding/nencoding"
connection = cx_Oracle.connect(TestEnv.GetMainUser(), connection = cx_Oracle.connect(TestEnv.GetMainUser(),
TestEnv.GetMainPassword(), TestEnv.GetConnectString(), TestEnv.GetMainPassword(), TestEnv.GetConnectString(),
encoding="UTF-8", nencoding="UTF-16") encoding="UTF-8", nencoding="UTF-16")
value = u"\u03b4\u4e2a" value = "\u03b4\u4e2a"
cursor = connection.cursor() cursor = connection.cursor()
ncharVar = cursor.var(cx_Oracle.DB_TYPE_NVARCHAR, 100) ncharVar = cursor.var(cx_Oracle.DB_TYPE_NVARCHAR, 100)
ncharVar.setvalue(0, value) ncharVar.setvalue(0, value)
@ -197,14 +200,14 @@ class TestCase(TestEnv.BaseTestCase):
result, = cursor.fetchone() result, = cursor.fetchone()
self.assertEqual(result, value) self.assertEqual(result, value)
def testExceptionOnClose(self): def test_1112_ExceptionOnClose(self):
"confirm an exception is raised after closing a connection" "1112 - confirm an exception is raised after closing a connection"
connection = TestEnv.GetConnection() connection = TestEnv.GetConnection()
connection.close() connection.close()
self.assertRaises(cx_Oracle.InterfaceError, connection.rollback) self.assertRaises(cx_Oracle.InterfaceError, connection.rollback)
def testConnectWithHandle(self): def test_1113_ConnectWithHandle(self):
"test creating a connection using a handle" "1113 - test creating a connection using a handle"
connection = TestEnv.GetConnection() connection = TestEnv.GetConnection()
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("truncate table TestTempTable") cursor.execute("truncate table TestTempTable")
@ -224,31 +227,28 @@ class TestCase(TestEnv.BaseTestCase):
self.assertRaises(cx_Oracle.DatabaseError, cursor.execute, self.assertRaises(cx_Oracle.DatabaseError, cursor.execute,
"select count(*) from TestTempTable") "select count(*) from TestTempTable")
def testMakeDSN(self): def test_1114_MakeDSN(self):
"test making a data source name from host, port and sid" "1114 - test making a data source name from host, port and sid"
formatString = u"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)" + \ formatString = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)" + \
"(HOST=%s)(PORT=%d))(CONNECT_DATA=(SID=%s)))" "(HOST=%s)(PORT=%d))(CONNECT_DATA=(SID=%s)))"
args = ("hostname", 1521, "TEST") args = ("hostname", 1521, "TEST")
result = cx_Oracle.makedsn(*args) result = cx_Oracle.makedsn(*args)
self.assertEqual(result, formatString % args) self.assertEqual(result, formatString % args)
args = (u"hostname", 1521, u"TEST")
result = cx_Oracle.makedsn(*args)
self.assertEqual(result, formatString % args)
def testSingleArg(self): def test_1115_SingleArg(self):
"connection to database with user, password, DSN together" "1115 - connection to database with user, password, DSN together"
connection = cx_Oracle.connect("%s/%s@%s" % \ connection = cx_Oracle.connect("%s/%s@%s" % \
(TestEnv.GetMainUser(), TestEnv.GetMainPassword(), (TestEnv.GetMainUser(), TestEnv.GetMainPassword(),
TestEnv.GetConnectString())) TestEnv.GetConnectString()))
self.verifyArgs(connection) self.verifyArgs(connection)
def testVersion(self): def test_1116_Version(self):
"connection version is a string" "1116 - connection version is a string"
connection = TestEnv.GetConnection() connection = TestEnv.GetConnection()
self.assertTrue(isinstance(connection.version, str)) self.assertTrue(isinstance(connection.version, str))
def testRollbackOnClose(self): def test_1117_RollbackOnClose(self):
"connection rolls back before close" "1117 - connection rolls back before close"
connection = TestEnv.GetConnection() connection = TestEnv.GetConnection()
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("truncate table TestTempTable") cursor.execute("truncate table TestTempTable")
@ -261,8 +261,8 @@ class TestCase(TestEnv.BaseTestCase):
count, = cursor.fetchone() count, = cursor.fetchone()
self.assertEqual(count, 0) self.assertEqual(count, 0)
def testRollbackOnDel(self): def test_1118_RollbackOnDel(self):
"connection rolls back before destruction" "1118 - connection rolls back before destruction"
connection = TestEnv.GetConnection() connection = TestEnv.GetConnection()
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("truncate table TestTempTable") cursor.execute("truncate table TestTempTable")
@ -275,8 +275,8 @@ class TestCase(TestEnv.BaseTestCase):
count, = cursor.fetchone() count, = cursor.fetchone()
self.assertEqual(count, 0) self.assertEqual(count, 0)
def testThreading(self): def test_1119_Threading(self):
"connection to database with multiple threads" "1119 - connection to database with multiple threads"
threads = [] threads = []
for i in range(20): for i in range(20):
thread = threading.Thread(None, self.__ConnectAndDrop) thread = threading.Thread(None, self.__ConnectAndDrop)
@ -285,15 +285,15 @@ class TestCase(TestEnv.BaseTestCase):
for thread in threads: for thread in threads:
thread.join() thread.join()
def testStringFormat(self): def test_1120_StringFormat(self):
"test string format of connection" "1120 - test string format of connection"
connection = TestEnv.GetConnection() connection = TestEnv.GetConnection()
expectedValue = "<cx_Oracle.Connection to %s@%s>" % \ expectedValue = "<cx_Oracle.Connection to %s@%s>" % \
(TestEnv.GetMainUser(), TestEnv.GetConnectString()) (TestEnv.GetMainUser(), TestEnv.GetConnectString())
self.assertEqual(str(connection), expectedValue) self.assertEqual(str(connection), expectedValue)
def testCtxMgrClose(self): def test_1121_CtxMgrClose(self):
"test context manager - close" "1121 - test context manager - close"
connection = TestEnv.GetConnection() connection = TestEnv.GetConnection()
with connection: with connection:
cursor = connection.cursor() cursor = connection.cursor()
@ -308,8 +308,8 @@ class TestCase(TestEnv.BaseTestCase):
count, = cursor.fetchone() count, = cursor.fetchone()
self.assertEqual(count, 1) self.assertEqual(count, 1)
def testConnectionAttributes(self): def test_1122_ConnectionAttributes(self):
"test connection attribute values" "1122 - test connection attribute values"
connection = cx_Oracle.connect(TestEnv.GetMainUser(), connection = cx_Oracle.connect(TestEnv.GetMainUser(),
TestEnv.GetMainPassword(), TestEnv.GetConnectString(), TestEnv.GetMainPassword(), TestEnv.GetConnectString(),
encoding="ASCII") encoding="ASCII")
@ -333,8 +333,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertRaises(TypeError, connection.stmtcachesize, 20.5) self.assertRaises(TypeError, connection.stmtcachesize, 20.5)
self.assertRaises(TypeError, connection.stmtcachesize, "value") self.assertRaises(TypeError, connection.stmtcachesize, "value")
def testClosedConnectionAttributes(self): def test_1123_ClosedConnectionAttributes(self):
"test closed connection attribute values" "1123 - test closed connection attribute values"
connection = TestEnv.GetConnection() connection = TestEnv.GetConnection()
connection.close() connection.close()
attrNames = ["current_schema", "edition", "external_name", attrNames = ["current_schema", "edition", "external_name",
@ -345,13 +345,13 @@ class TestCase(TestEnv.BaseTestCase):
self.assertRaises(cx_Oracle.InterfaceError, getattr, connection, self.assertRaises(cx_Oracle.InterfaceError, getattr, connection,
name) name)
def testPing(self): def test_1124_Ping(self):
"test connection ping" "1124 - test connection ping"
connection = TestEnv.GetConnection() connection = TestEnv.GetConnection()
connection.ping() connection.ping()
def testTransactionBegin(self): def test_1125_TransactionBegin(self):
"test begin, prepare, cancel transaction" "1125 - test begin, prepare, cancel transaction"
connection = TestEnv.GetConnection() connection = TestEnv.GetConnection()
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("truncate table TestTempTable") cursor.execute("truncate table TestTempTable")
@ -370,4 +370,3 @@ class TestCase(TestEnv.BaseTestCase):
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -1,5 +1,5 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
# #
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -7,7 +7,9 @@
# Canada. All rights reserved. # Canada. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing cursor objects.""" """
1200 - Module for testing cursors
"""
import TestEnv import TestEnv
@ -17,8 +19,8 @@ import sys
class TestCase(TestEnv.BaseTestCase): class TestCase(TestEnv.BaseTestCase):
def testCreateScrollableCursor(self): def test_1200_CreateScrollableCursor(self):
"""test creating a scrollable cursor""" "1200 - test creating a scrollable cursor"
cursor = self.connection.cursor() cursor = self.connection.cursor()
self.assertEqual(cursor.scrollable, False) self.assertEqual(cursor.scrollable, False)
cursor = self.connection.cursor(True) cursor = self.connection.cursor(True)
@ -28,18 +30,18 @@ class TestCase(TestEnv.BaseTestCase):
cursor.scrollable = False cursor.scrollable = False
self.assertEqual(cursor.scrollable, False) self.assertEqual(cursor.scrollable, False)
def testExecuteNoArgs(self): def test_1201_ExecuteNoArgs(self):
"""test executing a statement without any arguments""" "1201 - test executing a statement without any arguments"
result = self.cursor.execute("begin null; end;") result = self.cursor.execute("begin null; end;")
self.assertEqual(result, None) self.assertEqual(result, None)
def testExecuteNoStatementWithArgs(self): def test_1202_ExecuteNoStatementWithArgs(self):
"""test executing a None statement with bind variables""" "1202 - test executing a None statement with bind variables"
self.assertRaises(cx_Oracle.ProgrammingError, self.cursor.execute, self.assertRaises(cx_Oracle.ProgrammingError, self.cursor.execute,
None, x = 5) None, x = 5)
def testExecuteEmptyKeywordArgs(self): def test_1203_ExecuteEmptyKeywordArgs(self):
"""test executing a statement with args and empty keyword args""" "1203 - test executing a statement with args and empty keyword args"
simpleVar = self.cursor.var(cx_Oracle.NUMBER) simpleVar = self.cursor.var(cx_Oracle.NUMBER)
args = [simpleVar] args = [simpleVar]
kwArgs = {} kwArgs = {}
@ -47,47 +49,43 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(result, None) self.assertEqual(result, None)
self.assertEqual(simpleVar.getvalue(), 25) self.assertEqual(simpleVar.getvalue(), 25)
def testExecuteKeywordArgs(self): def test_1204_ExecuteKeywordArgs(self):
"""test executing a statement with keyword arguments""" "1204 - test executing a statement with keyword arguments"
simpleVar = self.cursor.var(cx_Oracle.NUMBER) simpleVar = self.cursor.var(cx_Oracle.NUMBER)
result = self.cursor.execute("begin :value := 5; end;", result = self.cursor.execute("begin :value := 5; end;",
value = simpleVar) value = simpleVar)
self.assertEqual(result, None) self.assertEqual(result, None)
self.assertEqual(simpleVar.getvalue(), 5) self.assertEqual(simpleVar.getvalue(), 5)
def testExecuteDictionaryArg(self): def test_1205_ExecuteDictionaryArg(self):
"""test executing a statement with a dictionary argument""" "1205 - test executing a statement with a dictionary argument"
simpleVar = self.cursor.var(cx_Oracle.NUMBER) simpleVar = self.cursor.var(cx_Oracle.NUMBER)
dictArg = { "value" : simpleVar } dictArg = { "value" : simpleVar }
result = self.cursor.execute("begin :value := 10; end;", dictArg) result = self.cursor.execute("begin :value := 10; end;", dictArg)
self.assertEqual(result, None) self.assertEqual(result, None)
self.assertEqual(simpleVar.getvalue(), 10) self.assertEqual(simpleVar.getvalue(), 10)
dictArg = { u"value" : simpleVar }
result = self.cursor.execute("begin :value := 25; end;", dictArg)
self.assertEqual(result, None)
self.assertEqual(simpleVar.getvalue(), 25)
def testExecuteMultipleMethod(self): def test_1206_ExecuteMultipleMethod(self):
"""test executing a statement with both a dict arg and keyword args""" "1206 - test executing a statement with both a dict and keyword args"
simpleVar = self.cursor.var(cx_Oracle.NUMBER) simpleVar = self.cursor.var(cx_Oracle.NUMBER)
dictArg = { "value" : simpleVar } dictArg = { "value" : simpleVar }
self.assertRaises(cx_Oracle.InterfaceError, self.cursor.execute, self.assertRaises(cx_Oracle.InterfaceError, self.cursor.execute,
"begin :value := 15; end;", dictArg, value = simpleVar) "begin :value := 15; end;", dictArg, value = simpleVar)
def testExecuteAndModifyArraySize(self): def test_1207_ExecuteAndModifyArraySize(self):
"""test executing a statement and then changing the array size""" "1207 - test executing a statement and then changing the array size"
self.cursor.execute("select IntCol from TestNumbers") self.cursor.execute("select IntCol from TestNumbers")
self.cursor.arraysize = 20 self.cursor.arraysize = 20
self.assertEqual(len(self.cursor.fetchall()), 10) self.assertEqual(len(self.cursor.fetchall()), 10)
def testCallProc(self): def test_1208_CallProc(self):
"""test executing a stored procedure""" "1208 - test executing a stored procedure"
var = self.cursor.var(cx_Oracle.NUMBER) var = self.cursor.var(cx_Oracle.NUMBER)
results = self.cursor.callproc("proc_Test", ("hi", 5, var)) results = self.cursor.callproc("proc_Test", ("hi", 5, var))
self.assertEqual(results, ["hi", 10, 2.0]) self.assertEqual(results, ["hi", 10, 2.0])
def testCallProcAllKeywords(self): def test_1209_CallProcAllKeywords(self):
"test executing a stored procedure with args in keywordParameters" "1209 - test executing a stored procedure with keyword args"
kwargs = dict(a_InOutValue=self.cursor.var(cx_Oracle.NUMBER), kwargs = dict(a_InOutValue=self.cursor.var(cx_Oracle.NUMBER),
a_InValue="hi", a_OutValue=self.cursor.var(cx_Oracle.NUMBER)) a_InValue="hi", a_OutValue=self.cursor.var(cx_Oracle.NUMBER))
kwargs['a_InOutValue'].setvalue(0, 5) kwargs['a_InOutValue'].setvalue(0, 5)
@ -96,38 +94,38 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(kwargs['a_InOutValue'].getvalue(), 10) self.assertEqual(kwargs['a_InOutValue'].getvalue(), 10)
self.assertEqual(kwargs['a_OutValue'].getvalue(), 2.0) self.assertEqual(kwargs['a_OutValue'].getvalue(), 2.0)
def testCallProcOnlyLastKeyword(self): def test_1210_CallProcOnlyLastKeyword(self):
"test executing a stored procedure with last arg in keywordParameters" "1210 - test executing a stored procedure with last arg as keyword arg"
kwargs = dict(a_OutValue = self.cursor.var(cx_Oracle.NUMBER)) kwargs = dict(a_OutValue = self.cursor.var(cx_Oracle.NUMBER))
results = self.cursor.callproc("proc_Test", ("hi", 5), kwargs) results = self.cursor.callproc("proc_Test", ("hi", 5), kwargs)
self.assertEqual(results, ["hi", 10]) self.assertEqual(results, ["hi", 10])
self.assertEqual(kwargs['a_OutValue'].getvalue(), 2.0) self.assertEqual(kwargs['a_OutValue'].getvalue(), 2.0)
def testCallProcRepeatedKeywordParameters(self): def test_1211_CallProcRepeatedKeywordParameters(self):
"test executing a stored procedure, repeated arg in keywordParameters" "1211 - test executing a stored procedure, repeated keyword arg"
kwargs = dict(a_InValue="hi", kwargs = dict(a_InValue="hi",
a_OutValue=self.cursor.var(cx_Oracle.NUMBER)) a_OutValue=self.cursor.var(cx_Oracle.NUMBER))
self.assertRaises(cx_Oracle.DatabaseError, self.cursor.callproc, self.assertRaises(cx_Oracle.DatabaseError, self.cursor.callproc,
"proc_Test", parameters=("hi", 5), keywordParameters=kwargs) "proc_Test", parameters=("hi", 5), keywordParameters=kwargs)
def testCallProcNoArgs(self): def test_1212_CallProcNoArgs(self):
"""test executing a stored procedure without any arguments""" "1212 - test executing a stored procedure without any arguments"
results = self.cursor.callproc(u"proc_TestNoArgs") results = self.cursor.callproc("proc_TestNoArgs")
self.assertEqual(results, []) self.assertEqual(results, [])
def testCallFunc(self): def test_1213_CallFunc(self):
"""test executing a stored function""" "1213 - test executing a stored function"
results = self.cursor.callfunc(u"func_Test", cx_Oracle.NUMBER, results = self.cursor.callfunc("func_Test", cx_Oracle.NUMBER,
(u"hi", 5)) ("hi", 5))
self.assertEqual(results, 7) self.assertEqual(results, 7)
def testCallFuncNoArgs(self): def test_1214_CallFuncNoArgs(self):
"""test executing a stored function without any arguments""" "1214 - test executing a stored function without any arguments"
results = self.cursor.callfunc("func_TestNoArgs", cx_Oracle.NUMBER) results = self.cursor.callfunc("func_TestNoArgs", cx_Oracle.NUMBER)
self.assertEqual(results, 712) self.assertEqual(results, 712)
def testCallFuncNegative(self): def test_1215_CallFuncNegative(self):
"""test executing a stored function with wrong parameters""" "1215 - test executing a stored function with wrong parameters"
funcName = "func_Test" funcName = "func_Test"
self.assertRaises(TypeError, self.cursor.callfunc, cx_Oracle.NUMBER, self.assertRaises(TypeError, self.cursor.callfunc, cx_Oracle.NUMBER,
funcName, ("hi", 5)) funcName, ("hi", 5))
@ -142,10 +140,10 @@ class TestCase(TestEnv.BaseTestCase):
self.assertRaises(TypeError, self.cursor.callfunc, funcName, self.assertRaises(TypeError, self.cursor.callfunc, funcName,
cx_Oracle.NUMBER, 5) cx_Oracle.NUMBER, 5)
def testExecuteManyByName(self): def test_1216_ExecuteManyByName(self):
"""test executing a statement multiple times (named args)""" "1216 - test executing a statement multiple times (named args)"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
rows = [ { u"value" : n } for n in range(250) ] rows = [ { "value" : n } for n in range(250) ]
self.cursor.arraysize = 100 self.cursor.arraysize = 100
statement = "insert into TestTempTable (IntCol) values (:value)" statement = "insert into TestTempTable (IntCol) values (:value)"
self.cursor.executemany(statement, rows) self.cursor.executemany(statement, rows)
@ -154,8 +152,8 @@ class TestCase(TestEnv.BaseTestCase):
count, = self.cursor.fetchone() count, = self.cursor.fetchone()
self.assertEqual(count, len(rows)) self.assertEqual(count, len(rows))
def testExecuteManyByPosition(self): def test_1217_ExecuteManyByPosition(self):
"""test executing a statement multiple times (positional args)""" "1217 - test executing a statement multiple times (positional args)"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
rows = [ [n] for n in range(230) ] rows = [ [n] for n in range(230) ]
self.cursor.arraysize = 100 self.cursor.arraysize = 100
@ -166,8 +164,8 @@ class TestCase(TestEnv.BaseTestCase):
count, = self.cursor.fetchone() count, = self.cursor.fetchone()
self.assertEqual(count, len(rows)) self.assertEqual(count, len(rows))
def testExecuteManyWithPrepare(self): def test_1218_ExecuteManyWithPrepare(self):
"""test executing a statement multiple times (with prepare)""" "1218 - test executing a statement multiple times (with prepare)"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
rows = [ [n] for n in range(225) ] rows = [ [n] for n in range(225) ]
self.cursor.arraysize = 100 self.cursor.arraysize = 100
@ -179,8 +177,8 @@ class TestCase(TestEnv.BaseTestCase):
count, = self.cursor.fetchone() count, = self.cursor.fetchone()
self.assertEqual(count, len(rows)) self.assertEqual(count, len(rows))
def testExecuteManyWithRebind(self): def test_1219_ExecuteManyWithRebind(self):
"""test executing a statement multiple times (with rebind)""" "1219 - test executing a statement multiple times (with rebind)"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
rows = [ [n] for n in range(235) ] rows = [ [n] for n in range(235) ]
self.cursor.arraysize = 100 self.cursor.arraysize = 100
@ -192,22 +190,22 @@ class TestCase(TestEnv.BaseTestCase):
count, = self.cursor.fetchone() count, = self.cursor.fetchone()
self.assertEqual(count, len(rows)) self.assertEqual(count, len(rows))
def testExecuteManyWithInputSizesWrong(self): def test_1220_ExecuteManyWithInputSizesWrong(self):
"test executing a statement multiple times (with input sizes wrong)" "1220 - test executing multiple times (with input sizes wrong)"
cursor = self.connection.cursor() cursor = self.connection.cursor()
cursor.setinputsizes(cx_Oracle.NUMBER) cursor.setinputsizes(cx_Oracle.NUMBER)
data = [[decimal.Decimal("25.8")], [decimal.Decimal("30.0")]] data = [[decimal.Decimal("25.8")], [decimal.Decimal("30.0")]]
cursor.executemany("declare t number; begin t := :1; end;", data) cursor.executemany("declare t number; begin t := :1; end;", data)
def testExecuteManyMultipleBatches(self): def test_1221_ExecuteManyMultipleBatches(self):
"test executing a statement multiple times (with multiple batches)" "1221 - test executing multiple times (with multiple batches)"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
sql = "insert into TestTempTable (IntCol, StringCol) values (:1, :2)" sql = "insert into TestTempTable (IntCol, StringCol) values (:1, :2)"
self.cursor.executemany(sql, [(1, None), (2, None)]) self.cursor.executemany(sql, [(1, None), (2, None)])
self.cursor.executemany(sql, [(3, None), (4, "Testing")]) self.cursor.executemany(sql, [(3, None), (4, "Testing")])
def testExecuteManyNumeric(self): def test_1222_ExecuteManyNumeric(self):
"test executemany() with various numeric types" "1222 - test executemany() with various numeric types"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
data = [(1, 5), (2, 7.0), (3, 6.5), (4, 2 ** 65), data = [(1, 5), (2, 7.0), (3, 6.5), (4, 2 ** 65),
(5, decimal.Decimal("24.5"))] (5, decimal.Decimal("24.5"))]
@ -219,8 +217,8 @@ class TestCase(TestEnv.BaseTestCase):
order by IntCol""") order by IntCol""")
self.assertEqual(self.cursor.fetchall(), data) self.assertEqual(self.cursor.fetchall(), data)
def testExecuteManyWithResize(self): def test_1223_ExecuteManyWithResize(self):
"""test executing a statement multiple times (with resize)""" "1223 - test executing a statement multiple times (with resize)"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
rows = [ ( 1, "First" ), rows = [ ( 1, "First" ),
( 2, "Second" ), ( 2, "Second" ),
@ -238,8 +236,8 @@ class TestCase(TestEnv.BaseTestCase):
fetchedRows = self.cursor.fetchall() fetchedRows = self.cursor.fetchall()
self.assertEqual(fetchedRows, rows) self.assertEqual(fetchedRows, rows)
def testExecuteManyWithExecption(self): def test_1224_ExecuteManyWithExecption(self):
"""test executing a statement multiple times (with exception)""" "1224 - test executing a statement multiple times (with exception)"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
rows = [ { "value" : n } for n in (1, 2, 3, 2, 5) ] rows = [ { "value" : n } for n in (1, 2, 3, 2, 5) ]
statement = "insert into TestTempTable (IntCol) values (:value)" statement = "insert into TestTempTable (IntCol) values (:value)"
@ -247,14 +245,14 @@ class TestCase(TestEnv.BaseTestCase):
statement, rows) statement, rows)
self.assertEqual(self.cursor.rowcount, 3) self.assertEqual(self.cursor.rowcount, 3)
def testExecuteManyWithInvalidParameters(self): def test_1225_ExecuteManyWithInvalidParameters(self):
"test calling executemany() with invalid parameters" "1225 - test calling executemany() with invalid parameters"
self.assertRaises(TypeError, self.cursor.executemany, self.assertRaises(TypeError, self.cursor.executemany,
"insert into TestTempTable (IntCol, StringCol) values (:1, :2)", "insert into TestTempTable (IntCol, StringCol) values (:1, :2)",
"These are not valid parameters") "These are not valid parameters")
def testExecuteManyNoParameters(self): def test_1226_ExecuteManyNoParameters(self):
"test calling executemany() without any bind parameters" "1226 - test calling executemany() without any bind parameters"
numRows = 5 numRows = 5
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
self.cursor.executemany(""" self.cursor.executemany("""
@ -272,8 +270,8 @@ class TestCase(TestEnv.BaseTestCase):
count, = self.cursor.fetchone() count, = self.cursor.fetchone()
self.assertEqual(count, numRows) self.assertEqual(count, numRows)
def testExecuteManyBoundEarlier(self): def test_1227_ExecuteManyBoundEarlier(self):
"test calling executemany() with binds performed earlier" "1227 - test calling executemany() with binds performed earlier"
numRows = 9 numRows = 9
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
var = self.cursor.var(int, arraysize = numRows) var = self.cursor.var(int, arraysize = numRows)
@ -295,8 +293,8 @@ class TestCase(TestEnv.BaseTestCase):
expectedData = [1, 3, 6, 10, 15, 21, 28, 36, 45] expectedData = [1, 3, 6, 10, 15, 21, 28, 36, 45]
self.assertEqual(var.values, expectedData) self.assertEqual(var.values, expectedData)
def testPrepare(self): def test_1228_Prepare(self):
"""test preparing a statement and executing it multiple times""" "1228 - test preparing a statement and executing it multiple times"
self.assertEqual(self.cursor.statement, None) self.assertEqual(self.cursor.statement, None)
statement = "begin :value := :value + 5; end;" statement = "begin :value := :value + 5; end;"
self.cursor.prepare(statement) self.cursor.prepare(statement)
@ -310,14 +308,14 @@ class TestCase(TestEnv.BaseTestCase):
self.cursor.execute("begin :value2 := 3; end;", value2 = var) self.cursor.execute("begin :value2 := 3; end;", value2 = var)
self.assertEqual(var.getvalue(), 3) self.assertEqual(var.getvalue(), 3)
def testExceptionOnClose(self): def test_1229_ExceptionOnClose(self):
"confirm an exception is raised after closing a cursor" "1229 - confirm an exception is raised after closing a cursor"
self.cursor.close() self.cursor.close()
self.assertRaises(cx_Oracle.InterfaceError, self.cursor.execute, self.assertRaises(cx_Oracle.InterfaceError, self.cursor.execute,
"select 1 from dual") "select 1 from dual")
def testIterators(self): def test_1230_Iterators(self):
"""test iterators""" "1230 - test iterators"
self.cursor.execute(""" self.cursor.execute("""
select IntCol select IntCol
from TestNumbers from TestNumbers
@ -328,8 +326,8 @@ class TestCase(TestEnv.BaseTestCase):
rows.append(row[0]) rows.append(row[0])
self.assertEqual(rows, [1, 2, 3]) self.assertEqual(rows, [1, 2, 3])
def testIteratorsInterrupted(self): def test_1231_IteratorsInterrupted(self):
"""test iterators (with intermediate execute)""" "1231 - test iterators (with intermediate execute)"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
self.cursor.execute(""" self.cursor.execute("""
select IntCol select IntCol
@ -347,10 +345,10 @@ class TestCase(TestEnv.BaseTestCase):
else: else:
self.assertRaises(cx_Oracle.InterfaceError, testIter.next) self.assertRaises(cx_Oracle.InterfaceError, testIter.next)
def testBindNames(self): def test_1232_BindNames(self):
"""test that bindnames() works correctly.""" "1232 - test that bindnames() works correctly."
self.assertRaises(cx_Oracle.ProgrammingError, self.cursor.bindnames) self.assertRaises(cx_Oracle.ProgrammingError, self.cursor.bindnames)
self.cursor.prepare(u"begin null; end;") self.cursor.prepare("begin null; end;")
self.assertEqual(self.cursor.bindnames(), []) self.assertEqual(self.cursor.bindnames(), [])
self.cursor.prepare("begin :retval := :inval + 5; end;") self.cursor.prepare("begin :retval := :inval + 5; end;")
self.assertEqual(self.cursor.bindnames(), ["RETVAL", "INVAL"]) self.assertEqual(self.cursor.bindnames(), ["RETVAL", "INVAL"])
@ -363,22 +361,22 @@ class TestCase(TestEnv.BaseTestCase):
self.cursor.prepare("select :a * :a + :b * :b from dual") self.cursor.prepare("select :a * :a + :b * :b from dual")
self.assertEqual(self.cursor.bindnames(), ["A", "B"]) self.assertEqual(self.cursor.bindnames(), ["A", "B"])
def testBadPrepare(self): def test_1233_BadPrepare(self):
"""test that subsequent executes succeed after bad prepare""" "1233 - test that subsequent executes succeed after bad prepare"
self.assertRaises(cx_Oracle.DatabaseError, self.assertRaises(cx_Oracle.DatabaseError,
self.cursor.execute, self.cursor.execute,
"begin raise_application_error(-20000, 'this); end;") "begin raise_application_error(-20000, 'this); end;")
self.cursor.execute("begin null; end;") self.cursor.execute("begin null; end;")
def testBadExecute(self): def test_1234_BadExecute(self):
"""test that subsequent fetches fail after bad execute""" "1234 - test that subsequent fetches fail after bad execute"
self.assertRaises(cx_Oracle.DatabaseError, self.assertRaises(cx_Oracle.DatabaseError,
self.cursor.execute, "select y from dual") self.cursor.execute, "select y from dual")
self.assertRaises(cx_Oracle.InterfaceError, self.assertRaises(cx_Oracle.InterfaceError,
self.cursor.fetchall) self.cursor.fetchall)
def testScrollAbsoluteExceptionAfter(self): def test_1235_ScrollAbsoluteExceptionAfter(self):
"""test scrolling absolute yields an exception (after result set)""" "1235 - test scrolling absolute yields an exception (after result set)"
cursor = self.connection.cursor(scrollable = True) cursor = self.connection.cursor(scrollable = True)
cursor.arraysize = self.cursor.arraysize cursor.arraysize = self.cursor.arraysize
cursor.execute(""" cursor.execute("""
@ -388,8 +386,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, 12, self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, 12,
"absolute") "absolute")
def testScrollAbsoluteInBuffer(self): def test_1236_ScrollAbsoluteInBuffer(self):
"""test scrolling absolute (when in buffers)""" "1236 - test scrolling absolute (when in buffers)"
cursor = self.connection.cursor(scrollable = True) cursor = self.connection.cursor(scrollable = True)
cursor.arraysize = self.cursor.arraysize cursor.arraysize = self.cursor.arraysize
cursor.execute(""" cursor.execute("""
@ -404,8 +402,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(row[0], 1.25) self.assertEqual(row[0], 1.25)
self.assertEqual(cursor.rowcount, 1) self.assertEqual(cursor.rowcount, 1)
def testScrollAbsoluteNotInBuffer(self): def test_1237_ScrollAbsoluteNotInBuffer(self):
"""test scrolling absolute (when not in buffers)""" "1237 - test scrolling absolute (when not in buffers)"
cursor = self.connection.cursor(scrollable = True) cursor = self.connection.cursor(scrollable = True)
cursor.arraysize = self.cursor.arraysize cursor.arraysize = self.cursor.arraysize
cursor.execute(""" cursor.execute("""
@ -417,8 +415,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(row[0], 7.5) self.assertEqual(row[0], 7.5)
self.assertEqual(cursor.rowcount, 6) self.assertEqual(cursor.rowcount, 6)
def testScrollFirstInBuffer(self): def test_1238_ScrollFirstInBuffer(self):
"""test scrolling to first row in result set (when in buffers)""" "1238 - test scrolling to first row in result set (in buffers)"
cursor = self.connection.cursor(scrollable = True) cursor = self.connection.cursor(scrollable = True)
cursor.arraysize = self.cursor.arraysize cursor.arraysize = self.cursor.arraysize
cursor.execute(""" cursor.execute("""
@ -431,8 +429,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(row[0], 1.25) self.assertEqual(row[0], 1.25)
self.assertEqual(cursor.rowcount, 1) self.assertEqual(cursor.rowcount, 1)
def testScrollFirstNotInBuffer(self): def test_1239_ScrollFirstNotInBuffer(self):
"""test scrolling to first row in result set (when not in buffers)""" "1239 - test scrolling to first row in result set (not in buffers)"
cursor = self.connection.cursor(scrollable = True) cursor = self.connection.cursor(scrollable = True)
cursor.arraysize = self.cursor.arraysize cursor.arraysize = self.cursor.arraysize
cursor.execute(""" cursor.execute("""
@ -446,8 +444,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(row[0], 1.25) self.assertEqual(row[0], 1.25)
self.assertEqual(cursor.rowcount, 1) self.assertEqual(cursor.rowcount, 1)
def testScrollLast(self): def test_1240_ScrollLast(self):
"""test scrolling to last row in result set""" "1240 - test scrolling to last row in result set"
cursor = self.connection.cursor(scrollable = True) cursor = self.connection.cursor(scrollable = True)
cursor.arraysize = self.cursor.arraysize cursor.arraysize = self.cursor.arraysize
cursor.execute(""" cursor.execute("""
@ -459,8 +457,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(row[0], 12.5) self.assertEqual(row[0], 12.5)
self.assertEqual(cursor.rowcount, 10) self.assertEqual(cursor.rowcount, 10)
def testScrollRelativeExceptionAfter(self): def test_1241_ScrollRelativeExceptionAfter(self):
"""test scrolling relative yields an exception (after result set)""" "1241 - test scrolling relative yields an exception (after result set)"
cursor = self.connection.cursor(scrollable = True) cursor = self.connection.cursor(scrollable = True)
cursor.arraysize = self.cursor.arraysize cursor.arraysize = self.cursor.arraysize
cursor.execute(""" cursor.execute("""
@ -469,8 +467,8 @@ class TestCase(TestEnv.BaseTestCase):
order by IntCol""") order by IntCol""")
self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, 15) self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, 15)
def testScrollRelativeExceptionBefore(self): def test_1242_ScrollRelativeExceptionBefore(self):
"""test scrolling relative yields an exception (before result set)""" "1242 - test scrolling relative yields exception (before result set)"
cursor = self.connection.cursor(scrollable = True) cursor = self.connection.cursor(scrollable = True)
cursor.arraysize = self.cursor.arraysize cursor.arraysize = self.cursor.arraysize
cursor.execute(""" cursor.execute("""
@ -479,8 +477,8 @@ class TestCase(TestEnv.BaseTestCase):
order by IntCol""") order by IntCol""")
self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, -5) self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, -5)
def testScrollRelativeInBuffer(self): def test_1243_ScrollRelativeInBuffer(self):
"""test scrolling relative (when in buffers)""" "1243 - test scrolling relative (when in buffers)"
cursor = self.connection.cursor(scrollable = True) cursor = self.connection.cursor(scrollable = True)
cursor.arraysize = self.cursor.arraysize cursor.arraysize = self.cursor.arraysize
cursor.execute(""" cursor.execute("""
@ -495,8 +493,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(row[0], 2.5) self.assertEqual(row[0], 2.5)
self.assertEqual(cursor.rowcount, 2) self.assertEqual(cursor.rowcount, 2)
def testScrollRelativeNotInBuffer(self): def test_1244_ScrollRelativeNotInBuffer(self):
"""test scrolling relative (when not in buffers)""" "1244 - test scrolling relative (when not in buffers)"
cursor = self.connection.cursor(scrollable = True) cursor = self.connection.cursor(scrollable = True)
cursor.arraysize = self.cursor.arraysize cursor.arraysize = self.cursor.arraysize
cursor.execute(""" cursor.execute("""
@ -512,8 +510,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(row[0], 3.75) self.assertEqual(row[0], 3.75)
self.assertEqual(cursor.rowcount, 3) self.assertEqual(cursor.rowcount, 3)
def testScrollNoRows(self): def test_1245_ScrollNoRows(self):
"""test scrolling when there are no rows""" "1245 - test scrolling when there are no rows"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
cursor = self.connection.cursor(scrollable = True) cursor = self.connection.cursor(scrollable = True)
cursor.execute("select * from TestTempTable") cursor.execute("select * from TestTempTable")
@ -524,8 +522,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, 1, self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, 1,
mode = "absolute") mode = "absolute")
def testScrollDifferingArrayAndFetchSizes(self): def test_1246_ScrollDifferingArrayAndFetchSizes(self):
"""test scrolling with differing array sizes and fetch array sizes""" "1246 - test scrolling with differing array and fetch array sizes"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
for i in range(30): for i in range(30):
self.cursor.execute(""" self.cursor.execute("""
@ -553,62 +551,62 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(cursor.rowcount, self.assertEqual(cursor.rowcount,
15 + numRows + numRowsFetched + numRows - 6) 15 + numRows + numRowsFetched + numRows - 6)
def testSetInputSizesNegative(self): def test_1247_SetInputSizesNegative(self):
"test cursor.setinputsizes() with invalid parameters" "1247 - test cursor.setinputsizes() with invalid parameters"
val = decimal.Decimal(5) val = decimal.Decimal(5)
self.assertRaises(cx_Oracle.InterfaceError, self.assertRaises(cx_Oracle.InterfaceError,
self.cursor.setinputsizes, val, x = val) self.cursor.setinputsizes, val, x = val)
self.assertRaises(TypeError, self.cursor.setinputsizes, val) self.assertRaises(TypeError, self.cursor.setinputsizes, val)
def testSetInputSizesNoParameters(self): def test_1248_SetInputSizesNoParameters(self):
"test setting input sizes without any parameters" "1248 - test setting input sizes without any parameters"
self.cursor.setinputsizes() self.cursor.setinputsizes()
self.cursor.execute("select :val from dual", val = "Test Value") self.cursor.execute("select :val from dual", val = "Test Value")
self.assertEqual(self.cursor.fetchall(), [("Test Value",)]) self.assertEqual(self.cursor.fetchall(), [("Test Value",)])
def testSetInputSizesEmptyDict(self): def test_1249_SetInputSizesEmptyDict(self):
"test setting input sizes with an empty dictionary" "1249 - test setting input sizes with an empty dictionary"
emptyDict = {} emptyDict = {}
self.cursor.prepare("select 236 from dual") self.cursor.prepare("select 236 from dual")
self.cursor.setinputsizes(**emptyDict) self.cursor.setinputsizes(**emptyDict)
self.cursor.execute(None, emptyDict) self.cursor.execute(None, emptyDict)
self.assertEqual(self.cursor.fetchall(), [(236,)]) self.assertEqual(self.cursor.fetchall(), [(236,)])
def testSetInputSizesEmptyList(self): def test_1250_SetInputSizesEmptyList(self):
"test setting input sizes with an empty list" "1250 - test setting input sizes with an empty list"
emptyList = {} emptyList = {}
self.cursor.prepare("select 239 from dual") self.cursor.prepare("select 239 from dual")
self.cursor.setinputsizes(*emptyList) self.cursor.setinputsizes(*emptyList)
self.cursor.execute(None, emptyList) self.cursor.execute(None, emptyList)
self.assertEqual(self.cursor.fetchall(), [(239,)]) self.assertEqual(self.cursor.fetchall(), [(239,)])
def testSetInputSizesByPosition(self): def test_1251_SetInputSizesByPosition(self):
"""test setting input sizes with positional args""" "1251 - test setting input sizes with positional args"
var = self.cursor.var(cx_Oracle.STRING, 100) var = self.cursor.var(cx_Oracle.STRING, 100)
self.cursor.setinputsizes(None, 5, None, 10, None, cx_Oracle.NUMBER) self.cursor.setinputsizes(None, 5, None, 10, None, cx_Oracle.NUMBER)
self.cursor.execute(""" self.cursor.execute("""
begin begin
:1 := :2 || to_char(:3) || :4 || to_char(:5) || to_char(:6); :1 := :2 || to_char(:3) || :4 || to_char(:5) || to_char(:6);
end;""", [var, 'test_', 5, '_second_', 3, 7]) end;""", [var, 'test_', 5, '_second_', 3, 7])
self.assertEqual(var.getvalue(), u"test_5_second_37") self.assertEqual(var.getvalue(), "test_5_second_37")
def testStringFormat(self): def test_1252_StringFormat(self):
"""test string format of cursor""" "1252 - test string format of cursor"
formatString = "<cx_Oracle.Cursor on <cx_Oracle.Connection to %s@%s>>" formatString = "<cx_Oracle.Cursor on <cx_Oracle.Connection to %s@%s>>"
expectedValue = formatString % \ expectedValue = formatString % \
(TestEnv.GetMainUser(), TestEnv.GetConnectString()) (TestEnv.GetMainUser(), TestEnv.GetConnectString())
self.assertEqual(str(self.cursor), expectedValue) self.assertEqual(str(self.cursor), expectedValue)
def testCursorFetchRaw(self): def test_1253_CursorFetchRaw(self):
"""test cursor.fetchraw()""" "1253 - test cursor.fetchraw()"
cursor = self.connection.cursor() cursor = self.connection.cursor()
cursor.arraysize = 25 cursor.arraysize = 25
cursor.execute("select LongIntCol from TestNumbers order by IntCol") cursor.execute("select LongIntCol from TestNumbers order by IntCol")
self.assertEqual(cursor.fetchraw(), 10) self.assertEqual(cursor.fetchraw(), 10)
self.assertEqual(cursor.fetchvars[0].getvalue(), 38) self.assertEqual(cursor.fetchvars[0].getvalue(), 38)
def testParse(self): def test_1254_Parse(self):
"""test parsing statements""" "1254 - test parsing statements"
sql = "select LongIntCol from TestNumbers where IntCol = :val" sql = "select LongIntCol from TestNumbers where IntCol = :val"
self.cursor.parse(sql) self.cursor.parse(sql)
self.assertEqual(self.cursor.statement, sql) self.assertEqual(self.cursor.statement, sql)
@ -616,20 +614,20 @@ class TestCase(TestEnv.BaseTestCase):
[ ('LONGINTCOL', cx_Oracle.DB_TYPE_NUMBER, 17, None, 16, 0, [ ('LONGINTCOL', cx_Oracle.DB_TYPE_NUMBER, 17, None, 16, 0,
0) ]) 0) ])
def testSetOutputSize(self): def test_1255_SetOutputSize(self):
"test cursor.setoutputsize() does not fail (but does nothing)" "1255 - test cursor.setoutputsize() does not fail (but does nothing)"
self.cursor.setoutputsize(100, 2) self.cursor.setoutputsize(100, 2)
def testVarNegative(self): def test_1256_VarNegative(self):
"test cursor.var() with invalid parameters" "1256 - test cursor.var() with invalid parameters"
self.assertRaises(TypeError, self.cursor.var, 5) self.assertRaises(TypeError, self.cursor.var, 5)
def testArrayVarNegative(self): def test_1257_ArrayVarNegative(self):
"test cursor.arrayvar() with invalid parameters" "1257 - test cursor.arrayvar() with invalid parameters"
self.assertRaises(TypeError, self.cursor.arrayvar, 5, 1) self.assertRaises(TypeError, self.cursor.arrayvar, 5, 1)
def testBooleanWithoutPlsql(self): def test_1258_BooleanWithoutPlsql(self):
"test binding boolean data without the use of PL/SQL" "1258 - test binding boolean data without the use of PL/SQL"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
sql = "insert into TestTempTable (IntCol, StringCol) values (:1, :2)" sql = "insert into TestTempTable (IntCol, StringCol) values (:1, :2)"
self.cursor.execute(sql, (False, "Value should be 0")) self.cursor.execute(sql, (False, "Value should be 0"))
@ -641,8 +639,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(self.cursor.fetchall(), self.assertEqual(self.cursor.fetchall(),
[ (0, "Value should be 0"), (1, "Value should be 1") ]) [ (0, "Value should be 0"), (1, "Value should be 1") ])
def testAsContextManager(self): def test_1259_AsContextManager(self):
"test using a cursor as a context manager" "1259 - test using a cursor as a context manager"
with self.cursor as cursor: with self.cursor as cursor:
cursor.execute("truncate table TestTempTable") cursor.execute("truncate table TestTempTable")
cursor.execute("select count(*) from TestTempTable") cursor.execute("select count(*) from TestTempTable")
@ -650,8 +648,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(count, 0) self.assertEqual(count, 0)
self.assertRaises(cx_Oracle.InterfaceError, self.cursor.close) self.assertRaises(cx_Oracle.InterfaceError, self.cursor.close)
def testQueryRowCount(self): def test_1260_QueryRowCount(self):
"test that the rowcount attribute is reset to zero on query execute" "1260 - test that rowcount attribute is reset to zero on query execute"
sql = "select * from dual where 1 = :s" sql = "select * from dual where 1 = :s"
self.cursor.execute(sql, [0]) self.cursor.execute(sql, [0])
self.cursor.fetchone() self.cursor.fetchone()
@ -666,15 +664,15 @@ class TestCase(TestEnv.BaseTestCase):
self.cursor.fetchone() self.cursor.fetchone()
self.assertEqual(self.cursor.rowcount, 0) self.assertEqual(self.cursor.rowcount, 0)
def testVarTypeNameNone(self): def test_1261_VarTypeNameNone(self):
"test that the typename attribute can be passed a value of None" "1261 - test that the typename attribute can be passed a value of None"
valueToSet = 5 valueToSet = 5
var = self.cursor.var(int, typename=None) var = self.cursor.var(int, typename=None)
var.setvalue(0, valueToSet) var.setvalue(0, valueToSet)
self.assertEqual(var.getvalue(), valueToSet) self.assertEqual(var.getvalue(), valueToSet)
def testVarTypeWithObjectType(self): def test_1262_VarTypeWithObjectType(self):
"test that an object type can be used as type in cursor.var()" "1262 - test that an object type can be used as type in cursor.var()"
objType = self.connection.gettype("UDT_OBJECT") objType = self.connection.gettype("UDT_OBJECT")
var = self.cursor.var(objType) var = self.cursor.var(objType)
self.cursor.callproc("pkg_TestBindObject.BindObjectOut", self.cursor.callproc("pkg_TestBindObject.BindObjectOut",
@ -685,8 +683,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(result, self.assertEqual(result,
"udt_Object(28, 'Bind obj out', null, null, null, null, null)") "udt_Object(28, 'Bind obj out', null, null, null, null, null)")
def testFetchXMLType(self): def test_1263_FetchXMLType(self):
"test that fetching an XMLType returns a string contains its contents" "1263 - test that fetching an XMLType returns a string"
intVal = 5 intVal = 5
label = "IntCol" label = "IntCol"
expectedResult = "<%s>%s</%s>" % (label, intVal, label) expectedResult = "<%s>%s</%s>" % (label, intVal, label)
@ -698,8 +696,8 @@ class TestCase(TestEnv.BaseTestCase):
result, = self.cursor.fetchone() result, = self.cursor.fetchone()
self.assertEqual(result, expectedResult) self.assertEqual(result, expectedResult)
def testLastRowid(self): def test_1264_LastRowid(self):
"test last rowid" "1264 - test last rowid"
# no statement executed: no rowid # no statement executed: no rowid
self.assertEqual(None, self.cursor.lastrowid) self.assertEqual(None, self.cursor.lastrowid)
@ -750,8 +748,8 @@ class TestCase(TestEnv.BaseTestCase):
where rowid = :1""", [rowid]) where rowid = :1""", [rowid])
self.assertEqual("Row %s" % rows[-3], self.cursor.fetchone()[0]) self.assertEqual("Row %s" % rows[-3], self.cursor.fetchone()[0])
def testPrefetchRows(self): def test_1265_PrefetchRows(self):
"test prefetch rows" "1265 - test prefetch rows"
self.setUpRoundTripChecker() self.setUpRoundTripChecker()
# perform simple query and verify only one round trip is needed # perform simple query and verify only one round trip is needed

View File

@ -7,7 +7,9 @@
# Canada. All rights reserved. # Canada. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing cursor variables.""" """
1300 - Module for testing cursor variables
"""
import TestEnv import TestEnv
@ -16,8 +18,8 @@ import sys
class TestCase(TestEnv.BaseTestCase): class TestCase(TestEnv.BaseTestCase):
def testBindCursor(self): def test_1300_BindCursor(self):
"test binding in a cursor" "1300 - test binding in a cursor"
cursor = self.connection.cursor() cursor = self.connection.cursor()
self.assertEqual(cursor.description, None) self.assertEqual(cursor.description, None)
self.cursor.execute(""" self.cursor.execute("""
@ -30,8 +32,8 @@ class TestCase(TestEnv.BaseTestCase):
TestEnv.GetCharSetRatio(), None, None, 1) ]) TestEnv.GetCharSetRatio(), None, None, 1) ])
self.assertEqual(cursor.fetchall(), [('X',)]) self.assertEqual(cursor.fetchall(), [('X',)])
def testBindCursorInPackage(self): def test_1301_BindCursorInPackage(self):
"test binding in a cursor from a package" "1301 - test binding in a cursor from a package"
cursor = self.connection.cursor() cursor = self.connection.cursor()
self.assertEqual(cursor.description, None) self.assertEqual(cursor.description, None)
self.cursor.callproc("pkg_TestRefCursors.TestOutCursor", (2, cursor)) self.cursor.callproc("pkg_TestRefCursors.TestOutCursor", (2, cursor))
@ -42,8 +44,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(cursor.fetchall(), self.assertEqual(cursor.fetchall(),
[ (1, 'String 1'), (2, 'String 2') ]) [ (1, 'String 1'), (2, 'String 2') ])
def testBindSelf(self): def test_1302_BindSelf(self):
"test that binding the cursor itself is not supported" "1302 - test that binding the cursor itself is not supported"
cursor = self.connection.cursor() cursor = self.connection.cursor()
sql = """ sql = """
begin begin
@ -53,8 +55,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertRaises(cx_Oracle.DatabaseError, cursor.execute, sql, self.assertRaises(cx_Oracle.DatabaseError, cursor.execute, sql,
pcursor = cursor) pcursor = cursor)
def testExecuteAfterClose(self): def test_1303_ExecuteAfterClose(self):
"test executing a statement returning a ref cursor after closing it" "1303 - test returning a ref cursor after closing it"
outCursor = self.connection.cursor() outCursor = self.connection.cursor()
sql = """ sql = """
begin begin
@ -71,8 +73,8 @@ class TestCase(TestEnv.BaseTestCase):
rows2 = outCursor.fetchall() rows2 = outCursor.fetchall()
self.assertEqual(rows, rows2) self.assertEqual(rows, rows2)
def testFetchCursor(self): def test_1304_FetchCursor(self):
"test fetching a cursor" "1304 - test fetching a cursor"
self.cursor.execute(""" self.cursor.execute("""
select select
IntCol, IntCol,

View File

@ -1,5 +1,5 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
# #
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -7,7 +7,9 @@
# Canada. All rights reserved. # Canada. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing date/time variables.""" """
1400 - Module for testing date/time variables
"""
import TestEnv import TestEnv
@ -35,31 +37,31 @@ class TestCase(TestEnv.BaseTestCase):
self.rawData.append(tuple) self.rawData.append(tuple)
self.dataByKey[i] = tuple self.dataByKey[i] = tuple
def testBindDate(self): def test_1400_BindDate(self):
"test binding in a date" "1400 - test binding in a date"
self.cursor.execute(""" self.cursor.execute("""
select * from TestDates select * from TestDates
where DateCol = :value""", where DateCol = :value""",
value = cx_Oracle.Timestamp(2002, 12, 13, 9, 36, 0)) value = cx_Oracle.Timestamp(2002, 12, 13, 9, 36, 0))
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[4]]) self.assertEqual(self.cursor.fetchall(), [self.dataByKey[4]])
def testBindDateTime(self): def test_1401_BindDateTime(self):
"test binding in a datetime.datetime value" "1401 - test binding in a datetime.datetime value"
self.cursor.execute(""" self.cursor.execute("""
select * from TestDates select * from TestDates
where DateCol = :value""", where DateCol = :value""",
value = datetime.datetime(2002, 12, 13, 9, 36, 0)) value = datetime.datetime(2002, 12, 13, 9, 36, 0))
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[4]]) self.assertEqual(self.cursor.fetchall(), [self.dataByKey[4]])
def testBindDateInDateTimeVar(self): def test_1402_BindDateInDateTimeVar(self):
"test binding date in a datetime variable" "1402 - test binding date in a datetime variable"
var = self.cursor.var(cx_Oracle.DATETIME) var = self.cursor.var(cx_Oracle.DATETIME)
dateVal = datetime.date.today() dateVal = datetime.date.today()
var.setvalue(0, dateVal) var.setvalue(0, dateVal)
self.assertEqual(var.getvalue().date(), dateVal) self.assertEqual(var.getvalue().date(), dateVal)
def testBindDateAfterString(self): def test_1403_BindDateAfterString(self):
"test binding in a date after setting input sizes to a string" "1403 - test binding in a date after setting input sizes to a string"
self.cursor.setinputsizes(value = 15) self.cursor.setinputsizes(value = 15)
self.cursor.execute(""" self.cursor.execute("""
select * from TestDates select * from TestDates
@ -67,8 +69,8 @@ class TestCase(TestEnv.BaseTestCase):
value = cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0)) value = cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0))
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[5]]) self.assertEqual(self.cursor.fetchall(), [self.dataByKey[5]])
def testBindNull(self): def test_1404_BindNull(self):
"test binding in a null" "1404 - test binding in a null"
self.cursor.setinputsizes(value = cx_Oracle.DATETIME) self.cursor.setinputsizes(value = cx_Oracle.DATETIME)
self.cursor.execute(""" self.cursor.execute("""
select * from TestDates select * from TestDates
@ -76,8 +78,8 @@ class TestCase(TestEnv.BaseTestCase):
value = None) value = None)
self.assertEqual(self.cursor.fetchall(), []) self.assertEqual(self.cursor.fetchall(), [])
def testBindDateArrayDirect(self): def test_1405_BindDateArrayDirect(self):
"test binding in a date array" "1405 - test binding in a date array"
returnValue = self.cursor.var(cx_Oracle.NUMBER) returnValue = self.cursor.var(cx_Oracle.NUMBER)
array = [r[1] for r in self.rawData] array = [r[1] for r in self.rawData]
statement = """ statement = """
@ -98,8 +100,8 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(returnValue.getvalue(), 24.0) self.assertEqual(returnValue.getvalue(), 24.0)
def testBindDateArrayBySizes(self): def test_1406_BindDateArrayBySizes(self):
"test binding in a date array (with setinputsizes)" "1406 - test binding in a date array (with setinputsizes)"
returnValue = self.cursor.var(cx_Oracle.NUMBER) returnValue = self.cursor.var(cx_Oracle.NUMBER)
self.cursor.setinputsizes(array = [cx_Oracle.DATETIME, 10]) self.cursor.setinputsizes(array = [cx_Oracle.DATETIME, 10])
array = [r[1] for r in self.rawData] array = [r[1] for r in self.rawData]
@ -114,8 +116,8 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(returnValue.getvalue(), 26.5) self.assertEqual(returnValue.getvalue(), 26.5)
def testBindDateArrayByVar(self): def test_1407_BindDateArrayByVar(self):
"test binding in a date array (with arrayvar)" "1407 - test binding in a date array (with arrayvar)"
returnValue = self.cursor.var(cx_Oracle.NUMBER) returnValue = self.cursor.var(cx_Oracle.NUMBER)
array = self.cursor.arrayvar(cx_Oracle.DATETIME, 10, 20) array = self.cursor.arrayvar(cx_Oracle.DATETIME, 10, 20)
array.setvalue(0, [r[1] for r in self.rawData]) array.setvalue(0, [r[1] for r in self.rawData])
@ -130,8 +132,8 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(returnValue.getvalue(), 17.5) self.assertEqual(returnValue.getvalue(), 17.5)
def testBindInOutDateArrayByVar(self): def test_1408_BindInOutDateArrayByVar(self):
"test binding in/out a date array (with arrayvar)" "1408 - test binding in/out a date array (with arrayvar)"
array = self.cursor.arrayvar(cx_Oracle.DATETIME, 10, 100) array = self.cursor.arrayvar(cx_Oracle.DATETIME, 10, 100)
originalData = [r[1] for r in self.rawData] originalData = [r[1] for r in self.rawData]
array.setvalue(0, originalData) array.setvalue(0, originalData)
@ -149,8 +151,8 @@ class TestCase(TestEnv.BaseTestCase):
cx_Oracle.Timestamp(2002, 12, 21, 12, 0, 0) ] + \ cx_Oracle.Timestamp(2002, 12, 21, 12, 0, 0) ] + \
originalData[5:]) originalData[5:])
def testBindOutDateArrayByVar(self): def test_1409_BindOutDateArrayByVar(self):
"test binding out a date array (with arrayvar)" "1409 - test binding out a date array (with arrayvar)"
array = self.cursor.arrayvar(cx_Oracle.DATETIME, 6, 100) array = self.cursor.arrayvar(cx_Oracle.DATETIME, 6, 100)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -166,8 +168,8 @@ class TestCase(TestEnv.BaseTestCase):
cx_Oracle.Timestamp(2002, 12, 18, 0, 0, 0), cx_Oracle.Timestamp(2002, 12, 18, 0, 0, 0),
cx_Oracle.Timestamp(2002, 12, 19, 4, 48, 0) ]) cx_Oracle.Timestamp(2002, 12, 19, 4, 48, 0) ])
def testBindOutSetInputSizes(self): def test_1410_BindOutSetInputSizes(self):
"test binding out with set input sizes defined" "1410 - test binding out with set input sizes defined"
vars = self.cursor.setinputsizes(value = cx_Oracle.DATETIME) vars = self.cursor.setinputsizes(value = cx_Oracle.DATETIME)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -176,8 +178,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(vars["value"].getvalue(), self.assertEqual(vars["value"].getvalue(),
cx_Oracle.Timestamp(2002, 12, 9)) cx_Oracle.Timestamp(2002, 12, 9))
def testBindInOutSetInputSizes(self): def test_1411_BindInOutSetInputSizes(self):
"test binding in/out with set input sizes defined" "1411 - test binding in/out with set input sizes defined"
vars = self.cursor.setinputsizes(value = cx_Oracle.DATETIME) vars = self.cursor.setinputsizes(value = cx_Oracle.DATETIME)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -187,8 +189,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(vars["value"].getvalue(), self.assertEqual(vars["value"].getvalue(),
cx_Oracle.Timestamp(2002, 12, 17, 16, 0, 0)) cx_Oracle.Timestamp(2002, 12, 17, 16, 0, 0))
def testBindOutVar(self): def test_1412_BindOutVar(self):
"test binding out with cursor.var() method" "1412 - test binding out with cursor.var() method"
var = self.cursor.var(cx_Oracle.DATETIME) var = self.cursor.var(cx_Oracle.DATETIME)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -199,8 +201,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(var.getvalue(), self.assertEqual(var.getvalue(),
cx_Oracle.Timestamp(2002, 12, 31, 12, 31, 0)) cx_Oracle.Timestamp(2002, 12, 31, 12, 31, 0))
def testBindInOutVarDirectSet(self): def test_1413_BindInOutVarDirectSet(self):
"test binding in/out with cursor.var() method" "1413 - test binding in/out with cursor.var() method"
var = self.cursor.var(cx_Oracle.DATETIME) var = self.cursor.var(cx_Oracle.DATETIME)
var.setvalue(0, cx_Oracle.Timestamp(2002, 12, 9, 6, 0, 0)) var.setvalue(0, cx_Oracle.Timestamp(2002, 12, 9, 6, 0, 0))
self.cursor.execute(""" self.cursor.execute("""
@ -211,8 +213,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(var.getvalue(), self.assertEqual(var.getvalue(),
cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0)) cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0))
def testCursorDescription(self): def test_1414_CursorDescription(self):
"test cursor description is accurate" "1414 - test cursor description is accurate"
self.cursor.execute("select * from TestDates") self.cursor.execute("select * from TestDates")
self.assertEqual(self.cursor.description, self.assertEqual(self.cursor.description,
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0), [ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
@ -220,14 +222,14 @@ class TestCase(TestEnv.BaseTestCase):
('NULLABLECOL', cx_Oracle.DB_TYPE_DATE, 23, None, None, None, ('NULLABLECOL', cx_Oracle.DB_TYPE_DATE, 23, None, None, None,
1) ]) 1) ])
def testFetchAll(self): def test_1415_FetchAll(self):
"test that fetching all of the data returns the correct results" "1415 - test that fetching all of the data returns the correct results"
self.cursor.execute("select * From TestDates order by IntCol") self.cursor.execute("select * From TestDates order by IntCol")
self.assertEqual(self.cursor.fetchall(), self.rawData) self.assertEqual(self.cursor.fetchall(), self.rawData)
self.assertEqual(self.cursor.fetchall(), []) self.assertEqual(self.cursor.fetchall(), [])
def testFetchMany(self): def test_1416_FetchMany(self):
"test that fetching data in chunks returns the correct results" "1416 - test that fetching data in chunks returns the correct results"
self.cursor.execute("select * From TestDates order by IntCol") self.cursor.execute("select * From TestDates order by IntCol")
self.assertEqual(self.cursor.fetchmany(3), self.rawData[0:3]) 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(2), self.rawData[3:5])
@ -235,8 +237,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:]) self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:])
self.assertEqual(self.cursor.fetchmany(3), []) self.assertEqual(self.cursor.fetchmany(3), [])
def testFetchOne(self): def test_1417_FetchOne(self):
"test that fetching a single row returns the correct results" "1417 - test that fetching a single row returns the correct results"
self.cursor.execute(""" self.cursor.execute("""
select * select *
from TestDates from TestDates
@ -248,4 +250,3 @@ class TestCase(TestEnv.BaseTestCase):
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -3,8 +3,8 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
""" """
Module for testing comparisons with database types and API types. This also 1500 - Module for testing comparisons with database types and API types. This
contains tests for comparisons with database types and variable types, for also contains tests for comparisons with database types and variable types, for
backwards compatibility. backwards compatibility.
""" """
@ -21,110 +21,110 @@ class TestCase(TestEnv.BaseTestCase):
self.assertNotEqual(dbType, 5) self.assertNotEqual(dbType, 5)
self.assertNotEqual(dbType, cx_Oracle.DB_TYPE_OBJECT) self.assertNotEqual(dbType, cx_Oracle.DB_TYPE_OBJECT)
def testBfile(self): def test_1500_Bfile(self):
"test cx_Oracle.DB_TYPE_BFILE comparisons" "1500 - test cx_Oracle.DB_TYPE_BFILE comparisons"
self.assertEqual(cx_Oracle.DB_TYPE_BFILE, cx_Oracle.BFILE) self.assertEqual(cx_Oracle.DB_TYPE_BFILE, cx_Oracle.BFILE)
def testBinaryDouble(self): def test_1501_BinaryDouble(self):
"test cx_Oracle.DB_TYPE_BINARY_DOUBLE comparisons" "1501 - test cx_Oracle.DB_TYPE_BINARY_DOUBLE comparisons"
self.__testCompare(cx_Oracle.DB_TYPE_BINARY_DOUBLE, cx_Oracle.NUMBER) self.__testCompare(cx_Oracle.DB_TYPE_BINARY_DOUBLE, cx_Oracle.NUMBER)
self.assertEqual(cx_Oracle.DB_TYPE_BINARY_DOUBLE, self.assertEqual(cx_Oracle.DB_TYPE_BINARY_DOUBLE,
cx_Oracle.NATIVE_FLOAT) cx_Oracle.NATIVE_FLOAT)
def testBinaryFloat(self): def test_1502_BinaryFloat(self):
"test cx_Oracle.DB_TYPE_BINARY_FLOAT comparisons" "1502 - test cx_Oracle.DB_TYPE_BINARY_FLOAT comparisons"
self.__testCompare(cx_Oracle.DB_TYPE_BINARY_FLOAT, cx_Oracle.NUMBER) self.__testCompare(cx_Oracle.DB_TYPE_BINARY_FLOAT, cx_Oracle.NUMBER)
def testBinaryInteger(self): def test_1503_BinaryInteger(self):
"test cx_Oracle.DB_TYPE_BINARY_INTEGER comparisons" "1503 - test cx_Oracle.DB_TYPE_BINARY_INTEGER comparisons"
self.__testCompare(cx_Oracle.DB_TYPE_BINARY_INTEGER, cx_Oracle.NUMBER) self.__testCompare(cx_Oracle.DB_TYPE_BINARY_INTEGER, cx_Oracle.NUMBER)
self.assertEqual(cx_Oracle.DB_TYPE_BINARY_INTEGER, self.assertEqual(cx_Oracle.DB_TYPE_BINARY_INTEGER,
cx_Oracle.NATIVE_INT) cx_Oracle.NATIVE_INT)
def testBlob(self): def test_1504_Blob(self):
"test cx_Oracle.DB_TYPE_BLOB comparisons" "1504 - test cx_Oracle.DB_TYPE_BLOB comparisons"
self.assertEqual(cx_Oracle.DB_TYPE_BLOB, cx_Oracle.BLOB) self.assertEqual(cx_Oracle.DB_TYPE_BLOB, cx_Oracle.BLOB)
def testBoolean(self): def test_1505_Boolean(self):
"test cx_Oracle.DB_TYPE_BOOLEAN comparisons" "1505 - test cx_Oracle.DB_TYPE_BOOLEAN comparisons"
self.assertEqual(cx_Oracle.DB_TYPE_BOOLEAN, cx_Oracle.BOOLEAN) self.assertEqual(cx_Oracle.DB_TYPE_BOOLEAN, cx_Oracle.BOOLEAN)
def testChar(self): def test_1506_Char(self):
"test cx_Oracle.DB_TYPE_CHAR comparisons" "1506 - test cx_Oracle.DB_TYPE_CHAR comparisons"
self.__testCompare(cx_Oracle.DB_TYPE_CHAR, cx_Oracle.STRING) self.__testCompare(cx_Oracle.DB_TYPE_CHAR, cx_Oracle.STRING)
self.assertEqual(cx_Oracle.DB_TYPE_CHAR, cx_Oracle.FIXED_CHAR) self.assertEqual(cx_Oracle.DB_TYPE_CHAR, cx_Oracle.FIXED_CHAR)
def testClob(self): def test_1507_Clob(self):
"test cx_Oracle.DB_TYPE_CLOB comparisons" "1507 - test cx_Oracle.DB_TYPE_CLOB comparisons"
self.assertEqual(cx_Oracle.DB_TYPE_CLOB, cx_Oracle.CLOB) self.assertEqual(cx_Oracle.DB_TYPE_CLOB, cx_Oracle.CLOB)
def testCursor(self): def test_1508_Cursor(self):
"test cx_Oracle.DB_TYPE_CURSOR comparisons" "1508 - test cx_Oracle.DB_TYPE_CURSOR comparisons"
self.assertEqual(cx_Oracle.DB_TYPE_CURSOR, cx_Oracle.CURSOR) self.assertEqual(cx_Oracle.DB_TYPE_CURSOR, cx_Oracle.CURSOR)
def testDate(self): def test_1509_Date(self):
"test cx_Oracle.DB_TYPE_DATE comparisons" "1509 - test cx_Oracle.DB_TYPE_DATE comparisons"
self.__testCompare(cx_Oracle.DB_TYPE_DATE, cx_Oracle.DATETIME) self.__testCompare(cx_Oracle.DB_TYPE_DATE, cx_Oracle.DATETIME)
def testIntervalDS(self): def test_1510_IntervalDS(self):
"test cx_Oracle.DB_TYPE_INTERVAL_DS comparisons" "1510 - test cx_Oracle.DB_TYPE_INTERVAL_DS comparisons"
self.assertEqual(cx_Oracle.DB_TYPE_INTERVAL_DS, cx_Oracle.INTERVAL) self.assertEqual(cx_Oracle.DB_TYPE_INTERVAL_DS, cx_Oracle.INTERVAL)
def testLong(self): def test_1511_Long(self):
"test cx_Oracle.DB_TYPE_LONG comparisons" "1511 - test cx_Oracle.DB_TYPE_LONG comparisons"
self.__testCompare(cx_Oracle.DB_TYPE_LONG, cx_Oracle.STRING) self.__testCompare(cx_Oracle.DB_TYPE_LONG, cx_Oracle.STRING)
self.assertEqual(cx_Oracle.DB_TYPE_LONG, cx_Oracle.LONG_STRING) self.assertEqual(cx_Oracle.DB_TYPE_LONG, cx_Oracle.LONG_STRING)
def testLongRaw(self): def test_1512_LongRaw(self):
"test cx_Oracle.DB_TYPE_LONG_RAW comparisons" "1512 - test cx_Oracle.DB_TYPE_LONG_RAW comparisons"
self.__testCompare(cx_Oracle.DB_TYPE_LONG_RAW, cx_Oracle.BINARY) self.__testCompare(cx_Oracle.DB_TYPE_LONG_RAW, cx_Oracle.BINARY)
self.assertEqual(cx_Oracle.DB_TYPE_LONG_RAW, cx_Oracle.LONG_BINARY) self.assertEqual(cx_Oracle.DB_TYPE_LONG_RAW, cx_Oracle.LONG_BINARY)
def testNchar(self): def test_1513_Nchar(self):
"test cx_Oracle.DB_TYPE_NCHAR comparisons" "1513 - test cx_Oracle.DB_TYPE_NCHAR comparisons"
self.__testCompare(cx_Oracle.DB_TYPE_NCHAR, cx_Oracle.STRING) self.__testCompare(cx_Oracle.DB_TYPE_NCHAR, cx_Oracle.STRING)
self.assertEqual(cx_Oracle.DB_TYPE_NCHAR, cx_Oracle.FIXED_NCHAR) self.assertEqual(cx_Oracle.DB_TYPE_NCHAR, cx_Oracle.FIXED_NCHAR)
def testNclob(self): def test_1514_Nclob(self):
"test cx_Oracle.DB_TYPE_NCLOB comparisons" "1514 - test cx_Oracle.DB_TYPE_NCLOB comparisons"
self.assertEqual(cx_Oracle.DB_TYPE_NCLOB, cx_Oracle.NCLOB) self.assertEqual(cx_Oracle.DB_TYPE_NCLOB, cx_Oracle.NCLOB)
def testNumber(self): def test_1515_Number(self):
"test cx_Oracle.DB_TYPE_NUMBER comparisons" "1515 - test cx_Oracle.DB_TYPE_NUMBER comparisons"
self.__testCompare(cx_Oracle.DB_TYPE_NUMBER, cx_Oracle.NUMBER) self.__testCompare(cx_Oracle.DB_TYPE_NUMBER, cx_Oracle.NUMBER)
def testNvarchar(self): def test_1516_Nvarchar(self):
"test cx_Oracle.DB_TYPE_NVARCHAR comparisons" "1516 - test cx_Oracle.DB_TYPE_NVARCHAR comparisons"
self.__testCompare(cx_Oracle.DB_TYPE_NVARCHAR, cx_Oracle.STRING) self.__testCompare(cx_Oracle.DB_TYPE_NVARCHAR, cx_Oracle.STRING)
self.assertEqual(cx_Oracle.DB_TYPE_NVARCHAR, cx_Oracle.NCHAR) self.assertEqual(cx_Oracle.DB_TYPE_NVARCHAR, cx_Oracle.NCHAR)
def testObject(self): def test_1517_Object(self):
"test cx_Oracle.DB_TYPE_OBJECT comparisons" "1517 - test cx_Oracle.DB_TYPE_OBJECT comparisons"
self.assertEqual(cx_Oracle.DB_TYPE_OBJECT, cx_Oracle.OBJECT) self.assertEqual(cx_Oracle.DB_TYPE_OBJECT, cx_Oracle.OBJECT)
def testRaw(self): def test_1518_Raw(self):
"test cx_Oracle.DB_TYPE_RAW comparisons" "1518 - test cx_Oracle.DB_TYPE_RAW comparisons"
self.__testCompare(cx_Oracle.DB_TYPE_RAW, cx_Oracle.BINARY) self.__testCompare(cx_Oracle.DB_TYPE_RAW, cx_Oracle.BINARY)
def testRowid(self): def test_1519_Rowid(self):
"test cx_Oracle.DB_TYPE_ROWID comparisons" "1519 - test cx_Oracle.DB_TYPE_ROWID comparisons"
self.__testCompare(cx_Oracle.DB_TYPE_ROWID, cx_Oracle.ROWID) self.__testCompare(cx_Oracle.DB_TYPE_ROWID, cx_Oracle.ROWID)
def testTimestamp(self): def test_1520_Timestamp(self):
"test cx_Oracle.DB_TYPE_TIMESTAMP comparisons" "1520 - test cx_Oracle.DB_TYPE_TIMESTAMP comparisons"
self.__testCompare(cx_Oracle.DB_TYPE_TIMESTAMP, cx_Oracle.DATETIME) self.__testCompare(cx_Oracle.DB_TYPE_TIMESTAMP, cx_Oracle.DATETIME)
self.assertEqual(cx_Oracle.DB_TYPE_TIMESTAMP, cx_Oracle.TIMESTAMP) self.assertEqual(cx_Oracle.DB_TYPE_TIMESTAMP, cx_Oracle.TIMESTAMP)
def testTimestampLTZ(self): def test_1521_TimestampLTZ(self):
"test cx_Oracle.DB_TYPE_TIMESTAMP_LTZ comparisons" "1521 - test cx_Oracle.DB_TYPE_TIMESTAMP_LTZ comparisons"
self.__testCompare(cx_Oracle.DB_TYPE_TIMESTAMP_LTZ, cx_Oracle.DATETIME) self.__testCompare(cx_Oracle.DB_TYPE_TIMESTAMP_LTZ, cx_Oracle.DATETIME)
def testTimestampTZ(self): def test_1522_TimestampTZ(self):
"test cx_Oracle.DB_TYPE_TIMESTAMP_TZ comparisons" "1522 - test cx_Oracle.DB_TYPE_TIMESTAMP_TZ comparisons"
self.__testCompare(cx_Oracle.DB_TYPE_TIMESTAMP_TZ, cx_Oracle.DATETIME) self.__testCompare(cx_Oracle.DB_TYPE_TIMESTAMP_TZ, cx_Oracle.DATETIME)
def testVarchar(self): def test_1523_Varchar(self):
"test cx_Oracle.DB_TYPE_VARCHAR comparisons" "1523 - test cx_Oracle.DB_TYPE_VARCHAR comparisons"
self.__testCompare(cx_Oracle.DB_TYPE_VARCHAR, cx_Oracle.STRING) self.__testCompare(cx_Oracle.DB_TYPE_VARCHAR, cx_Oracle.STRING)

View File

@ -1,8 +1,10 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing DML returning clauses.""" """
1600 - Module for testing DML returning clauses
"""
import TestEnv import TestEnv
@ -10,8 +12,8 @@ import cx_Oracle
class TestCase(TestEnv.BaseTestCase): class TestCase(TestEnv.BaseTestCase):
def testInsert(self): def test_1600_Insert(self):
"test insert statement (single row) with DML returning" "1600 - test insert (single row) with DML returning"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
intVal = 5 intVal = 5
strVal = "A test string" strVal = "A test string"
@ -28,8 +30,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(intVar.values, [[intVal]]) self.assertEqual(intVar.values, [[intVal]])
self.assertEqual(strVar.values, [[strVal]]) self.assertEqual(strVar.values, [[strVal]])
def testInsertMany(self): def test_1601_InsertMany(self):
"test insert statement (multiple rows) with DML returning" "1601 - test insert (multiple rows) with DML returning"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
intValues = [5, 8, 17, 24, 6] intValues = [5, 8, 17, 24, 6]
strValues = ["Test 5", "Test 8", "Test 17", "Test 24", "Test 6"] strValues = ["Test 5", "Test 8", "Test 17", "Test 24", "Test 6"]
@ -44,8 +46,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(intVar.values, [[v] for v in intValues]) self.assertEqual(intVar.values, [[v] for v in intValues])
self.assertEqual(strVar.values, [[v] for v in strValues]) self.assertEqual(strVar.values, [[v] for v in strValues])
def testInsertWithSmallSize(self): def test_1602_InsertWithSmallSize(self):
"test insert statement with DML returning into too small a variable" "1602 - test insert with DML returning into too small a variable"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
intVal = 6 intVal = 6
strVal = "A different test string" strVal = "A different test string"
@ -59,8 +61,8 @@ class TestCase(TestEnv.BaseTestCase):
returning IntCol, StringCol into :intVar, :strVar""", returning IntCol, StringCol into :intVar, :strVar""",
parameters) parameters)
def testUpdateSingleRow(self): def test_1603_UpdateSingleRow(self):
"test update single row statement with DML returning" "1603 - test update single row with DML returning"
intVal = 7 intVal = 7
strVal = "The updated value of the string" strVal = "The updated value of the string"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
@ -82,8 +84,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(intVar.values, [[intVal]]) self.assertEqual(intVar.values, [[intVal]])
self.assertEqual(strVar.values, [[strVal]]) self.assertEqual(strVar.values, [[strVal]])
def testUpdateNoRows(self): def test_1604_UpdateNoRows(self):
"test update no rows statement with DML returning" "1604 - test update no rows with DML returning"
intVal = 8 intVal = 8
strVal = "The updated value of the string" strVal = "The updated value of the string"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
@ -107,8 +109,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(intVar.getvalue(), []) self.assertEqual(intVar.getvalue(), [])
self.assertEqual(strVar.getvalue(), []) self.assertEqual(strVar.getvalue(), [])
def testUpdateMultipleRows(self): def test_1605_UpdateMultipleRows(self):
"test update multiple rows statement with DML returning" "1605 - test update multiple rows with DML returning"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
for i in (8, 9, 10): for i in (8, 9, 10):
self.cursor.execute(""" self.cursor.execute("""
@ -132,8 +134,8 @@ class TestCase(TestEnv.BaseTestCase):
"The final value of string 10" "The final value of string 10"
]]) ]])
def testUpdateMultipleRowsExecuteMany(self): def test_1606_UpdateMultipleRowsExecuteMany(self):
"test update multiple rows with DML returning (executeMany)" "1606 - test update multiple rows with DML returning (executeMany)"
data = [(i, "The initial value of string %d" % i) \ data = [(i, "The initial value of string %d" % i) \
for i in range(1, 11)] for i in range(1, 11)]
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
@ -168,8 +170,8 @@ class TestCase(TestEnv.BaseTestCase):
"Updated value of string 10" ] "Updated value of string 10" ]
]) ])
def testInsertAndReturnObject(self): def test_1607_InsertAndReturnObject(self):
"test inserting an object with DML returning" "1607 - test inserting an object with DML returning"
typeObj = self.connection.gettype("UDT_OBJECT") typeObj = self.connection.gettype("UDT_OBJECT")
stringValue = "The string that will be verified" stringValue = "The string that will be verified"
obj = typeObj.newobject() obj = typeObj.newobject()
@ -185,8 +187,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(result.STRINGVALUE, stringValue) self.assertEqual(result.STRINGVALUE, stringValue)
self.connection.rollback() self.connection.rollback()
def testInsertAndReturnRowid(self): def test_1608_InsertAndReturnRowid(self):
"test inserting a row and returning a rowid" "1608 - test inserting a row and returning a rowid"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
var = self.cursor.var(cx_Oracle.ROWID) var = self.cursor.var(cx_Oracle.ROWID)
self.cursor.execute(""" self.cursor.execute("""
@ -201,8 +203,8 @@ class TestCase(TestEnv.BaseTestCase):
(rowid,)) (rowid,))
self.assertEqual(self.cursor.fetchall(), [(278, 'String 278')]) self.assertEqual(self.cursor.fetchall(), [(278, 'String 278')])
def testInsertWithRefCursor(self): def test_1609_InsertWithRefCursor(self):
"test inserting with a REF cursor and returning a rowid" "1609 - test inserting with a REF cursor and returning a rowid"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
var = self.cursor.var(cx_Oracle.ROWID) var = self.cursor.var(cx_Oracle.ROWID)
inCursor = self.connection.cursor() inCursor = self.connection.cursor()
@ -224,8 +226,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(self.cursor.fetchall(), self.assertEqual(self.cursor.fetchall(),
[(187, 'String 7 (Modified)')]) [(187, 'String 7 (Modified)')])
def testDeleteReturningDecreasingRowsReturned(self): def test_1610_DeleteReturningDecreasingRowsReturned(self):
"test delete returning multiple times with decreasing number of rows" "1610 - test delete returning decreasing number of rows"
data = [(i, "Test String %d" % i) for i in range(1, 11)] data = [(i, "Test String %d" % i) for i in range(1, 11)]
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
self.cursor.executemany(""" self.cursor.executemany("""
@ -242,8 +244,8 @@ class TestCase(TestEnv.BaseTestCase):
results.append(intVar.getvalue()) results.append(intVar.getvalue())
self.assertEqual(results, [ [1, 2, 3, 4], [5, 6, 7], [8, 9] ]) self.assertEqual(results, [ [1, 2, 3, 4], [5, 6, 7], [8, 9] ])
def testDeleteReturningNoRowsAfterManyRows(self): def test_1611_DeleteReturningNoRowsAfterManyRows(self):
"test delete returning no rows after initially returning many rows" "1611 - test delete returning no rows after returning many rows"
data = [(i, "Test String %d" % i) for i in range(1, 11)] data = [(i, "Test String %d" % i) for i in range(1, 11)]
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
self.cursor.executemany(""" self.cursor.executemany("""
@ -260,4 +262,3 @@ class TestCase(TestEnv.BaseTestCase):
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -1,5 +1,5 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
# #
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -7,7 +7,9 @@
# Canada. All rights reserved. # Canada. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing error objects.""" """
1700 - Module for testing error objects
"""
import TestEnv import TestEnv
@ -16,15 +18,15 @@ import pickle
class TestCase(TestEnv.BaseTestCase): class TestCase(TestEnv.BaseTestCase):
def testParseError(self): def test_1700_ParseError(self):
"test parse error returns offset correctly" "1700 - test parse error returns offset correctly"
with self.assertRaises(cx_Oracle.Error) as cm: with self.assertRaises(cx_Oracle.Error) as cm:
self.cursor.execute("begin t_Missing := 5; end;") self.cursor.execute("begin t_Missing := 5; end;")
errorObj, = cm.exception.args errorObj, = cm.exception.args
self.assertEqual(errorObj.offset, 6) self.assertEqual(errorObj.offset, 6)
def testPickleError(self): def test_1701_PickleError(self):
"test picking/unpickling an error object" "1701 - test picking/unpickling an error object"
with self.assertRaises(cx_Oracle.Error) as cm: with self.assertRaises(cx_Oracle.Error) as cm:
self.cursor.execute(""" self.cursor.execute("""
begin begin

View File

@ -7,7 +7,9 @@
# Canada. All rights reserved. # Canada. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing interval variables.""" """
1800 - Module for testing interval variables
"""
import TestEnv import TestEnv
@ -32,8 +34,8 @@ class TestCase(TestEnv.BaseTestCase):
self.rawData.append(tuple) self.rawData.append(tuple)
self.dataByKey[i] = tuple self.dataByKey[i] = tuple
def testBindInterval(self): def test_1800_BindInterval(self):
"test binding in an interval" "1800 - test binding in an interval"
self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_INTERVAL_DS) self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_INTERVAL_DS)
self.cursor.execute(""" self.cursor.execute("""
select * from TestIntervals select * from TestIntervals
@ -42,8 +44,8 @@ class TestCase(TestEnv.BaseTestCase):
seconds = 15)) seconds = 15))
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[5]]) self.assertEqual(self.cursor.fetchall(), [self.dataByKey[5]])
def testBindNull(self): def test_1801_BindNull(self):
"test binding in a null" "1801 - test binding in a null"
self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_INTERVAL_DS) self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_INTERVAL_DS)
self.cursor.execute(""" self.cursor.execute("""
select * from TestIntervals select * from TestIntervals
@ -51,8 +53,8 @@ class TestCase(TestEnv.BaseTestCase):
value = None) value = None)
self.assertEqual(self.cursor.fetchall(), []) self.assertEqual(self.cursor.fetchall(), [])
def testBindOutSetInputSizes(self): def test_1802_BindOutSetInputSizes(self):
"test binding out with set input sizes defined" "1802 - test binding out with set input sizes defined"
vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_INTERVAL_DS) vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_INTERVAL_DS)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -62,8 +64,8 @@ class TestCase(TestEnv.BaseTestCase):
datetime.timedelta(days = 8, hours = 9, minutes = 24, datetime.timedelta(days = 8, hours = 9, minutes = 24,
seconds = 18, microseconds = 123789)) seconds = 18, microseconds = 123789))
def testBindInOutSetInputSizes(self): def test_1803_BindInOutSetInputSizes(self):
"test binding in/out with set input sizes defined" "1803 - test binding in/out with set input sizes defined"
vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_INTERVAL_DS) vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_INTERVAL_DS)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -73,8 +75,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(vars["value"].getvalue(), self.assertEqual(vars["value"].getvalue(),
datetime.timedelta(days = 10, hours = 10, minutes = 45)) datetime.timedelta(days = 10, hours = 10, minutes = 45))
def testBindInOutFractionalSecond(self): def test_1804_BindInOutFractionalSecond(self):
"test binding in/out with set input sizes defined" "1804 - test binding in/out with set input sizes defined"
vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_INTERVAL_DS) vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_INTERVAL_DS)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -85,8 +87,8 @@ class TestCase(TestEnv.BaseTestCase):
datetime.timedelta(days = 10, hours = 8, minutes = 30, datetime.timedelta(days = 10, hours = 8, minutes = 30,
seconds=12, microseconds=123789)) seconds=12, microseconds=123789))
def testBindOutVar(self): def test_1805_BindOutVar(self):
"test binding out with cursor.var() method" "1805 - test binding out with cursor.var() method"
var = self.cursor.var(cx_Oracle.DB_TYPE_INTERVAL_DS) var = self.cursor.var(cx_Oracle.DB_TYPE_INTERVAL_DS)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -97,8 +99,8 @@ class TestCase(TestEnv.BaseTestCase):
datetime.timedelta(days = 15, hours = 18, minutes = 35, datetime.timedelta(days = 15, hours = 18, minutes = 35,
seconds = 45, milliseconds = 586)) seconds = 45, milliseconds = 586))
def testBindInOutVarDirectSet(self): def test_1806_BindInOutVarDirectSet(self):
"test binding in/out with cursor.var() method" "1806 - test binding in/out with cursor.var() method"
var = self.cursor.var(cx_Oracle.DB_TYPE_INTERVAL_DS) var = self.cursor.var(cx_Oracle.DB_TYPE_INTERVAL_DS)
var.setvalue(0, datetime.timedelta(days = 1, minutes = 50)) var.setvalue(0, datetime.timedelta(days = 1, minutes = 50))
self.cursor.execute(""" self.cursor.execute("""
@ -109,8 +111,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(var.getvalue(), self.assertEqual(var.getvalue(),
datetime.timedelta(days = 9, hours = 6, minutes = 5)) datetime.timedelta(days = 9, hours = 6, minutes = 5))
def testCursorDescription(self): def test_1807_CursorDescription(self):
"test cursor description is accurate" "1807 - test cursor description is accurate"
self.cursor.execute("select * from TestIntervals") self.cursor.execute("select * from TestIntervals")
self.assertEqual(self.cursor.description, self.assertEqual(self.cursor.description,
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0), [ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
@ -119,14 +121,14 @@ class TestCase(TestEnv.BaseTestCase):
('NULLABLECOL', cx_Oracle.DB_TYPE_INTERVAL_DS, None, None, 2, ('NULLABLECOL', cx_Oracle.DB_TYPE_INTERVAL_DS, None, None, 2,
6, 1) ]) 6, 1) ])
def testFetchAll(self): def test_1808_FetchAll(self):
"test that fetching all of the data returns the correct results" "1808 - test that fetching all of the data returns the correct results"
self.cursor.execute("select * From TestIntervals order by IntCol") self.cursor.execute("select * From TestIntervals order by IntCol")
self.assertEqual(self.cursor.fetchall(), self.rawData) self.assertEqual(self.cursor.fetchall(), self.rawData)
self.assertEqual(self.cursor.fetchall(), []) self.assertEqual(self.cursor.fetchall(), [])
def testFetchMany(self): def test_1809_FetchMany(self):
"test that fetching data in chunks returns the correct results" "1809 - test that fetching data in chunks returns the correct results"
self.cursor.execute("select * From TestIntervals order by IntCol") self.cursor.execute("select * From TestIntervals order by IntCol")
self.assertEqual(self.cursor.fetchmany(3), self.rawData[0:3]) 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(2), self.rawData[3:5])
@ -134,8 +136,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:]) self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:])
self.assertEqual(self.cursor.fetchmany(3), []) self.assertEqual(self.cursor.fetchmany(3), [])
def testFetchOne(self): def test_1810_FetchOne(self):
"test that fetching a single row returns the correct results" "1810 - test that fetching a single row returns the correct results"
self.cursor.execute(""" self.cursor.execute("""
select * select *
from TestIntervals from TestIntervals
@ -147,4 +149,3 @@ class TestCase(TestEnv.BaseTestCase):
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -7,7 +7,9 @@
# Canada. All rights reserved. # Canada. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing LOB (CLOB and BLOB) variables.""" """
1900 - Module for testing LOB (CLOB and BLOB) variables
"""
import TestEnv import TestEnv
@ -147,8 +149,8 @@ class TestCase(TestEnv.BaseTestCase):
string = prevChar * 5 + char * 5 string = prevChar * 5 + char * 5
self.assertEqual(lob.read(offset, 10), string) self.assertEqual(lob.read(offset, 10), string)
def testBindLobValue(self): def test_1900_BindLobValue(self):
"test binding a LOB value directly" "1900 - test binding a LOB value directly"
self.cursor.execute("truncate table TestCLOBs") self.cursor.execute("truncate table TestCLOBs")
self.cursor.execute("insert into TestCLOBs values (1, 'Short value')") self.cursor.execute("insert into TestCLOBs values (1, 'Short value')")
self.cursor.execute("select ClobCol from TestCLOBs") self.cursor.execute("select ClobCol from TestCLOBs")
@ -156,83 +158,83 @@ class TestCase(TestEnv.BaseTestCase):
self.cursor.execute("insert into TestCLOBs values (2, :value)", self.cursor.execute("insert into TestCLOBs values (2, :value)",
value = lob) value = lob)
def testBLOBCursorDescription(self): def test_1901_BLOBCursorDescription(self):
"test cursor description is accurate for BLOBs" "1901 - test cursor description is accurate for BLOBs"
self.cursor.execute("select * from TestBLOBs") self.cursor.execute("select * from TestBLOBs")
self.assertEqual(self.cursor.description, self.assertEqual(self.cursor.description,
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0), [ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
('BLOBCOL', cx_Oracle.DB_TYPE_BLOB, None, None, None, None, ('BLOBCOL', cx_Oracle.DB_TYPE_BLOB, None, None, None, None,
0) ]) 0) ])
def testBLOBsDirect(self): def test_1902_BLOBsDirect(self):
"test binding and fetching BLOB data (directly)" "1902 - test binding and fetching BLOB data (directly)"
self.__PerformTest("BLOB", cx_Oracle.DB_TYPE_BLOB) self.__PerformTest("BLOB", cx_Oracle.DB_TYPE_BLOB)
def testBLOBsIndirect(self): def test_1903_BLOBsIndirect(self):
"test binding and fetching BLOB data (indirectly)" "1903 - test binding and fetching BLOB data (indirectly)"
self.__PerformTest("BLOB", cx_Oracle.DB_TYPE_LONG_RAW) self.__PerformTest("BLOB", cx_Oracle.DB_TYPE_LONG_RAW)
def testBLOBOperations(self): def test_1904_BLOBOperations(self):
"test operations on BLOBs" "1904 - test operations on BLOBs"
self.__TestLobOperations("BLOB") self.__TestLobOperations("BLOB")
def testCLOBCursorDescription(self): def test_1905_CLOBCursorDescription(self):
"test cursor description is accurate for CLOBs" "1905 - test cursor description is accurate for CLOBs"
self.cursor.execute("select * from TestCLOBs") self.cursor.execute("select * from TestCLOBs")
self.assertEqual(self.cursor.description, self.assertEqual(self.cursor.description,
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0), [ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
('CLOBCOL', cx_Oracle.DB_TYPE_CLOB, None, None, None, None, ('CLOBCOL', cx_Oracle.DB_TYPE_CLOB, None, None, None, None,
0) ]) 0) ])
def testCLOBsDirect(self): def test_1906_CLOBsDirect(self):
"test binding and fetching CLOB data (directly)" "1906 - test binding and fetching CLOB data (directly)"
self.__PerformTest("CLOB", cx_Oracle.DB_TYPE_CLOB) self.__PerformTest("CLOB", cx_Oracle.DB_TYPE_CLOB)
def testCLOBsIndirect(self): def test_1907_CLOBsIndirect(self):
"test binding and fetching CLOB data (indirectly)" "1907 - test binding and fetching CLOB data (indirectly)"
self.__PerformTest("CLOB", cx_Oracle.DB_TYPE_LONG) self.__PerformTest("CLOB", cx_Oracle.DB_TYPE_LONG)
def testCLOBOperations(self): def test_1908_CLOBOperations(self):
"test operations on CLOBs" "1908 - test operations on CLOBs"
self.__TestLobOperations("CLOB") self.__TestLobOperations("CLOB")
def testCreateBlob(self): def test_1909_CreateBlob(self):
"test creating a temporary BLOB" "1909 - test creating a temporary BLOB"
self.__TestTemporaryLOB("BLOB") self.__TestTemporaryLOB("BLOB")
def testCreateClob(self): def test_1910_CreateClob(self):
"test creating a temporary CLOB" "1910 - test creating a temporary CLOB"
self.__TestTemporaryLOB("CLOB") self.__TestTemporaryLOB("CLOB")
def testCreateNclob(self): def test_1911_CreateNclob(self):
"test creating a temporary NCLOB" "1911 - test creating a temporary NCLOB"
self.__TestTemporaryLOB("NCLOB") self.__TestTemporaryLOB("NCLOB")
def testMultipleFetch(self): def test_1912_MultipleFetch(self):
"test retrieving data from a CLOB after multiple fetches" "1912 - test retrieving data from a CLOB after multiple fetches"
self.cursor.arraysize = 1 self.cursor.arraysize = 1
self.cursor.execute("select * from TestCLOBS") self.cursor.execute("select * from TestCLOBS")
rows = self.cursor.fetchall() rows = self.cursor.fetchall()
self.__ValidateQuery(rows, "CLOB") self.__ValidateQuery(rows, "CLOB")
def testNCLOBCursorDescription(self): def test_1913_NCLOBCursorDescription(self):
"test cursor description is accurate for NCLOBs" "1913 - test cursor description is accurate for NCLOBs"
self.cursor.execute("select * from TestNCLOBs") self.cursor.execute("select * from TestNCLOBs")
self.assertEqual(self.cursor.description, self.assertEqual(self.cursor.description,
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0), [ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
('NCLOBCOL', cx_Oracle.DB_TYPE_NCLOB, None, None, None, None, ('NCLOBCOL', cx_Oracle.DB_TYPE_NCLOB, None, None, None, None,
0) ]) 0) ])
def testNCLOBsDirect(self): def test_1914_NCLOBsDirect(self):
"test binding and fetching NCLOB data (directly)" "1914 - test binding and fetching NCLOB data (directly)"
self.__PerformTest("NCLOB", cx_Oracle.DB_TYPE_NCLOB) self.__PerformTest("NCLOB", cx_Oracle.DB_TYPE_NCLOB)
def testNCLOBDifferentEncodings(self): def test_1915_NCLOBDifferentEncodings(self):
"test binding and fetching NCLOB data (different encodings)" "1915 - test binding and fetching NCLOB data (different encodings)"
connection = cx_Oracle.connect(TestEnv.GetMainUser(), connection = cx_Oracle.connect(TestEnv.GetMainUser(),
TestEnv.GetMainPassword(), TestEnv.GetConnectString(), TestEnv.GetMainPassword(), TestEnv.GetConnectString(),
encoding = "UTF-8", nencoding = "UTF-16") encoding = "UTF-8", nencoding = "UTF-16")
value = u"\u03b4\u4e2a" value = "\u03b4\u4e2a"
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("truncate table TestNCLOBs") cursor.execute("truncate table TestNCLOBs")
cursor.setinputsizes(val = cx_Oracle.DB_TYPE_NVARCHAR) cursor.setinputsizes(val = cx_Oracle.DB_TYPE_NVARCHAR)
@ -246,16 +248,16 @@ class TestCase(TestEnv.BaseTestCase):
nclob, = cursor.fetchone() nclob, = cursor.fetchone()
self.assertEqual(nclob.read(), value + value) self.assertEqual(nclob.read(), value + value)
def testNCLOBsIndirect(self): def test_1916_NCLOBsIndirect(self):
"test binding and fetching NCLOB data (indirectly)" "1916 - test binding and fetching NCLOB data (indirectly)"
self.__PerformTest("NCLOB", cx_Oracle.DB_TYPE_LONG) self.__PerformTest("NCLOB", cx_Oracle.DB_TYPE_LONG)
def testNCLOBOperations(self): def test_1917_NCLOBOperations(self):
"test operations on NCLOBs" "1917 - test operations on NCLOBs"
self.__TestLobOperations("NCLOB") self.__TestLobOperations("NCLOB")
def testTemporaryLobs(self): def test_1918_TemporaryLobs(self):
"test temporary LOBs" "1918 - test temporary LOBs"
cursor = self.connection.cursor() cursor = self.connection.cursor()
cursor.arraysize = self.cursor.arraysize cursor.arraysize = self.cursor.arraysize
cursor.execute(""" cursor.execute("""
@ -274,11 +276,10 @@ class TestCase(TestEnv.BaseTestCase):
tempLobs = self.__GetTempLobs(sid) tempLobs = self.__GetTempLobs(sid)
self.assertEqual(tempLobs, 0) self.assertEqual(tempLobs, 0)
def testAssignStringBeyondArraySize(self): def test_1919_AssignStringBeyondArraySize(self):
"test assign string to NCLOB beyond array size" "1919 - test assign string to NCLOB beyond array size"
nclobVar = self.cursor.var(cx_Oracle.DB_TYPE_NCLOB) nclobVar = self.cursor.var(cx_Oracle.DB_TYPE_NCLOB)
self.assertRaises(IndexError, nclobVar.setvalue, 1, "test char") self.assertRaises(IndexError, nclobVar.setvalue, 1, "test char")
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -1,5 +1,5 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
# #
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -7,7 +7,9 @@
# Canada. All rights reserved. # Canada. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing long and long raw variables.""" """
2000 - Module for testing long and long raw variables
"""
import TestEnv import TestEnv
@ -57,12 +59,12 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(len(fetchedValue), integerValue * 25000) self.assertEqual(len(fetchedValue), integerValue * 25000)
self.assertEqual(fetchedValue, actualValue) self.assertEqual(fetchedValue, actualValue)
def testLongs(self): def test_2000_Longs(self):
"test binding and fetching long data" "2000 - test binding and fetching long data"
self.__PerformTest("Long", cx_Oracle.DB_TYPE_LONG) self.__PerformTest("Long", cx_Oracle.DB_TYPE_LONG)
def testLongWithExecuteMany(self): def test_2001_LongWithExecuteMany(self):
"test binding long data with executemany()" "2001 - test binding long data with executemany()"
data = [] data = []
self.cursor.execute("truncate table TestLongs") self.cursor.execute("truncate table TestLongs")
for i in range(5): for i in range(5):
@ -75,32 +77,31 @@ class TestCase(TestEnv.BaseTestCase):
fetchedData = self.cursor.fetchall() fetchedData = self.cursor.fetchall()
self.assertEqual(fetchedData, data) self.assertEqual(fetchedData, data)
def testLongRaws(self): def test_2002_LongRaws(self):
"test binding and fetching long raw data" "2002 - test binding and fetching long raw data"
self.__PerformTest("LongRaw", cx_Oracle.DB_TYPE_LONG_RAW) self.__PerformTest("LongRaw", cx_Oracle.DB_TYPE_LONG_RAW)
def testLongCursorDescription(self): def test_2003_LongCursorDescription(self):
"test cursor description is accurate for longs" "2003 - test cursor description is accurate for longs"
self.cursor.execute("select * from TestLongs") self.cursor.execute("select * from TestLongs")
self.assertEqual(self.cursor.description, self.assertEqual(self.cursor.description,
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0), [ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
('LONGCOL', cx_Oracle.DB_TYPE_LONG, None, None, None, None, ('LONGCOL', cx_Oracle.DB_TYPE_LONG, None, None, None, None,
0) ]) 0) ])
def testLongRawCursorDescription(self): def test_2004_LongRawCursorDescription(self):
"test cursor description is accurate for long raws" "2004 - test cursor description is accurate for long raws"
self.cursor.execute("select * from TestLongRaws") self.cursor.execute("select * from TestLongRaws")
self.assertEqual(self.cursor.description, self.assertEqual(self.cursor.description,
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0), [ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
('LONGRAWCOL', cx_Oracle.DB_TYPE_LONG_RAW, None, None, None, ('LONGRAWCOL', cx_Oracle.DB_TYPE_LONG_RAW, None, None, None,
None, 0) ]) None, 0) ])
def testArraySizeTooLarge(self): def test_2005_ArraySizeTooLarge(self):
"test array size too large generates an exception" "2005 - test array size too large generates an exception"
self.cursor.arraysize = 268435456 self.cursor.arraysize = 268435456
self.assertRaises(cx_Oracle.DatabaseError, self.cursor.execute, self.assertRaises(cx_Oracle.DatabaseError, self.cursor.execute,
"select * from TestLongRaws") "select * from TestLongRaws")
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -1,5 +1,5 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
# #
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -7,7 +7,9 @@
# Canada. All rights reserved. # Canada. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing NCHAR variables.""" """
2100 - Module for testing NCHAR variables
"""
import TestEnv import TestEnv
@ -20,51 +22,51 @@ class TestCase(TestEnv.BaseTestCase):
self.rawData = [] self.rawData = []
self.dataByKey = {} self.dataByKey = {}
for i in range(1, 11): for i in range(1, 11):
unicodeCol = u"Unicode \u3042 %d" % i unicodeCol = "Unicode \u3042 %d" % i
fixedCharCol = (u"Fixed Unicode %d" % i).ljust(40) fixedCharCol = ("Fixed Unicode %d" % i).ljust(40)
if i % 2: if i % 2:
nullableCol = u"Nullable %d" % i nullableCol = "Nullable %d" % i
else: else:
nullableCol = None nullableCol = None
dataTuple = (i, unicodeCol, fixedCharCol, nullableCol) dataTuple = (i, unicodeCol, fixedCharCol, nullableCol)
self.rawData.append(dataTuple) self.rawData.append(dataTuple)
self.dataByKey[i] = dataTuple self.dataByKey[i] = dataTuple
def testUnicodeLength(self): def test_2100_UnicodeLength(self):
"test value length" "2100 - test value length"
returnValue = self.cursor.var(int) returnValue = self.cursor.var(int)
self.cursor.execute(""" self.cursor.execute("""
begin begin
:retval := LENGTH(:value); :retval := LENGTH(:value);
end;""", end;""",
value = u"InVal \u3042", value = "InVal \u3042",
retval = returnValue) retval = returnValue)
self.assertEqual(returnValue.getvalue(), 7) self.assertEqual(returnValue.getvalue(), 7)
def testBindUnicode(self): def test_2101_BindUnicode(self):
"test binding in a unicode" "2101 - test binding in a unicode"
self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_NVARCHAR) self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_NVARCHAR)
self.cursor.execute(""" self.cursor.execute("""
select * from TestUnicodes select * from TestUnicodes
where UnicodeCol = :value""", where UnicodeCol = :value""",
value = u"Unicode \u3042 5") value = "Unicode \u3042 5")
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[5]]) self.assertEqual(self.cursor.fetchall(), [self.dataByKey[5]])
def testBindDifferentVar(self): def test_2102_BindDifferentVar(self):
"test binding a different variable on second execution" "2102 - test binding a different variable on second execution"
retval_1 = self.cursor.var(cx_Oracle.DB_TYPE_NVARCHAR, 30) retval_1 = self.cursor.var(cx_Oracle.DB_TYPE_NVARCHAR, 30)
retval_2 = self.cursor.var(cx_Oracle.DB_TYPE_NVARCHAR, 30) retval_2 = self.cursor.var(cx_Oracle.DB_TYPE_NVARCHAR, 30)
self.cursor.execute(r"begin :retval := unistr('Called \3042'); end;", self.cursor.execute(r"begin :retval := unistr('Called \3042'); end;",
retval = retval_1) retval = retval_1)
self.assertEqual(retval_1.getvalue(), u"Called \u3042") self.assertEqual(retval_1.getvalue(), "Called \u3042")
self.cursor.execute("begin :retval := 'Called'; end;", self.cursor.execute("begin :retval := 'Called'; end;",
retval = retval_2) retval = retval_2)
self.assertEqual(retval_2.getvalue(), "Called") self.assertEqual(retval_2.getvalue(), "Called")
def testBindUnicodeAfterNumber(self): def test_2103_BindUnicodeAfterNumber(self):
"test binding in a unicode after setting input sizes to a number" "2103 - test binding in a string after setting input sizes to a number"
unicodeVal = self.cursor.var(cx_Oracle.DB_TYPE_NVARCHAR) unicodeVal = self.cursor.var(cx_Oracle.DB_TYPE_NVARCHAR)
unicodeVal.setvalue(0, u"Unicode \u3042 6") unicodeVal.setvalue(0, "Unicode \u3042 6")
self.cursor.setinputsizes(value = cx_Oracle.NUMBER) self.cursor.setinputsizes(value = cx_Oracle.NUMBER)
self.cursor.execute(""" self.cursor.execute("""
select * from TestUnicodes select * from TestUnicodes
@ -72,8 +74,8 @@ class TestCase(TestEnv.BaseTestCase):
value = unicodeVal) value = unicodeVal)
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[6]]) self.assertEqual(self.cursor.fetchall(), [self.dataByKey[6]])
def testBindUnicodeArrayDirect(self): def test_2104_BindUnicodeArrayDirect(self):
"test binding in a unicode array" "2104 - test binding in a unicode array"
returnValue = self.cursor.var(cx_Oracle.NUMBER) returnValue = self.cursor.var(cx_Oracle.NUMBER)
array = [r[1] for r in self.rawData] array = [r[1] for r in self.rawData]
arrayVar = self.cursor.arrayvar(cx_Oracle.DB_TYPE_NVARCHAR, array) arrayVar = self.cursor.arrayvar(cx_Oracle.DB_TYPE_NVARCHAR, array)
@ -87,15 +89,15 @@ class TestCase(TestEnv.BaseTestCase):
integerValue = 5, integerValue = 5,
array = arrayVar) array = arrayVar)
self.assertEqual(returnValue.getvalue(), 116) self.assertEqual(returnValue.getvalue(), 116)
array = [ u"Unicode - \u3042 %d" % i for i in range(15) ] array = [ "Unicode - \u3042 %d" % i for i in range(15) ]
arrayVar = self.cursor.arrayvar(cx_Oracle.DB_TYPE_NVARCHAR, array) arrayVar = self.cursor.arrayvar(cx_Oracle.DB_TYPE_NVARCHAR, array)
self.cursor.execute(statement, self.cursor.execute(statement,
integerValue = 8, integerValue = 8,
array = arrayVar) array = arrayVar)
self.assertEqual(returnValue.getvalue(), 208) self.assertEqual(returnValue.getvalue(), 208)
def testBindUnicodeArrayBySizes(self): def test_2105_BindUnicodeArrayBySizes(self):
"test binding in a unicode array (with setinputsizes)" "2105 - test binding in a unicode array (with setinputsizes)"
returnValue = self.cursor.var(cx_Oracle.NUMBER) returnValue = self.cursor.var(cx_Oracle.NUMBER)
self.cursor.setinputsizes(array = [cx_Oracle.DB_TYPE_NVARCHAR, 10]) self.cursor.setinputsizes(array = [cx_Oracle.DB_TYPE_NVARCHAR, 10])
array = [r[1] for r in self.rawData] array = [r[1] for r in self.rawData]
@ -109,8 +111,8 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(returnValue.getvalue(), 117) self.assertEqual(returnValue.getvalue(), 117)
def testBindUnicodeArrayByVar(self): def test_2106_BindUnicodeArrayByVar(self):
"test binding in a unicode array (with arrayvar)" "2106 - test binding in a unicode array (with arrayvar)"
returnValue = self.cursor.var(cx_Oracle.NUMBER) returnValue = self.cursor.var(cx_Oracle.NUMBER)
array = self.cursor.arrayvar(cx_Oracle.DB_TYPE_NVARCHAR, 10, 20) array = self.cursor.arrayvar(cx_Oracle.DB_TYPE_NVARCHAR, 10, 20)
array.setvalue(0, [r[1] for r in self.rawData]) array.setvalue(0, [r[1] for r in self.rawData])
@ -124,11 +126,11 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(returnValue.getvalue(), 118) self.assertEqual(returnValue.getvalue(), 118)
def testBindInOutUnicodeArrayByVar(self): def test_2107_BindInOutUnicodeArrayByVar(self):
"test binding in/out a unicode array (with arrayvar)" "2107 - test binding in/out a unicode array (with arrayvar)"
array = self.cursor.arrayvar(cx_Oracle.DB_TYPE_NVARCHAR, 10, 100) array = self.cursor.arrayvar(cx_Oracle.DB_TYPE_NVARCHAR, 10, 100)
originalData = [r[1] for r in self.rawData] originalData = [r[1] for r in self.rawData]
format = u"Converted element \u3042 # %d originally had length %d" format = "Converted element \u3042 # %d originally had length %d"
expectedData = [format % (i, len(originalData[i - 1])) \ expectedData = [format % (i, len(originalData[i - 1])) \
for i in range(1, 6)] + originalData[5:] for i in range(1, 6)] + originalData[5:]
array.setvalue(0, originalData) array.setvalue(0, originalData)
@ -140,10 +142,10 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(array.getvalue(), expectedData) self.assertEqual(array.getvalue(), expectedData)
def testBindOutUnicodeArrayByVar(self): def test_2108_BindOutUnicodeArrayByVar(self):
"test binding out a unicode array (with arrayvar)" "2108 - test binding out a unicode array (with arrayvar)"
array = self.cursor.arrayvar(cx_Oracle.DB_TYPE_NVARCHAR, 6, 100) array = self.cursor.arrayvar(cx_Oracle.DB_TYPE_NVARCHAR, 6, 100)
format = u"Test out element \u3042 # %d" format = "Test out element \u3042 # %d"
expectedData = [format % i for i in range(1, 7)] expectedData = [format % i for i in range(1, 7)]
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -153,57 +155,57 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(array.getvalue(), expectedData) self.assertEqual(array.getvalue(), expectedData)
def testBindNull(self): def test_2109_BindNull(self):
"test binding in a null" "2109 - test binding in a null"
self.cursor.execute(""" self.cursor.execute("""
select * from TestUnicodes select * from TestUnicodes
where UnicodeCol = :value""", where UnicodeCol = :value""",
value = None) value = None)
self.assertEqual(self.cursor.fetchall(), []) self.assertEqual(self.cursor.fetchall(), [])
def testBindOutSetInputSizesByType(self): def test_2110_BindOutSetInputSizesByType(self):
"test binding out with set input sizes defined (by type)" "2110 - test binding out with set input sizes defined (by type)"
vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_NVARCHAR) vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_NVARCHAR)
self.cursor.execute(r""" self.cursor.execute(r"""
begin begin
:value := unistr('TSI \3042'); :value := unistr('TSI \3042');
end;""") end;""")
self.assertEqual(vars["value"].getvalue(), u"TSI \u3042") self.assertEqual(vars["value"].getvalue(), "TSI \u3042")
def testBindInOutSetInputSizesByType(self): def test_2111_BindInOutSetInputSizesByType(self):
"test binding in/out with set input sizes defined (by type)" "2111 - test binding in/out with set input sizes defined (by type)"
vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_NVARCHAR) vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_NVARCHAR)
self.cursor.execute(r""" self.cursor.execute(r"""
begin begin
:value := :value || unistr(' TSI \3042'); :value := :value || unistr(' TSI \3042');
end;""", end;""",
value = u"InVal \u3041") value = "InVal \u3041")
self.assertEqual(vars["value"].getvalue(), self.assertEqual(vars["value"].getvalue(),
u"InVal \u3041 TSI \u3042") "InVal \u3041 TSI \u3042")
def testBindOutVar(self): def test_2112_BindOutVar(self):
"test binding out with cursor.var() method" "2112 - test binding out with cursor.var() method"
var = self.cursor.var(cx_Oracle.DB_TYPE_NVARCHAR) var = self.cursor.var(cx_Oracle.DB_TYPE_NVARCHAR)
self.cursor.execute(r""" self.cursor.execute(r"""
begin begin
:value := unistr('TSI (VAR) \3042'); :value := unistr('TSI (VAR) \3042');
end;""", end;""",
value = var) value = var)
self.assertEqual(var.getvalue(), u"TSI (VAR) \u3042") self.assertEqual(var.getvalue(), "TSI (VAR) \u3042")
def testBindInOutVarDirectSet(self): def test_2113_BindInOutVarDirectSet(self):
"test binding in/out with cursor.var() method" "2113 - test binding in/out with cursor.var() method"
var = self.cursor.var(cx_Oracle.DB_TYPE_NVARCHAR) var = self.cursor.var(cx_Oracle.DB_TYPE_NVARCHAR)
var.setvalue(0, u"InVal \u3041") var.setvalue(0, "InVal \u3041")
self.cursor.execute(r""" self.cursor.execute(r"""
begin begin
:value := :value || unistr(' TSI (VAR) \3042'); :value := :value || unistr(' TSI (VAR) \3042');
end;""", end;""",
value = var) value = var)
self.assertEqual(var.getvalue(), u"InVal \u3041 TSI (VAR) \u3042") self.assertEqual(var.getvalue(), "InVal \u3041 TSI (VAR) \u3042")
def testCursorDescription(self): def test_2114_CursorDescription(self):
"test cursor description is accurate" "2114 - test cursor description is accurate"
self.cursor.execute("select * from TestUnicodes") self.cursor.execute("select * from TestUnicodes")
self.assertEqual(self.cursor.description, self.assertEqual(self.cursor.description,
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0), [ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
@ -214,14 +216,14 @@ class TestCase(TestEnv.BaseTestCase):
('NULLABLECOL', cx_Oracle.DB_TYPE_NVARCHAR, 50, 200, None, ('NULLABLECOL', cx_Oracle.DB_TYPE_NVARCHAR, 50, 200, None,
None, 1) ]) None, 1) ])
def testFetchAll(self): def test_2115_FetchAll(self):
"test that fetching all of the data returns the correct results" "2115 - test that fetching all of the data returns the correct results"
self.cursor.execute("select * From TestUnicodes order by IntCol") self.cursor.execute("select * From TestUnicodes order by IntCol")
self.assertEqual(self.cursor.fetchall(), self.rawData) self.assertEqual(self.cursor.fetchall(), self.rawData)
self.assertEqual(self.cursor.fetchall(), []) self.assertEqual(self.cursor.fetchall(), [])
def testFetchMany(self): def test_2116_FetchMany(self):
"test that fetching data in chunks returns the correct results" "2116 - test that fetching data in chunks returns the correct results"
self.cursor.execute("select * From TestUnicodes order by IntCol") self.cursor.execute("select * From TestUnicodes order by IntCol")
self.assertEqual(self.cursor.fetchmany(3), self.rawData[0:3]) 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(2), self.rawData[3:5])
@ -229,8 +231,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:]) self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:])
self.assertEqual(self.cursor.fetchmany(3), []) self.assertEqual(self.cursor.fetchmany(3), [])
def testFetchOne(self): def test_2117_FetchOne(self):
"test that fetching a single row returns the correct results" "2117 - test that fetching a single row returns the correct results"
self.cursor.execute(""" self.cursor.execute("""
select * select *
from TestUnicodes from TestUnicodes
@ -242,4 +244,3 @@ class TestCase(TestEnv.BaseTestCase):
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -7,7 +7,9 @@
# Canada. All rights reserved. # Canada. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing number variables.""" """
2200 - Module for testing number variables
"""
import TestEnv import TestEnv
@ -45,14 +47,14 @@ class TestCase(TestEnv.BaseTestCase):
self.rawData.append(dataTuple) self.rawData.append(dataTuple)
self.dataByKey[i] = dataTuple self.dataByKey[i] = dataTuple
def testBindBoolean(self): def test_2200_BindBoolean(self):
"test binding in a boolean" "2200 - test binding in a boolean"
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str, result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
(True,)) (True,))
self.assertEqual(result, "TRUE") self.assertEqual(result, "TRUE")
def testBindBooleanAsNumber(self): def test_2201_BindBooleanAsNumber(self):
"test binding in a boolean as a number" "2201 - test binding in a boolean as a number"
var = self.cursor.var(cx_Oracle.NUMBER) var = self.cursor.var(cx_Oracle.NUMBER)
var.setvalue(0, True) var.setvalue(0, True)
self.cursor.execute("select :1 from dual", [var]) self.cursor.execute("select :1 from dual", [var])
@ -63,8 +65,8 @@ class TestCase(TestEnv.BaseTestCase):
result, = self.cursor.fetchone() result, = self.cursor.fetchone()
self.assertEqual(result, 0) self.assertEqual(result, 0)
def testBindDecimal(self): def test_2202_BindDecimal(self):
"test binding in a decimal.Decimal" "2202 - test binding in a decimal.Decimal"
self.cursor.execute(""" self.cursor.execute("""
select * from TestNumbers select * from TestNumbers
where NumberCol - :value1 - :value2 = trunc(NumberCol)""", where NumberCol - :value1 - :value2 = trunc(NumberCol)""",
@ -73,8 +75,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(self.cursor.fetchall(), self.assertEqual(self.cursor.fetchall(),
[self.dataByKey[1], self.dataByKey[5], self.dataByKey[9]]) [self.dataByKey[1], self.dataByKey[5], self.dataByKey[9]])
def testBindFloat(self): def test_2203_BindFloat(self):
"test binding in a float" "2203 - test binding in a float"
self.cursor.execute(""" self.cursor.execute("""
select * from TestNumbers select * from TestNumbers
where NumberCol - :value = trunc(NumberCol)""", where NumberCol - :value = trunc(NumberCol)""",
@ -82,16 +84,16 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(self.cursor.fetchall(), self.assertEqual(self.cursor.fetchall(),
[self.dataByKey[1], self.dataByKey[5], self.dataByKey[9]]) [self.dataByKey[1], self.dataByKey[5], self.dataByKey[9]])
def testBindInteger(self): def test_2204_BindInteger(self):
"test binding in an integer" "2204 - test binding in an integer"
self.cursor.execute(""" self.cursor.execute("""
select * from TestNumbers select * from TestNumbers
where IntCol = :value""", where IntCol = :value""",
value = 2) value = 2)
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[2]]) self.assertEqual(self.cursor.fetchall(), [self.dataByKey[2]])
def testBindLargeLongAsOracleNumber(self): def test_2205_BindLargeLongAsOracleNumber(self):
"test binding in a large long integer as Oracle number" "2205 - test binding in a large long integer as Oracle number"
valueVar = self.cursor.var(cx_Oracle.NUMBER) valueVar = self.cursor.var(cx_Oracle.NUMBER)
valueVar.setvalue(0, 6088343244) valueVar.setvalue(0, 6088343244)
self.cursor.execute(""" self.cursor.execute("""
@ -102,15 +104,15 @@ class TestCase(TestEnv.BaseTestCase):
value = valueVar.getvalue() value = valueVar.getvalue()
self.assertEqual(value, 6088343249) self.assertEqual(value, 6088343249)
def testBindLargeLongAsInteger(self): def test_2206_BindLargeLongAsInteger(self):
"test binding in a large long integer as Python integer" "2206 - test binding in a large long integer as Python integer"
longValue = -9999999999999999999 longValue = -9999999999999999999
self.cursor.execute("select :value from dual", value = longValue) self.cursor.execute("select :value from dual", value = longValue)
result, = self.cursor.fetchone() result, = self.cursor.fetchone()
self.assertEqual(result, longValue) self.assertEqual(result, longValue)
def testBindIntegerAfterString(self): def test_2207_BindIntegerAfterString(self):
"test binding in an number after setting input sizes to a string" "2207 - test binding in an integer after setting input sizes to string"
self.cursor.setinputsizes(value = 15) self.cursor.setinputsizes(value = 15)
self.cursor.execute(""" self.cursor.execute("""
select * from TestNumbers select * from TestNumbers
@ -118,8 +120,8 @@ class TestCase(TestEnv.BaseTestCase):
value = 3) value = 3)
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[3]]) self.assertEqual(self.cursor.fetchall(), [self.dataByKey[3]])
def testBindDecimalAfterNumber(self): def test_2208_BindDecimalAfterNumber(self):
"test binding in a decimal value after setting input sizes to a number" "2208 - test binding in a decimal after setting input sizes to number"
cursor = self.connection.cursor() cursor = self.connection.cursor()
value = decimal.Decimal("319438950232418390.273596") value = decimal.Decimal("319438950232418390.273596")
cursor.setinputsizes(value = cx_Oracle.NUMBER) cursor.setinputsizes(value = cx_Oracle.NUMBER)
@ -129,16 +131,16 @@ class TestCase(TestEnv.BaseTestCase):
outValue, = cursor.fetchone() outValue, = cursor.fetchone()
self.assertEqual(outValue, value) self.assertEqual(outValue, value)
def testBindNull(self): def test_2209_BindNull(self):
"test binding in a null" "2209 - test binding in a null"
self.cursor.execute(""" self.cursor.execute("""
select * from TestNumbers select * from TestNumbers
where IntCol = :value""", where IntCol = :value""",
value = None) value = None)
self.assertEqual(self.cursor.fetchall(), []) self.assertEqual(self.cursor.fetchall(), [])
def testBindNumberArrayDirect(self): def test_2210_BindNumberArrayDirect(self):
"test binding in a number array" "2210 - test binding in a number array"
returnValue = self.cursor.var(cx_Oracle.NUMBER) returnValue = self.cursor.var(cx_Oracle.NUMBER)
array = [r[2] for r in self.rawData] array = [r[2] for r in self.rawData]
statement = """ statement = """
@ -157,8 +159,8 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(returnValue.getvalue(), 115.0) self.assertEqual(returnValue.getvalue(), 115.0)
def testBindNumberArrayBySizes(self): def test_2211_BindNumberArrayBySizes(self):
"test binding in a number array (with setinputsizes)" "2211 - test binding in a number array (with setinputsizes)"
returnValue = self.cursor.var(cx_Oracle.NUMBER) returnValue = self.cursor.var(cx_Oracle.NUMBER)
self.cursor.setinputsizes(array = [cx_Oracle.NUMBER, 10]) self.cursor.setinputsizes(array = [cx_Oracle.NUMBER, 10])
array = [r[2] for r in self.rawData] array = [r[2] for r in self.rawData]
@ -172,8 +174,8 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(returnValue.getvalue(), 74.75) self.assertEqual(returnValue.getvalue(), 74.75)
def testBindNumberArrayByVar(self): def test_2212_BindNumberArrayByVar(self):
"test binding in a number array (with arrayvar)" "2212 - test binding in a number array (with arrayvar)"
returnValue = self.cursor.var(cx_Oracle.NUMBER) returnValue = self.cursor.var(cx_Oracle.NUMBER)
array = self.cursor.arrayvar(cx_Oracle.NUMBER, array = self.cursor.arrayvar(cx_Oracle.NUMBER,
[r[2] for r in self.rawData]) [r[2] for r in self.rawData])
@ -187,8 +189,8 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(returnValue.getvalue(), 75.75) self.assertEqual(returnValue.getvalue(), 75.75)
def testBindZeroLengthNumberArrayByVar(self): def test_2213_BindZeroLengthNumberArrayByVar(self):
"test binding in a zero length number array (with arrayvar)" "2213 - test binding in a zero length number array (with arrayvar)"
returnValue = self.cursor.var(cx_Oracle.NUMBER) returnValue = self.cursor.var(cx_Oracle.NUMBER)
array = self.cursor.arrayvar(cx_Oracle.NUMBER, 0) array = self.cursor.arrayvar(cx_Oracle.NUMBER, 0)
self.cursor.execute(""" self.cursor.execute("""
@ -202,8 +204,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(returnValue.getvalue(), 8.0) self.assertEqual(returnValue.getvalue(), 8.0)
self.assertEqual(array.getvalue(), []) self.assertEqual(array.getvalue(), [])
def testBindInOutNumberArrayByVar(self): def test_2214_BindInOutNumberArrayByVar(self):
"test binding in/out a number array (with arrayvar)" "2214 - test binding in/out a number array (with arrayvar)"
array = self.cursor.arrayvar(cx_Oracle.NUMBER, 10) array = self.cursor.arrayvar(cx_Oracle.NUMBER, 10)
originalData = [r[2] for r in self.rawData] originalData = [r[2] for r in self.rawData]
expectedData = [originalData[i - 1] * 10 for i in range(1, 6)] + \ expectedData = [originalData[i - 1] * 10 for i in range(1, 6)] + \
@ -217,8 +219,8 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(array.getvalue(), expectedData) self.assertEqual(array.getvalue(), expectedData)
def testBindOutNumberArrayByVar(self): def test_2215_BindOutNumberArrayByVar(self):
"test binding out a Number array (with arrayvar)" "2215 - test binding out a Number array (with arrayvar)"
array = self.cursor.arrayvar(cx_Oracle.NUMBER, 6) array = self.cursor.arrayvar(cx_Oracle.NUMBER, 6)
expectedData = [i * 100 for i in range(1, 7)] expectedData = [i * 100 for i in range(1, 7)]
self.cursor.execute(""" self.cursor.execute("""
@ -229,8 +231,8 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(array.getvalue(), expectedData) self.assertEqual(array.getvalue(), expectedData)
def testBindOutSetInputSizes(self): def test_2216_BindOutSetInputSizes(self):
"test binding out with set input sizes defined" "2216 - test binding out with set input sizes defined"
vars = self.cursor.setinputsizes(value = cx_Oracle.NUMBER) vars = self.cursor.setinputsizes(value = cx_Oracle.NUMBER)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -238,8 +240,8 @@ class TestCase(TestEnv.BaseTestCase):
end;""") end;""")
self.assertEqual(vars["value"].getvalue(), 5) self.assertEqual(vars["value"].getvalue(), 5)
def testBindInOutSetInputSizes(self): def test_2217_BindInOutSetInputSizes(self):
"test binding in/out with set input sizes defined" "2217 - test binding in/out with set input sizes defined"
vars = self.cursor.setinputsizes(value = cx_Oracle.NUMBER) vars = self.cursor.setinputsizes(value = cx_Oracle.NUMBER)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -248,8 +250,8 @@ class TestCase(TestEnv.BaseTestCase):
value = 1.25) value = 1.25)
self.assertEqual(vars["value"].getvalue(), 6.25) self.assertEqual(vars["value"].getvalue(), 6.25)
def testBindOutVar(self): def test_2218_BindOutVar(self):
"test binding out with cursor.var() method" "2218 - test binding out with cursor.var() method"
var = self.cursor.var(cx_Oracle.NUMBER) var = self.cursor.var(cx_Oracle.NUMBER)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -258,8 +260,8 @@ class TestCase(TestEnv.BaseTestCase):
value = var) value = var)
self.assertEqual(var.getvalue(), 5) self.assertEqual(var.getvalue(), 5)
def testBindInOutVarDirectSet(self): def test_2219_BindInOutVarDirectSet(self):
"test binding in/out with cursor.var() method" "2219 - test binding in/out with cursor.var() method"
var = self.cursor.var(cx_Oracle.NUMBER) var = self.cursor.var(cx_Oracle.NUMBER)
var.setvalue(0, 2.25) var.setvalue(0, 2.25)
self.cursor.execute(""" self.cursor.execute("""
@ -269,8 +271,8 @@ class TestCase(TestEnv.BaseTestCase):
value = var) value = var)
self.assertEqual(var.getvalue(), 7.25) self.assertEqual(var.getvalue(), 7.25)
def testCursorDescription(self): def test_2220_CursorDescription(self):
"test cursor description is accurate" "2220 - test cursor description is accurate"
self.cursor.execute("select * from TestNumbers") self.cursor.execute("select * from TestNumbers")
self.assertEqual(self.cursor.description, self.assertEqual(self.cursor.description,
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0), [ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
@ -283,14 +285,14 @@ class TestCase(TestEnv.BaseTestCase):
('NULLABLECOL', cx_Oracle.DB_TYPE_NUMBER, 39, None, 38, 0, ('NULLABLECOL', cx_Oracle.DB_TYPE_NUMBER, 39, None, 38, 0,
1) ]) 1) ])
def testFetchAll(self): def test_2221_FetchAll(self):
"test that fetching all of the data returns the correct results" "2221 - test that fetching all of the data returns the correct results"
self.cursor.execute("select * From TestNumbers order by IntCol") self.cursor.execute("select * From TestNumbers order by IntCol")
self.assertEqual(self.cursor.fetchall(), self.rawData) self.assertEqual(self.cursor.fetchall(), self.rawData)
self.assertEqual(self.cursor.fetchall(), []) self.assertEqual(self.cursor.fetchall(), [])
def testFetchMany(self): def test_2222_FetchMany(self):
"test that fetching data in chunks returns the correct results" "2222 - test that fetching data in chunks returns the correct results"
self.cursor.execute("select * From TestNumbers order by IntCol") self.cursor.execute("select * From TestNumbers order by IntCol")
self.assertEqual(self.cursor.fetchmany(3), self.rawData[0:3]) 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(2), self.rawData[3:5])
@ -298,8 +300,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:]) self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:])
self.assertEqual(self.cursor.fetchmany(3), []) self.assertEqual(self.cursor.fetchmany(3), [])
def testFetchOne(self): def test_2223_FetchOne(self):
"test that fetching a single row returns the correct results" "2223 - test that fetching a single row returns the correct results"
self.cursor.execute(""" self.cursor.execute("""
select * select *
from TestNumbers from TestNumbers
@ -309,8 +311,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(self.cursor.fetchone(), self.dataByKey[4]) self.assertEqual(self.cursor.fetchone(), self.dataByKey[4])
self.assertEqual(self.cursor.fetchone(), None) self.assertEqual(self.cursor.fetchone(), None)
def testReturnAsLong(self): def test_2224_ReturnAsLong(self):
"test that fetching a long integer returns such in Python" "2224 - test that fetching a long integer returns such in Python"
self.cursor.execute(""" self.cursor.execute("""
select NullableCol select NullableCol
from TestNumbers from TestNumbers
@ -318,21 +320,21 @@ class TestCase(TestEnv.BaseTestCase):
col, = self.cursor.fetchone() col, = self.cursor.fetchone()
self.assertEqual(col, 25004854810776297743) self.assertEqual(col, 25004854810776297743)
def testReturnConstantFloat(self): def test_2225_ReturnConstantFloat(self):
"test that fetching a floating point number returns such in Python" "2225 - test fetching a floating point number returns such in Python"
self.cursor.execute("select 1.25 from dual") self.cursor.execute("select 1.25 from dual")
result, = self.cursor.fetchone() result, = self.cursor.fetchone()
self.assertEqual(result, 1.25) self.assertEqual(result, 1.25)
def testReturnConstantInteger(self): def test_2226_ReturnConstantInteger(self):
"test that fetching an integer returns such in Python" "2226 - test that fetching an integer returns such in Python"
self.cursor.execute("select 148 from dual") self.cursor.execute("select 148 from dual")
result, = self.cursor.fetchone() result, = self.cursor.fetchone()
self.assertEqual(result, 148) self.assertEqual(result, 148)
self.assertTrue(isinstance(result, int), "integer not returned") self.assertTrue(isinstance(result, int), "integer not returned")
def testAcceptableBoundaryNumbers(self): def test_2227_AcceptableBoundaryNumbers(self):
"test that acceptable boundary numbers are handled properly" "2227 - test that acceptable boundary numbers are handled properly"
inValues = [decimal.Decimal("9.99999999999999e+125"), inValues = [decimal.Decimal("9.99999999999999e+125"),
decimal.Decimal("-9.99999999999999e+125"), 0.0, 1e-130, decimal.Decimal("-9.99999999999999e+125"), 0.0, 1e-130,
-1e-130] -1e-130]
@ -343,8 +345,8 @@ class TestCase(TestEnv.BaseTestCase):
result, = self.cursor.fetchone() result, = self.cursor.fetchone()
self.assertEqual(result, outValue) self.assertEqual(result, outValue)
def testUnacceptableBoundaryNumbers(self): def test_2228_UnacceptableBoundaryNumbers(self):
"test that unacceptable boundary numbers are rejected" "2228 - test that unacceptable boundary numbers are rejected"
inValues = [1e126, -1e126, float("inf"), float("-inf"), inValues = [1e126, -1e126, float("inf"), float("-inf"),
float("NaN"), decimal.Decimal("1e126"), float("NaN"), decimal.Decimal("1e126"),
decimal.Decimal("-1e126"), decimal.Decimal("inf"), decimal.Decimal("-1e126"), decimal.Decimal("inf"),
@ -360,8 +362,8 @@ class TestCase(TestEnv.BaseTestCase):
method(cx_Oracle.DatabaseError, error, self.cursor.execute, method(cx_Oracle.DatabaseError, error, self.cursor.execute,
"select :1 from dual", (inValue,)) "select :1 from dual", (inValue,))
def testReturnFloatFromDivision(self): def test_2229_ReturnFloatFromDivision(self):
"test that fetching the result of division returns a float" "2229 - test that fetching the result of division returns a float"
self.cursor.execute(""" self.cursor.execute("""
select IntCol / 7 select IntCol / 7
from TestNumbers from TestNumbers
@ -370,8 +372,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(result, 1.0 / 7.0) self.assertEqual(result, 1.0 / 7.0)
self.assertTrue(isinstance(result, float), "float not returned") self.assertTrue(isinstance(result, float), "float not returned")
def testStringFormat(self): def test_2230_StringFormat(self):
"test that string format is returned properly" "2230 - test that string format is returned properly"
var = self.cursor.var(cx_Oracle.NUMBER) var = self.cursor.var(cx_Oracle.NUMBER)
self.assertEqual(str(var), self.assertEqual(str(var),
"<cx_Oracle.Var of type DB_TYPE_NUMBER with value None>") "<cx_Oracle.Var of type DB_TYPE_NUMBER with value None>")
@ -379,8 +381,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(str(var), self.assertEqual(str(var),
"<cx_Oracle.Var of type DB_TYPE_NUMBER with value 4.0>") "<cx_Oracle.Var of type DB_TYPE_NUMBER with value 4.0>")
def testBindNativeFloat(self): def test_2231_BindNativeFloat(self):
"test that binding native float is possible" "2231 - test that binding native float is possible"
self.cursor.setinputsizes(cx_Oracle.DB_TYPE_BINARY_DOUBLE) self.cursor.setinputsizes(cx_Oracle.DB_TYPE_BINARY_DOUBLE)
self.cursor.execute("select :1 from dual", (5,)) self.cursor.execute("select :1 from dual", (5,))
self.assertEqual(self.cursor.bindvars[0].type, self.assertEqual(self.cursor.bindvars[0].type,
@ -398,8 +400,8 @@ class TestCase(TestEnv.BaseTestCase):
value, = self.cursor.fetchone() value, = self.cursor.fetchone()
self.assertEqual(str(value), str(float("NaN"))) self.assertEqual(str(value), str(float("NaN")))
def testFetchNativeInt(self): def test_2232_FetchNativeInt(self):
"test fetching numbers as native integers" "2232 - test fetching numbers as native integers"
self.cursor.outputtypehandler = self.outputTypeHandlerNativeInt self.cursor.outputtypehandler = self.outputTypeHandlerNativeInt
for value in (1, 2 ** 31, 2 ** 63 - 1, -1, -2 ** 31, -2 ** 63 + 1): for value in (1, 2 ** 31, 2 ** 63 - 1, -1, -2 ** 31, -2 ** 63 + 1):
self.cursor.execute("select :1 from dual", [str(value)]) self.cursor.execute("select :1 from dual", [str(value)])

View File

@ -7,7 +7,9 @@
# Canada. All rights reserved. # Canada. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing object variables.""" """
2300 - Module for testing object variables
"""
import TestEnv import TestEnv
@ -48,16 +50,16 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(objectValue, expectedObjectValue) self.assertEqual(objectValue, expectedObjectValue)
self.assertEqual(arrayValue, expectedArrayValue) self.assertEqual(arrayValue, expectedArrayValue)
def testBindNullIn(self): def test_2300_BindNullIn(self):
"test binding a null value (IN)" "2300 - test binding a null value (IN)"
var = self.cursor.var(cx_Oracle.DB_TYPE_OBJECT, var = self.cursor.var(cx_Oracle.DB_TYPE_OBJECT,
typename = "UDT_OBJECT") typename = "UDT_OBJECT")
result = self.cursor.callfunc("pkg_TestBindObject.GetStringRep", str, result = self.cursor.callfunc("pkg_TestBindObject.GetStringRep", str,
(var,)) (var,))
self.assertEqual(result, "null") self.assertEqual(result, "null")
def testBindObjectIn(self): def test_2301_BindObjectIn(self):
"test binding an object (IN)" "2301 - test binding an object (IN)"
typeObj = self.connection.gettype("UDT_OBJECT") typeObj = self.connection.gettype("UDT_OBJECT")
obj = typeObj.newobject() obj = typeObj.newobject()
obj.NUMBERVALUE = 13 obj.NUMBERVALUE = 13
@ -91,8 +93,8 @@ class TestCase(TestEnv.BaseTestCase):
"udt_Object(null, 'Test With Dates', null, null, null, " \ "udt_Object(null, 'Test With Dates', null, null, null, " \
"udt_SubObject(18.25, 'Sub String'), null)") "udt_SubObject(18.25, 'Sub String'), null)")
def testCopyObject(self): def test_2302_CopyObject(self):
"test copying an object" "2302 - test copying an object"
typeObj = self.connection.gettype("UDT_OBJECT") typeObj = self.connection.gettype("UDT_OBJECT")
obj = typeObj() obj = typeObj()
obj.NUMBERVALUE = 5124 obj.NUMBERVALUE = 5124
@ -105,15 +107,15 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(obj.DATEVALUE, copiedObj.DATEVALUE) self.assertEqual(obj.DATEVALUE, copiedObj.DATEVALUE)
self.assertEqual(obj.TIMESTAMPVALUE, copiedObj.TIMESTAMPVALUE) self.assertEqual(obj.TIMESTAMPVALUE, copiedObj.TIMESTAMPVALUE)
def testEmptyCollectionAsList(self): def test_2303_EmptyCollectionAsList(self):
"test getting an empty collection as a list" "2303 - test getting an empty collection as a list"
typeName = "UDT_ARRAY" typeName = "UDT_ARRAY"
typeObj = self.connection.gettype(typeName) typeObj = self.connection.gettype(typeName)
obj = typeObj.newobject() obj = typeObj.newobject()
self.assertEqual(obj.aslist(), []) self.assertEqual(obj.aslist(), [])
def testFetchData(self): def test_2304_FetchData(self):
"test fetching objects" "2304 - test fetching objects"
self.cursor.execute("alter session set time_zone = 'UTC'") self.cursor.execute("alter session set time_zone = 'UTC'")
self.cursor.execute(""" self.cursor.execute("""
select select
@ -151,8 +153,8 @@ class TestCase(TestEnv.BaseTestCase):
[(10, 'element #1'), (20, 'element #2'), [(10, 'element #1'), (20, 'element #2'),
(30, 'element #3'), (40, 'element #4')]), None) (30, 'element #3'), (40, 'element #4')]), None)
def testGetObjectType(self): def test_2305_GetObjectType(self):
"test getting object type" "2305 - test getting object type"
typeObj = self.connection.gettype("UDT_OBJECT") typeObj = self.connection.gettype("UDT_OBJECT")
self.assertEqual(typeObj.iscollection, False) self.assertEqual(typeObj.iscollection, False)
self.assertEqual(typeObj.schema, self.connection.username.upper()) self.assertEqual(typeObj.schema, self.connection.username.upper())
@ -186,8 +188,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(subObjectArrayType.iscollection, True) self.assertEqual(subObjectArrayType.iscollection, True)
self.assertEqual(subObjectArrayType.attributes, []) self.assertEqual(subObjectArrayType.attributes, [])
def testObjectType(self): def test_2306_ObjectType(self):
"test object type data" "2306 - test object type data"
self.cursor.execute(""" self.cursor.execute("""
select ObjectCol select ObjectCol
from TestObjects from TestObjects
@ -196,11 +198,11 @@ class TestCase(TestEnv.BaseTestCase):
objValue, = self.cursor.fetchone() objValue, = self.cursor.fetchone()
self.assertEqual(objValue.type.schema, self.assertEqual(objValue.type.schema,
self.connection.username.upper()) self.connection.username.upper())
self.assertEqual(objValue.type.name, u"UDT_OBJECT") self.assertEqual(objValue.type.name, "UDT_OBJECT")
self.assertEqual(objValue.type.attributes[0].name, "NUMBERVALUE") self.assertEqual(objValue.type.attributes[0].name, "NUMBERVALUE")
def testRoundTripObject(self): def test_2307_RoundTripObject(self):
"test inserting and then querying object with all data types" "2307 - test inserting and then querying object with all data types"
self.cursor.execute("alter session set time_zone = 'UTC'") self.cursor.execute("alter session set time_zone = 'UTC'")
self.cursor.execute("truncate table TestClobs") self.cursor.execute("truncate table TestClobs")
self.cursor.execute("truncate table TestNClobs") self.cursor.execute("truncate table TestNClobs")
@ -218,7 +220,7 @@ class TestCase(TestEnv.BaseTestCase):
nclob, = self.cursor.fetchone() nclob, = self.cursor.fetchone()
self.cursor.execute("select BLOBCol from TestBlobs") self.cursor.execute("select BLOBCol from TestBlobs")
blob, = self.cursor.fetchone() blob, = self.cursor.fetchone()
typeObj = self.connection.gettype(u"UDT_OBJECT") typeObj = self.connection.gettype("UDT_OBJECT")
obj = typeObj.newobject() obj = typeObj.newobject()
obj.NUMBERVALUE = 5 obj.NUMBERVALUE = 5
obj.STRINGVALUE = "A string" obj.STRINGVALUE = "A string"
@ -279,13 +281,13 @@ class TestCase(TestEnv.BaseTestCase):
(23, 'Substring value'), None), None) (23, 'Substring value'), None), None)
self.connection.rollback() self.connection.rollback()
def testInvalidTypeObject(self): def test_2308_InvalidTypeObject(self):
"test trying to find an object type that does not exist" "2308 - test trying to find an object type that does not exist"
self.assertRaises(cx_Oracle.DatabaseError, self.connection.gettype, self.assertRaises(cx_Oracle.DatabaseError, self.connection.gettype,
"A TYPE THAT DOES NOT EXIST") "A TYPE THAT DOES NOT EXIST")
def testAppendingWrongObjectType(self): def test_2309_AppendingWrongObjectType(self):
"test appending an object of the wrong type to a collection" "2309 - test appending an object of the wrong type to a collection"
collectionObjType = self.connection.gettype("UDT_OBJECTARRAY") collectionObjType = self.connection.gettype("UDT_OBJECTARRAY")
collectionObj = collectionObjType.newobject() collectionObj = collectionObjType.newobject()
arrayObjType = self.connection.gettype("UDT_ARRAY") arrayObjType = self.connection.gettype("UDT_ARRAY")
@ -293,8 +295,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertRaises(cx_Oracle.DatabaseError, collectionObj.append, self.assertRaises(cx_Oracle.DatabaseError, collectionObj.append,
arrayObj) arrayObj)
def testReferencingSubObj(self): def test_2310_ReferencingSubObj(self):
"test that referencing a sub object affects the parent object" "2310 - test that referencing a sub object affects the parent object"
objType = self.connection.gettype("UDT_OBJECT") objType = self.connection.gettype("UDT_OBJECT")
subObjType = self.connection.gettype("UDT_SUBOBJECT") subObjType = self.connection.gettype("UDT_SUBOBJECT")
obj = objType.newobject() obj = objType.newobject()
@ -304,8 +306,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(obj.SUBOBJECTVALUE.SUBNUMBERVALUE, 5) self.assertEqual(obj.SUBOBJECTVALUE.SUBNUMBERVALUE, 5)
self.assertEqual(obj.SUBOBJECTVALUE.SUBSTRINGVALUE, "Substring") self.assertEqual(obj.SUBOBJECTVALUE.SUBSTRINGVALUE, "Substring")
def testAccessSubObjectParentObjectDestroyed(self): def test_2311_AccessSubObjectParentObjectDestroyed(self):
"test that accessing sub object after parent object destroyed works" "2311 - test accessing sub object after parent object destroyed"
objType = self.connection.gettype("UDT_OBJECT") objType = self.connection.gettype("UDT_OBJECT")
subObjType = self.connection.gettype("UDT_SUBOBJECT") subObjType = self.connection.gettype("UDT_SUBOBJECT")
arrayType = self.connection.gettype("UDT_OBJECTARRAY") arrayType = self.connection.gettype("UDT_OBJECTARRAY")
@ -322,8 +324,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(self.__GetObjectAsTuple(subObjArray), self.assertEqual(self.__GetObjectAsTuple(subObjArray),
[(2, "AB"), (3, "CDE")]) [(2, "AB"), (3, "CDE")])
def testSettingAttrWrongObjectType(self): def test_2312_SettingAttrWrongObjectType(self):
"test assigning an object of the wrong type to an object attribute" "2312 - test assigning an object of wrong type to an object attribute"
objType = self.connection.gettype("UDT_OBJECT") objType = self.connection.gettype("UDT_OBJECT")
obj = objType.newobject() obj = objType.newobject()
wrongObjType = self.connection.gettype("UDT_OBJECTARRAY") wrongObjType = self.connection.gettype("UDT_OBJECTARRAY")
@ -331,16 +333,16 @@ class TestCase(TestEnv.BaseTestCase):
self.assertRaises(cx_Oracle.DatabaseError, setattr, obj, self.assertRaises(cx_Oracle.DatabaseError, setattr, obj,
"SUBOBJECTVALUE", wrongObj) "SUBOBJECTVALUE", wrongObj)
def testSettingVarWrongObjectType(self): def test_2313_SettingVarWrongObjectType(self):
"test setting value of object variable to wrong object type" "2313 - test setting value of object variable to wrong object type"
wrongObjType = self.connection.gettype("UDT_OBJECTARRAY") wrongObjType = self.connection.gettype("UDT_OBJECTARRAY")
wrongObj = wrongObjType.newobject() wrongObj = wrongObjType.newobject()
var = self.cursor.var(cx_Oracle.DB_TYPE_OBJECT, var = self.cursor.var(cx_Oracle.DB_TYPE_OBJECT,
typename = "UDT_OBJECT") typename = "UDT_OBJECT")
self.assertRaises(cx_Oracle.DatabaseError, var.setvalue, 0, wrongObj) self.assertRaises(cx_Oracle.DatabaseError, var.setvalue, 0, wrongObj)
def testStringFormat(self): def test_2314_StringFormat(self):
"test object string format" "2314 - test object string format"
objType = self.connection.gettype("UDT_OBJECT") objType = self.connection.gettype("UDT_OBJECT")
user = TestEnv.GetMainUser() user = TestEnv.GetMainUser()
self.assertEqual(str(objType), self.assertEqual(str(objType),
@ -348,8 +350,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(str(objType.attributes[0]), self.assertEqual(str(objType.attributes[0]),
"<cx_Oracle.ObjectAttribute NUMBERVALUE>") "<cx_Oracle.ObjectAttribute NUMBERVALUE>")
def testTrimCollectionList(self): def test_2315_TrimCollectionList(self):
"test Trim number of elements from collection" "2315 - test Trim number of elements from collection"
subObjType = self.connection.gettype("UDT_SUBOBJECT") subObjType = self.connection.gettype("UDT_SUBOBJECT")
arrayType = self.connection.gettype("UDT_OBJECTARRAY") arrayType = self.connection.gettype("UDT_OBJECTARRAY")
data = [(1, "AB"), (2, "CDE"), (3, "FGH"), (4, "IJK")] data = [(1, "AB"), (2, "CDE"), (3, "FGH"), (4, "IJK")]
@ -371,4 +373,3 @@ class TestCase(TestEnv.BaseTestCase):
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -1,5 +1,5 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
# #
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -7,7 +7,9 @@
# Canada. All rights reserved. # Canada. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing session pools.""" """
2400 - Module for testing session pools
"""
import TestEnv import TestEnv
@ -50,8 +52,8 @@ class TestCase(TestEnv.BaseTestCase):
def tearDown(self): def tearDown(self):
pass pass
def testPool(self): def test_2400_Pool(self):
"""test that the pool is created and has the right attributes""" "2400 - test that the pool is created and has the right attributes"
pool = TestEnv.GetPool(min=2, max=8, increment=3, pool = TestEnv.GetPool(min=2, max=8, increment=3,
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT) getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT)
self.assertEqual(pool.username, TestEnv.GetMainUser(), self.assertEqual(pool.username, TestEnv.GetMainUser(),
@ -90,14 +92,14 @@ class TestCase(TestEnv.BaseTestCase):
pool.max_lifetime_session = 10 pool.max_lifetime_session = 10
self.assertEqual(pool.max_lifetime_session, 10) self.assertEqual(pool.max_lifetime_session, 10)
def testProxyAuth(self): def test_2401_ProxyAuth(self):
"""test that proxy authentication is possible""" "2401 - test that proxy authentication is possible"
pool = TestEnv.GetPool(min=2, max=8, increment=3, pool = TestEnv.GetPool(min=2, max=8, increment=3,
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT) getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT)
self.assertEqual(pool.homogeneous, 1, self.assertEqual(pool.homogeneous, 1,
"homogeneous should be 1 by default") "homogeneous should be 1 by default")
self.assertRaises(cx_Oracle.DatabaseError, pool.acquire, self.assertRaises(cx_Oracle.DatabaseError, pool.acquire,
user = u"missing_proxyuser") user = "missing_proxyuser")
pool = TestEnv.GetPool(min=2, max=8, increment=3, pool = TestEnv.GetPool(min=2, max=8, increment=3,
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT, homogeneous=False) getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT, homogeneous=False)
self.assertEqual(pool.homogeneous, 0, self.assertEqual(pool.homogeneous, 0,
@ -108,8 +110,8 @@ class TestCase(TestEnv.BaseTestCase):
result, = cursor.fetchone() result, = cursor.fetchone()
self.assertEqual(result, TestEnv.GetProxyUser().upper()) self.assertEqual(result, TestEnv.GetProxyUser().upper())
def testRollbackOnDel(self): def test_2402_RollbackOnDel(self):
"connection rolls back before being destroyed" "2402 - connection rolls back before being destroyed"
pool = TestEnv.GetPool() pool = TestEnv.GetPool()
connection = pool.acquire() connection = pool.acquire()
cursor = connection.cursor() cursor = connection.cursor()
@ -122,8 +124,8 @@ class TestCase(TestEnv.BaseTestCase):
count, = cursor.fetchone() count, = cursor.fetchone()
self.assertEqual(count, 0) self.assertEqual(count, 0)
def testRollbackOnRelease(self): def test_2403_RollbackOnRelease(self):
"connection rolls back before released back to the pool" "2403 - connection rolls back before released back to the pool"
pool = TestEnv.GetPool() pool = TestEnv.GetPool()
connection = pool.acquire() connection = pool.acquire()
cursor = connection.cursor() cursor = connection.cursor()
@ -138,8 +140,8 @@ class TestCase(TestEnv.BaseTestCase):
count, = cursor.fetchone() count, = cursor.fetchone()
self.assertEqual(count, 0) self.assertEqual(count, 0)
def testThreading(self): def test_2404_Threading(self):
"""test session pool to database with multiple threads""" "2404 - test session pool with multiple threads"
self.pool = TestEnv.GetPool(min=5, max=20, increment=2, threaded=True, self.pool = TestEnv.GetPool(min=5, max=20, increment=2, threaded=True,
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT) getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT)
threads = [] threads = []
@ -150,8 +152,8 @@ class TestCase(TestEnv.BaseTestCase):
for thread in threads: for thread in threads:
thread.join() thread.join()
def testThreadingWithErrors(self): def test_2405_ThreadingWithErrors(self):
"""test session pool to database with multiple threads (with errors)""" "2405 - test session pool with multiple threads (with errors)"
self.pool = TestEnv.GetPool(min=5, max=20, increment=2, threaded=True, self.pool = TestEnv.GetPool(min=5, max=20, increment=2, threaded=True,
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT) getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT)
threads = [] threads = []
@ -162,8 +164,8 @@ class TestCase(TestEnv.BaseTestCase):
for thread in threads: for thread in threads:
thread.join() thread.join()
def testPurity(self): def test_2406_Purity(self):
"""test session pool with various types of purity""" "2406 - test session pool with various types of purity"
action = "TEST_ACTION" action = "TEST_ACTION"
pool = TestEnv.GetPool(min=1, max=8, increment=1, pool = TestEnv.GetPool(min=1, max=8, increment=1,
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT) getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT)
@ -198,8 +200,8 @@ class TestCase(TestEnv.BaseTestCase):
pool.drop(connection) pool.drop(connection)
self.assertEqual(pool.opened, 1, "opened (4)") self.assertEqual(pool.opened, 1, "opened (4)")
def testHeterogeneous(self): def test_2407_Heterogeneous(self):
"""test heterogeneous pool with user and password specified""" "2407 - test heterogeneous pool with user and password specified"
pool = TestEnv.GetPool(min=2, max=8, increment=3, homogeneous=False, pool = TestEnv.GetPool(min=2, max=8, increment=3, homogeneous=False,
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT) getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT)
self.assertEqual(pool.homogeneous, 0) self.assertEqual(pool.homogeneous, 0)
@ -213,8 +215,8 @@ class TestCase(TestEnv.BaseTestCase):
TestEnv.GetMainPassword()), TestEnv.GetProxyUser(), TestEnv.GetMainPassword()), TestEnv.GetProxyUser(),
TestEnv.GetMainUser()) TestEnv.GetMainUser())
def testHeterogenousWithoutUser(self): def test_2408_HeterogenousWithoutUser(self):
"""test heterogeneous pool without user and password specified""" "2408 - test heterogeneous pool without user and password specified"
pool = TestEnv.GetPool(user="", password="", min=2, max=8, increment=3, pool = TestEnv.GetPool(user="", password="", min=2, max=8, increment=3,
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT, homogeneous=False) getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT, homogeneous=False)
self.__VerifyConnection(pool.acquire(TestEnv.GetMainUser(), self.__VerifyConnection(pool.acquire(TestEnv.GetMainUser(),
@ -226,15 +228,15 @@ class TestCase(TestEnv.BaseTestCase):
TestEnv.GetMainPassword()), TestEnv.GetProxyUser(), TestEnv.GetMainPassword()), TestEnv.GetProxyUser(),
TestEnv.GetMainUser()) TestEnv.GetMainUser())
def testHeterogeneousWrongPassword(self): def test_2409_HeterogeneousWrongPassword(self):
"""test heterogeneous pool with wrong password specified""" "2409 - test heterogeneous pool with wrong password specified"
pool = TestEnv.GetPool(min=2, max=8, increment=3, pool = TestEnv.GetPool(min=2, max=8, increment=3,
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT, homogeneous=False) getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT, homogeneous=False)
self.assertRaises(cx_Oracle.DatabaseError, pool.acquire, self.assertRaises(cx_Oracle.DatabaseError, pool.acquire,
TestEnv.GetProxyUser(), "this is the wrong password") TestEnv.GetProxyUser(), "this is the wrong password")
def testTaggingSession(self): def test_2410_TaggingSession(self):
"test tagging a session" "2410 - test tagging a session"
pool = TestEnv.GetPool(min=2, max=8, increment=3, pool = TestEnv.GetPool(min=2, max=8, increment=3,
getmode=cx_Oracle.SPOOL_ATTRVAL_NOWAIT) getmode=cx_Oracle.SPOOL_ATTRVAL_NOWAIT)
@ -258,8 +260,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(conn.tag, tagUTC) self.assertEqual(conn.tag, tagUTC)
conn.close() conn.close()
def testPLSQLSessionCallbacks(self): def test_2411_PLSQLSessionCallbacks(self):
"test PL/SQL session callbacks" "2411 - test PL/SQL session callbacks"
clientVersion = cx_Oracle.clientversion() clientVersion = cx_Oracle.clientversion()
if clientVersion < (12, 2): if clientVersion < (12, 2):
self.skipTest("PL/SQL session callbacks not supported before 12.2") self.skipTest("PL/SQL session callbacks not supported before 12.2")
@ -296,8 +298,8 @@ class TestCase(TestEnv.BaseTestCase):
expectedResults = list(zip(tags, actualTags)) expectedResults = list(zip(tags, actualTags))
self.assertEqual(results, expectedResults) self.assertEqual(results, expectedResults)
def testTaggingInvalidKey(self): def test_2412_TaggingInvalidKey(self):
"""testTagging with Invalid key""" "2412 - testTagging with Invalid key"
pool = TestEnv.GetPool(getmode=cx_Oracle.SPOOL_ATTRVAL_NOWAIT) pool = TestEnv.GetPool(getmode=cx_Oracle.SPOOL_ATTRVAL_NOWAIT)
conn = pool.acquire() conn = pool.acquire()
self.assertRaises(TypeError, pool.release, conn, tag=12345) self.assertRaises(TypeError, pool.release, conn, tag=12345)
@ -308,4 +310,3 @@ class TestCase(TestEnv.BaseTestCase):
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
# #
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -8,7 +8,9 @@
# Canada. All rights reserved. # Canada. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing string variables.""" """
2500 - Module for testing string variables
"""
import TestEnv import TestEnv
@ -35,23 +37,23 @@ class TestCase(TestEnv.BaseTestCase):
self.rawData.append(dataTuple) self.rawData.append(dataTuple)
self.dataByKey[i] = dataTuple self.dataByKey[i] = dataTuple
def testArrayWithIncreasedSize(self): def test_2500_ArrayWithIncreasedSize(self):
"test creating an array var and then increasing the internal size" "2500 - test creating array var and then increasing the internal size"
val = ["12345678901234567890"] * 3 val = ["12345678901234567890"] * 3
arrayVar = self.cursor.arrayvar(str, len(val), 4) arrayVar = self.cursor.arrayvar(str, len(val), 4)
arrayVar.setvalue(0, val) arrayVar.setvalue(0, val)
self.assertEqual(arrayVar.getvalue(), val) self.assertEqual(arrayVar.getvalue(), val)
def testBindString(self): def test_2501_BindString(self):
"test binding in a string" "2501 - test binding in a string"
self.cursor.execute(""" self.cursor.execute("""
select * from TestStrings select * from TestStrings
where StringCol = :value""", where StringCol = :value""",
value = "String 5") value = "String 5")
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[5]]) self.assertEqual(self.cursor.fetchall(), [self.dataByKey[5]])
def testBindDifferentVar(self): def test_2502_BindDifferentVar(self):
"test binding a different variable on second execution" "2502 - test binding a different variable on second execution"
retval_1 = self.cursor.var(cx_Oracle.STRING, 30) retval_1 = self.cursor.var(cx_Oracle.STRING, 30)
retval_2 = self.cursor.var(cx_Oracle.STRING, 30) retval_2 = self.cursor.var(cx_Oracle.STRING, 30)
self.cursor.execute("begin :retval := 'Called'; end;", self.cursor.execute("begin :retval := 'Called'; end;",
@ -61,13 +63,13 @@ class TestCase(TestEnv.BaseTestCase):
retval = retval_2) retval = retval_2)
self.assertEqual(retval_2.getvalue(), "Called") self.assertEqual(retval_2.getvalue(), "Called")
def testExceedsNumElements(self): def test_2503_ExceedsNumElements(self):
"test exceeding the number of elements returns IndexError" "2503 - test exceeding the number of elements returns IndexError"
var = self.cursor.var(str) var = self.cursor.var(str)
self.assertRaises(IndexError, var.getvalue, 1) self.assertRaises(IndexError, var.getvalue, 1)
def testBindStringAfterNumber(self): def test_2504_BindStringAfterNumber(self):
"test binding in a string after setting input sizes to a number" "2504 - test binding in a string after setting input sizes to a number"
self.cursor.setinputsizes(value = cx_Oracle.NUMBER) self.cursor.setinputsizes(value = cx_Oracle.NUMBER)
self.cursor.execute(""" self.cursor.execute("""
select * from TestStrings select * from TestStrings
@ -75,8 +77,8 @@ class TestCase(TestEnv.BaseTestCase):
value = "String 6") value = "String 6")
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[6]]) self.assertEqual(self.cursor.fetchall(), [self.dataByKey[6]])
def testBindStringArrayDirect(self): def test_2505_BindStringArrayDirect(self):
"test binding in a string array" "2505 - test binding in a string array"
returnValue = self.cursor.var(cx_Oracle.NUMBER) returnValue = self.cursor.var(cx_Oracle.NUMBER)
array = [r[1] for r in self.rawData] array = [r[1] for r in self.rawData]
statement = """ statement = """
@ -95,8 +97,8 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(returnValue.getvalue(), 163) self.assertEqual(returnValue.getvalue(), 163)
def testBindStringArrayBySizes(self): def test_2506_BindStringArrayBySizes(self):
"test binding in a string array (with setinputsizes)" "2506 - test binding in a string array (with setinputsizes)"
returnValue = self.cursor.var(cx_Oracle.NUMBER) returnValue = self.cursor.var(cx_Oracle.NUMBER)
self.cursor.setinputsizes(array = [cx_Oracle.STRING, 10]) self.cursor.setinputsizes(array = [cx_Oracle.STRING, 10])
array = [r[1] for r in self.rawData] array = [r[1] for r in self.rawData]
@ -110,8 +112,8 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(returnValue.getvalue(), 87) self.assertEqual(returnValue.getvalue(), 87)
def testBindStringArrayByVar(self): def test_2507_BindStringArrayByVar(self):
"test binding in a string array (with arrayvar)" "2507 - test binding in a string array (with arrayvar)"
returnValue = self.cursor.var(cx_Oracle.NUMBER) returnValue = self.cursor.var(cx_Oracle.NUMBER)
array = self.cursor.arrayvar(cx_Oracle.STRING, 10, 20) array = self.cursor.arrayvar(cx_Oracle.STRING, 10, 20)
array.setvalue(0, [r[1] for r in self.rawData]) array.setvalue(0, [r[1] for r in self.rawData])
@ -125,8 +127,8 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(returnValue.getvalue(), 88) self.assertEqual(returnValue.getvalue(), 88)
def testBindInOutStringArrayByVar(self): def test_2508_BindInOutStringArrayByVar(self):
"test binding in/out a string array (with arrayvar)" "2508 - test binding in/out a string array (with arrayvar)"
array = self.cursor.arrayvar(cx_Oracle.STRING, 10, 100) array = self.cursor.arrayvar(cx_Oracle.STRING, 10, 100)
originalData = [r[1] for r in self.rawData] originalData = [r[1] for r in self.rawData]
expectedData = ["Converted element # %d originally had length %d" % \ expectedData = ["Converted element # %d originally had length %d" % \
@ -141,8 +143,8 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(array.getvalue(), expectedData) self.assertEqual(array.getvalue(), expectedData)
def testBindOutStringArrayByVar(self): def test_2509_BindOutStringArrayByVar(self):
"test binding out a string array (with arrayvar)" "2509 - test binding out a string array (with arrayvar)"
array = self.cursor.arrayvar(cx_Oracle.STRING, 6, 100) array = self.cursor.arrayvar(cx_Oracle.STRING, 6, 100)
expectedData = ["Test out element # %d" % i for i in range(1, 7)] expectedData = ["Test out element # %d" % i for i in range(1, 7)]
self.cursor.execute(""" self.cursor.execute("""
@ -153,8 +155,8 @@ class TestCase(TestEnv.BaseTestCase):
array = array) array = array)
self.assertEqual(array.getvalue(), expectedData) self.assertEqual(array.getvalue(), expectedData)
def testBindRaw(self): def test_2510_BindRaw(self):
"test binding in a raw" "2510 - test binding in a raw"
self.cursor.setinputsizes(value = cx_Oracle.BINARY) self.cursor.setinputsizes(value = cx_Oracle.BINARY)
self.cursor.execute(""" self.cursor.execute("""
select * from TestStrings select * from TestStrings
@ -162,8 +164,8 @@ class TestCase(TestEnv.BaseTestCase):
value = "Raw 4".encode("ascii")) value = "Raw 4".encode("ascii"))
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[4]]) self.assertEqual(self.cursor.fetchall(), [self.dataByKey[4]])
def testBindAndFetchRowid(self): def test_2511_BindAndFetchRowid(self):
"test binding (and fetching) a rowid" "2511 - test binding (and fetching) a rowid"
self.cursor.execute(""" self.cursor.execute("""
select rowid select rowid
from TestStrings from TestStrings
@ -176,8 +178,8 @@ class TestCase(TestEnv.BaseTestCase):
value = rowid) value = rowid)
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[3]]) self.assertEqual(self.cursor.fetchall(), [self.dataByKey[3]])
def testBindAndFetchUniversalRowids(self): def test_2512_BindAndFetchUniversalRowids(self):
"test binding (and fetching) universal rowids" "2512 - test binding (and fetching) universal rowids"
self.cursor.execute("truncate table TestUniversalRowids") self.cursor.execute("truncate table TestUniversalRowids")
data = [ data = [
(1, "ABC" * 75, datetime.datetime(2017, 4, 11)), (1, "ABC" * 75, datetime.datetime(2017, 4, 11)),
@ -203,16 +205,16 @@ class TestCase(TestEnv.BaseTestCase):
fetchedData.extend(self.cursor.fetchall()) fetchedData.extend(self.cursor.fetchall())
self.assertEqual(fetchedData, data) self.assertEqual(fetchedData, data)
def testBindNull(self): def test_2513_BindNull(self):
"test binding in a null" "2513 - test binding in a null"
self.cursor.execute(""" self.cursor.execute("""
select * from TestStrings select * from TestStrings
where StringCol = :value""", where StringCol = :value""",
value = None) value = None)
self.assertEqual(self.cursor.fetchall(), []) self.assertEqual(self.cursor.fetchall(), [])
def testBindOutSetInputSizesByType(self): def test_2514_BindOutSetInputSizesByType(self):
"test binding out with set input sizes defined (by type)" "2514 - test binding out with set input sizes defined (by type)"
vars = self.cursor.setinputsizes(value = cx_Oracle.STRING) vars = self.cursor.setinputsizes(value = cx_Oracle.STRING)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -220,8 +222,8 @@ class TestCase(TestEnv.BaseTestCase):
end;""") end;""")
self.assertEqual(vars["value"].getvalue(), "TSI") self.assertEqual(vars["value"].getvalue(), "TSI")
def testBindOutSetInputSizesByInteger(self): def test_2515_BindOutSetInputSizesByInteger(self):
"test binding out with set input sizes defined (by integer)" "2515 - test binding out with set input sizes defined (by integer)"
vars = self.cursor.setinputsizes(value = 30) vars = self.cursor.setinputsizes(value = 30)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -229,8 +231,8 @@ class TestCase(TestEnv.BaseTestCase):
end;""") end;""")
self.assertEqual(vars["value"].getvalue(), "TSI (I)") self.assertEqual(vars["value"].getvalue(), "TSI (I)")
def testBindInOutSetInputSizesByType(self): def test_2516_BindInOutSetInputSizesByType(self):
"test binding in/out with set input sizes defined (by type)" "2516 - test binding in/out with set input sizes defined (by type)"
vars = self.cursor.setinputsizes(value = cx_Oracle.STRING) vars = self.cursor.setinputsizes(value = cx_Oracle.STRING)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -239,8 +241,8 @@ class TestCase(TestEnv.BaseTestCase):
value = "InVal") value = "InVal")
self.assertEqual(vars["value"].getvalue(), "InVal TSI") self.assertEqual(vars["value"].getvalue(), "InVal TSI")
def testBindInOutSetInputSizesByInteger(self): def test_2517_BindInOutSetInputSizesByInteger(self):
"test binding in/out with set input sizes defined (by integer)" "2517 - test binding in/out with set input sizes defined (by integer)"
vars = self.cursor.setinputsizes(value = 30) vars = self.cursor.setinputsizes(value = 30)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -249,8 +251,8 @@ class TestCase(TestEnv.BaseTestCase):
value = "InVal") value = "InVal")
self.assertEqual(vars["value"].getvalue(), "InVal TSI (I)") self.assertEqual(vars["value"].getvalue(), "InVal TSI (I)")
def testBindOutVar(self): def test_2518_BindOutVar(self):
"test binding out with cursor.var() method" "2518 - test binding out with cursor.var() method"
var = self.cursor.var(cx_Oracle.STRING) var = self.cursor.var(cx_Oracle.STRING)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -259,8 +261,8 @@ class TestCase(TestEnv.BaseTestCase):
value = var) value = var)
self.assertEqual(var.getvalue(), "TSI (VAR)") self.assertEqual(var.getvalue(), "TSI (VAR)")
def testBindInOutVarDirectSet(self): def test_2519_BindInOutVarDirectSet(self):
"test binding in/out with cursor.var() method" "2519 - test binding in/out with cursor.var() method"
var = self.cursor.var(cx_Oracle.STRING) var = self.cursor.var(cx_Oracle.STRING)
var.setvalue(0, "InVal") var.setvalue(0, "InVal")
self.cursor.execute(""" self.cursor.execute("""
@ -270,8 +272,8 @@ class TestCase(TestEnv.BaseTestCase):
value = var) value = var)
self.assertEqual(var.getvalue(), "InVal TSI (VAR)") self.assertEqual(var.getvalue(), "InVal TSI (VAR)")
def testBindLongString(self): def test_2520_BindLongString(self):
"test that binding a long string succeeds" "2520 - test that binding a long string succeeds"
self.cursor.setinputsizes(bigString = cx_Oracle.DB_TYPE_LONG) self.cursor.setinputsizes(bigString = cx_Oracle.DB_TYPE_LONG)
self.cursor.execute(""" self.cursor.execute("""
declare declare
@ -281,8 +283,8 @@ class TestCase(TestEnv.BaseTestCase):
end;""", end;""",
bigString = "X" * 10000) bigString = "X" * 10000)
def testBindLongStringAfterSettingSize(self): def test_2521_BindLongStringAfterSettingSize(self):
"test that setinputsizes() returns a long variable" "2521 - test that setinputsizes() returns a long variable"
var = self.cursor.setinputsizes(test = 90000)["test"] var = self.cursor.setinputsizes(test = 90000)["test"]
inString = "1234567890" * 9000 inString = "1234567890" * 9000
var.setvalue(0, inString) var.setvalue(0, inString)
@ -291,8 +293,8 @@ class TestCase(TestEnv.BaseTestCase):
"output does not match: in was %d, out was %d" % \ "output does not match: in was %d, out was %d" % \
(len(inString), len(outString))) (len(inString), len(outString)))
def testCursorDescription(self): def test_2522_CursorDescription(self):
"test cursor description is accurate" "2522 - test cursor description is accurate"
self.cursor.execute("select * from TestStrings") self.cursor.execute("select * from TestStrings")
self.assertEqual(self.cursor.description, self.assertEqual(self.cursor.description,
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0), [ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
@ -307,14 +309,14 @@ class TestCase(TestEnv.BaseTestCase):
50 * TestEnv.GetCharSetRatio(), None, 50 * TestEnv.GetCharSetRatio(), None,
None, 1) ]) None, 1) ])
def testFetchAll(self): def test_2523_FetchAll(self):
"test that fetching all of the data returns the correct results" "2523 - test that fetching all of the data returns the correct results"
self.cursor.execute("select * From TestStrings order by IntCol") self.cursor.execute("select * From TestStrings order by IntCol")
self.assertEqual(self.cursor.fetchall(), self.rawData) self.assertEqual(self.cursor.fetchall(), self.rawData)
self.assertEqual(self.cursor.fetchall(), []) self.assertEqual(self.cursor.fetchall(), [])
def testFetchMany(self): def test_2524_FetchMany(self):
"test that fetching data in chunks returns the correct results" "2524 - test that fetching data in chunks returns the correct results"
self.cursor.execute("select * From TestStrings order by IntCol") self.cursor.execute("select * From TestStrings order by IntCol")
self.assertEqual(self.cursor.fetchmany(3), self.rawData[0:3]) 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(2), self.rawData[3:5])
@ -322,8 +324,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:]) self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:])
self.assertEqual(self.cursor.fetchmany(3), []) self.assertEqual(self.cursor.fetchmany(3), [])
def testFetchOne(self): def test_2525_FetchOne(self):
"test that fetching a single row returns the correct results" "2525 - test that fetching a single row returns the correct results"
self.cursor.execute(""" self.cursor.execute("""
select * select *
from TestStrings from TestStrings
@ -333,8 +335,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(self.cursor.fetchone(), self.dataByKey[4]) self.assertEqual(self.cursor.fetchone(), self.dataByKey[4])
self.assertEqual(self.cursor.fetchone(), None) self.assertEqual(self.cursor.fetchone(), None)
def testSupplementalCharacters(self): def test_2526_SupplementalCharacters(self):
"test that binding and fetching supplemental charcters works correctly" "2526 - test binding and fetching supplemental charcters"
self.cursor.execute(""" self.cursor.execute("""
select value select value
from nls_database_parameters from nls_database_parameters
@ -356,8 +358,8 @@ class TestCase(TestEnv.BaseTestCase):
value, = self.cursor.fetchone() value, = self.cursor.fetchone()
self.assertEqual(value, supplementalChars) self.assertEqual(value, supplementalChars)
def testBindTwiceWithLargeStringSecond(self): def test_2527_BindTwiceWithLargeStringSecond(self):
"test binding twice with a larger string the second time" "2527 - test binding twice with a larger string the second time"
self.cursor.execute("truncate table TestTempTable") self.cursor.execute("truncate table TestTempTable")
sql = "insert into TestTempTable (IntCol, StringCol) values (:1, :2)" sql = "insert into TestTempTable (IntCol, StringCol) values (:1, :2)"
shortString = "short string" shortString = "short string"
@ -372,8 +374,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(self.cursor.fetchall(), self.assertEqual(self.cursor.fetchall(),
[(1, shortString), (2, longString)]) [(1, shortString), (2, longString)])
def testIssue50(self): def test_2528_Issue50(self):
"test issue 50 - avoid error ORA-24816" "2528 - test issue 50 - avoid error ORA-24816"
cursor = self.connection.cursor() cursor = self.connection.cursor()
try: try:
cursor.execute("drop table issue_50 purge") cursor.execute("drop table issue_50 purge")
@ -402,14 +404,14 @@ class TestCase(TestEnv.BaseTestCase):
[2, u'd5ff845a', u'94275767', u'bf161ff6', u'', u'', idVar]) [2, u'd5ff845a', u'94275767', u'bf161ff6', u'', u'', idVar])
cursor.execute("drop table issue_50 purge") cursor.execute("drop table issue_50 purge")
def testSetRowidToString(self): def test_2529_SetRowidToString(self):
"test assigning a string to rowid" "2529 - test assigning a string to rowid"
var = self.cursor.var(cx_Oracle.ROWID) var = self.cursor.var(cx_Oracle.ROWID)
self.assertRaises(cx_Oracle.NotSupportedError, var.setvalue, 0, self.assertRaises(cx_Oracle.NotSupportedError, var.setvalue, 0,
"ABDHRYTHFJGKDKKDH") "ABDHRYTHFJGKDKKDH")
def testShortXMLAsString(self): def test_2530_ShortXMLAsString(self):
"test fetching XMLType object as a string" "2530 - test fetching XMLType object as a string"
self.cursor.execute(""" self.cursor.execute("""
select XMLElement("string", stringCol) select XMLElement("string", stringCol)
from TestStrings from TestStrings
@ -418,8 +420,8 @@ class TestCase(TestEnv.BaseTestCase):
expectedValue = "<string>String 1</string>" expectedValue = "<string>String 1</string>"
self.assertEqual(actualValue, expectedValue) self.assertEqual(actualValue, expectedValue)
def testLongXMLAsString(self): def test_2531_LongXMLAsString(self):
"test inserting and fetching an XMLType object (1K) as a string" "2531 - test inserting and fetching an XMLType object (1K) as a string"
chars = string.ascii_uppercase + string.ascii_lowercase chars = string.ascii_uppercase + string.ascii_lowercase
randomString = ''.join(random.choice(chars) for _ in range(1024)) randomString = ''.join(random.choice(chars) for _ in range(1024))
intVal = 200 intVal = 200
@ -434,4 +436,3 @@ class TestCase(TestEnv.BaseTestCase):
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -1,5 +1,5 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
# #
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -7,7 +7,9 @@
# Canada. All rights reserved. # Canada. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing timestamp variables.""" """
2600 - Module for testing timestamp variables
"""
import TestEnv import TestEnv
@ -43,8 +45,8 @@ class TestCase(TestEnv.BaseTestCase):
self.rawData.append(tuple) self.rawData.append(tuple)
self.dataByKey[i] = tuple self.dataByKey[i] = tuple
def testBindTimestamp(self): def test_2600_BindTimestamp(self):
"test binding in a timestamp" "2600 - test binding in a timestamp"
self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_TIMESTAMP) self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_TIMESTAMP)
self.cursor.execute(""" self.cursor.execute("""
select * from TestTimestamps select * from TestTimestamps
@ -52,8 +54,8 @@ class TestCase(TestEnv.BaseTestCase):
value = cx_Oracle.Timestamp(2002, 12, 14, 0, 0, 10, 250000)) value = cx_Oracle.Timestamp(2002, 12, 14, 0, 0, 10, 250000))
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[5]]) self.assertEqual(self.cursor.fetchall(), [self.dataByKey[5]])
def testBindNull(self): def test_2601_BindNull(self):
"test binding in a null" "2601 - test binding in a null"
self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_TIMESTAMP) self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_TIMESTAMP)
self.cursor.execute(""" self.cursor.execute("""
select * from TestTimestamps select * from TestTimestamps
@ -61,8 +63,8 @@ class TestCase(TestEnv.BaseTestCase):
value = None) value = None)
self.assertEqual(self.cursor.fetchall(), []) self.assertEqual(self.cursor.fetchall(), [])
def testBindOutSetInputSizes(self): def test_2602_BindOutSetInputSizes(self):
"test binding out with set input sizes defined" "2602 - test binding out with set input sizes defined"
vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_TIMESTAMP) vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_TIMESTAMP)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -71,8 +73,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(vars["value"].getvalue(), self.assertEqual(vars["value"].getvalue(),
cx_Oracle.Timestamp(2002, 12, 9)) cx_Oracle.Timestamp(2002, 12, 9))
def testBindInOutSetInputSizes(self): def test_2603_BindInOutSetInputSizes(self):
"test binding in/out with set input sizes defined" "2603 - test binding in/out with set input sizes defined"
vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_TIMESTAMP) vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_TIMESTAMP)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -82,8 +84,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(vars["value"].getvalue(), self.assertEqual(vars["value"].getvalue(),
cx_Oracle.Timestamp(2002, 12, 17, 16, 0, 0)) cx_Oracle.Timestamp(2002, 12, 17, 16, 0, 0))
def testBindOutVar(self): def test_2604_BindOutVar(self):
"test binding out with cursor.var() method" "2604 - test binding out with cursor.var() method"
var = self.cursor.var(cx_Oracle.DB_TYPE_TIMESTAMP) var = self.cursor.var(cx_Oracle.DB_TYPE_TIMESTAMP)
self.cursor.execute(""" self.cursor.execute("""
begin begin
@ -94,8 +96,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(var.getvalue(), self.assertEqual(var.getvalue(),
cx_Oracle.Timestamp(2002, 12, 31, 12, 31, 0)) cx_Oracle.Timestamp(2002, 12, 31, 12, 31, 0))
def testBindInOutVarDirectSet(self): def test_2605_BindInOutVarDirectSet(self):
"test binding in/out with cursor.var() method" "2605 - test binding in/out with cursor.var() method"
var = self.cursor.var(cx_Oracle.DB_TYPE_TIMESTAMP) var = self.cursor.var(cx_Oracle.DB_TYPE_TIMESTAMP)
var.setvalue(0, cx_Oracle.Timestamp(2002, 12, 9, 6, 0, 0)) var.setvalue(0, cx_Oracle.Timestamp(2002, 12, 9, 6, 0, 0))
self.cursor.execute(""" self.cursor.execute("""
@ -106,8 +108,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(var.getvalue(), self.assertEqual(var.getvalue(),
cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0)) cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0))
def testCursorDescription(self): def test_2606_CursorDescription(self):
"test cursor description is accurate" "2606 - test cursor description is accurate"
self.cursor.execute("select * from TestTimestamps") self.cursor.execute("select * from TestTimestamps")
self.assertEqual(self.cursor.description, self.assertEqual(self.cursor.description,
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0), [ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
@ -116,14 +118,14 @@ class TestCase(TestEnv.BaseTestCase):
('NULLABLECOL', cx_Oracle.DB_TYPE_TIMESTAMP, 23, None, 0, 6, ('NULLABLECOL', cx_Oracle.DB_TYPE_TIMESTAMP, 23, None, 0, 6,
1) ]) 1) ])
def testFetchAll(self): def test_2607_FetchAll(self):
"test that fetching all of the data returns the correct results" "2607 - test that fetching all of the data returns the correct results"
self.cursor.execute("select * From TestTimestamps order by IntCol") self.cursor.execute("select * From TestTimestamps order by IntCol")
self.assertEqual(self.cursor.fetchall(), self.rawData) self.assertEqual(self.cursor.fetchall(), self.rawData)
self.assertEqual(self.cursor.fetchall(), []) self.assertEqual(self.cursor.fetchall(), [])
def testFetchMany(self): def test_2608_FetchMany(self):
"test that fetching data in chunks returns the correct results" "2608 - test that fetching data in chunks returns the correct results"
self.cursor.execute("select * From TestTimestamps order by IntCol") self.cursor.execute("select * From TestTimestamps order by IntCol")
self.assertEqual(self.cursor.fetchmany(3), self.rawData[0:3]) 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(2), self.rawData[3:5])
@ -131,8 +133,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:]) self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:])
self.assertEqual(self.cursor.fetchmany(3), []) self.assertEqual(self.cursor.fetchmany(3), [])
def testFetchOne(self): def test_2609_FetchOne(self):
"test that fetching a single row returns the correct results" "2609 - test that fetching a single row returns the correct results"
self.cursor.execute(""" self.cursor.execute("""
select * select *
from TestTimestamps from TestTimestamps
@ -144,4 +146,3 @@ class TestCase(TestEnv.BaseTestCase):
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -1,8 +1,10 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing AQ objects.""" """
2700 - Module for testing AQ
"""
import TestEnv import TestEnv
@ -47,8 +49,8 @@ class TestCase(TestEnv.BaseTestCase):
setattr(obj, attrName, value) setattr(obj, attrName, value)
self.assertEqual(getattr(obj, attrName), value) self.assertEqual(getattr(obj, attrName), value)
def testDeqEmpty(self): def test_2700_DeqEmpty(self):
"test dequeuing an empty queue" "2700 - test dequeuing an empty queue"
self.__clearBooksQueue() self.__clearBooksQueue()
booksType = self.connection.gettype("UDT_BOOK") booksType = self.connection.gettype("UDT_BOOK")
book = booksType.newobject() book = booksType.newobject()
@ -59,8 +61,8 @@ class TestCase(TestEnv.BaseTestCase):
book) book)
self.assertTrue(messageId is None) self.assertTrue(messageId is None)
def testDeqEnq(self): def test_2701_DeqEnq(self):
"test enqueuing and dequeuing multiple messages" "2701 - test enqueuing and dequeuing multiple messages"
self.__clearBooksQueue() self.__clearBooksQueue()
booksType = self.connection.gettype("UDT_BOOK") booksType = self.connection.gettype("UDT_BOOK")
options = self.connection.enqoptions() options = self.connection.enqoptions()
@ -81,8 +83,8 @@ class TestCase(TestEnv.BaseTestCase):
self.connection.commit() self.connection.commit()
self.assertEqual(results, self.bookData) self.assertEqual(results, self.bookData)
def testDeqModeRemoveNoData(self): def test_2702_DeqModeRemoveNoData(self):
"test dequeuing with DEQ_REMOVE_NODATA option" "2702 - test dequeuing with DEQ_REMOVE_NODATA option"
self.__clearBooksQueue() self.__clearBooksQueue()
booksType = self.connection.gettype("UDT_BOOK") booksType = self.connection.gettype("UDT_BOOK")
book = booksType.newobject() book = booksType.newobject()
@ -104,8 +106,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertTrue(messageId is not None) self.assertTrue(messageId is not None)
self.assertEqual(book.TITLE, "") self.assertEqual(book.TITLE, "")
def testDeqOptions(self): def test_2703_DeqOptions(self):
"test getting/setting dequeue options attributes" "2703 - test getting/setting dequeue options attributes"
options = self.connection.deqoptions() options = self.connection.deqoptions()
self.__verifyAttribute(options, "condition", "TEST_CONDITION") self.__verifyAttribute(options, "condition", "TEST_CONDITION")
self.__verifyAttribute(options, "consumername", "TEST_CONSUMERNAME") self.__verifyAttribute(options, "consumername", "TEST_CONSUMERNAME")
@ -119,8 +121,8 @@ class TestCase(TestEnv.BaseTestCase):
self.__verifyAttribute(options, "wait", 1287) self.__verifyAttribute(options, "wait", 1287)
self.__verifyAttribute(options, "msgid", b'mID') self.__verifyAttribute(options, "msgid", b'mID')
def testDeqWithWait(self): def test_2704_DeqWithWait(self):
"test waiting for dequeue" "2704 - test waiting for dequeue"
self.__clearBooksQueue() self.__clearBooksQueue()
results = [] results = []
thread = threading.Thread(target = self.__deqInThread, thread = threading.Thread(target = self.__deqInThread,
@ -139,13 +141,13 @@ class TestCase(TestEnv.BaseTestCase):
thread.join() thread.join()
self.assertEqual(results, [(title, authors, price)]) self.assertEqual(results, [(title, authors, price)])
def testEnqOptions(self): def test_2705_EnqOptions(self):
"test getting/setting enqueue options attributes" "2705 - test getting/setting enqueue options attributes"
options = self.connection.enqoptions() options = self.connection.enqoptions()
self.__verifyAttribute(options, "visibility", cx_Oracle.ENQ_IMMEDIATE) self.__verifyAttribute(options, "visibility", cx_Oracle.ENQ_IMMEDIATE)
def testErrorsForInvalidValues(self): def test_2706_ErrorsForInvalidValues(self):
"test errors for invalid values for options" "2706 - test errors for invalid values for options"
booksType = self.connection.gettype("UDT_BOOK") booksType = self.connection.gettype("UDT_BOOK")
book = booksType.newobject() book = booksType.newobject()
options = self.connection.enqoptions() options = self.connection.enqoptions()
@ -156,8 +158,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertRaises(TypeError, self.connection.enq, self.bookQueueName, self.assertRaises(TypeError, self.connection.enq, self.bookQueueName,
options, props, book) options, props, book)
def testMsgProps(self): def test_2707_MsgProps(self):
"test getting/setting message properties attributes" "2707 - test getting/setting message properties attributes"
props = self.connection.msgproperties() props = self.connection.msgproperties()
self.__verifyAttribute(props, "correlation", "TEST_CORRELATION") self.__verifyAttribute(props, "correlation", "TEST_CORRELATION")
self.__verifyAttribute(props, "delay", 60) self.__verifyAttribute(props, "delay", 60)
@ -169,8 +171,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(props.state, cx_Oracle.MSG_READY) self.assertEqual(props.state, cx_Oracle.MSG_READY)
self.assertEqual(props.deliverymode, 0) self.assertEqual(props.deliverymode, 0)
def testVisibilityModeCommit(self): def test_2708_VisibilityModeCommit(self):
"test enqueue visibility option - ENQ_ON_COMMIT" "2708 - test enqueue visibility option - ENQ_ON_COMMIT"
self.__clearBooksQueue() self.__clearBooksQueue()
booksType = self.connection.gettype("UDT_BOOK") booksType = self.connection.gettype("UDT_BOOK")
book = booksType.newobject() book = booksType.newobject()
@ -195,8 +197,8 @@ class TestCase(TestEnv.BaseTestCase):
book) book)
self.assertTrue(messageId is not None) self.assertTrue(messageId is not None)
def testVisibilityModeImmediate(self): def test_2709_VisibilityModeImmediate(self):
"test enqueue visibility option - ENQ_IMMEDIATE" "2709 - test enqueue visibility option - ENQ_IMMEDIATE"
self.__clearBooksQueue() self.__clearBooksQueue()
booksType = self.connection.gettype("UDT_BOOK") booksType = self.connection.gettype("UDT_BOOK")
book = booksType.newobject() book = booksType.newobject()
@ -219,8 +221,8 @@ class TestCase(TestEnv.BaseTestCase):
otherConnection.commit() otherConnection.commit()
self.assertEqual(results, self.bookData[0]) self.assertEqual(results, self.bookData[0])
def testDeliveryModeSameBuffered(self): def test_2710_DeliveryModeSameBuffered(self):
"test enqueue/dequeue delivery modes identical - buffered" "2710 - test enqueue/dequeue delivery modes identical - buffered"
self.__clearBooksQueue() self.__clearBooksQueue()
booksType = self.connection.gettype("UDT_BOOK") booksType = self.connection.gettype("UDT_BOOK")
book = booksType.newobject() book = booksType.newobject()
@ -245,8 +247,8 @@ class TestCase(TestEnv.BaseTestCase):
otherConnection.commit() otherConnection.commit()
self.assertEqual(results, self.bookData[0]) self.assertEqual(results, self.bookData[0])
def testDeliveryModeSamePersistent(self): def test_2711_DeliveryModeSamePersistent(self):
"test enqueue/dequeue delivery modes identical - persistent" "2711 - test enqueue/dequeue delivery modes identical - persistent"
self.__clearBooksQueue() self.__clearBooksQueue()
booksType = self.connection.gettype("UDT_BOOK") booksType = self.connection.gettype("UDT_BOOK")
book = booksType.newobject() book = booksType.newobject()
@ -271,8 +273,8 @@ class TestCase(TestEnv.BaseTestCase):
otherConnection.commit() otherConnection.commit()
self.assertEqual(results, self.bookData[0]) self.assertEqual(results, self.bookData[0])
def testDeliveryModeSamePersistentBuffered(self): def test_2712_DeliveryModeSamePersistentBuffered(self):
"test enqueue/dequeue delivery modes identical - persistent/buffered" "2712 - test enqueue/dequeue delivery modes the same"
self.__clearBooksQueue() self.__clearBooksQueue()
booksType = self.connection.gettype("UDT_BOOK") booksType = self.connection.gettype("UDT_BOOK")
book = booksType.newobject() book = booksType.newobject()
@ -297,8 +299,8 @@ class TestCase(TestEnv.BaseTestCase):
otherConnection.commit() otherConnection.commit()
self.assertEqual(results, self.bookData[0]) self.assertEqual(results, self.bookData[0])
def testDeliveryModeDifferent(self): def test_2713_DeliveryModeDifferent(self):
"test enqueue/dequeue delivery modes different" "2713 - test enqueue/dequeue delivery modes different"
self.__clearBooksQueue() self.__clearBooksQueue()
booksType = self.connection.gettype("UDT_BOOK") booksType = self.connection.gettype("UDT_BOOK")
book = booksType.newobject() book = booksType.newobject()
@ -322,8 +324,8 @@ class TestCase(TestEnv.BaseTestCase):
book) book)
self.assertTrue(messageId is None) self.assertTrue(messageId is None)
def testDequeueTransformation(self): def test_2714_DequeueTransformation(self):
"test dequeue transformation" "2714 - test dequeue transformation"
self.__clearBooksQueue() self.__clearBooksQueue()
booksType = self.connection.gettype("UDT_BOOK") booksType = self.connection.gettype("UDT_BOOK")
book = booksType.newobject() book = booksType.newobject()
@ -347,8 +349,8 @@ class TestCase(TestEnv.BaseTestCase):
otherPrice = book.PRICE otherPrice = book.PRICE
self.assertEqual(otherPrice, expectedPrice) self.assertEqual(otherPrice, expectedPrice)
def testEnqueueTransformation(self): def test_2715_EnqueueTransformation(self):
"test enqueue transformation" "2715 - test enqueue transformation"
self.__clearBooksQueue() self.__clearBooksQueue()
booksType = self.connection.gettype("UDT_BOOK") booksType = self.connection.gettype("UDT_BOOK")
book = booksType.newobject() book = booksType.newobject()
@ -374,4 +376,3 @@ class TestCase(TestEnv.BaseTestCase):
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -1,8 +1,10 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing AQ Bulk enqueue/dequeue.""" """
2800 - Module for testing AQ Bulk enqueue/dequeue
"""
import TestEnv import TestEnv
@ -50,8 +52,8 @@ class TestCase(TestEnv.BaseTestCase):
self.connection.commit() self.connection.commit()
return queue return queue
def testEnqAndDeq(self): def test_2800_EnqAndDeq(self):
"test bulk enqueue and dequeue" "2800 - test bulk enqueue and dequeue"
queue = self.__getAndClearRawQueue() queue = self.__getAndClearRawQueue()
messages = [self.connection.msgproperties(payload=d) \ messages = [self.connection.msgproperties(payload=d) \
for d in RAW_PAYLOAD_DATA] for d in RAW_PAYLOAD_DATA]
@ -61,15 +63,15 @@ class TestCase(TestEnv.BaseTestCase):
self.connection.commit() self.connection.commit()
self.assertEqual(data, RAW_PAYLOAD_DATA) self.assertEqual(data, RAW_PAYLOAD_DATA)
def testDequeueEmpty(self): def test_2801_DequeueEmpty(self):
"test empty bulk dequeue" "2801 - test empty bulk dequeue"
queue = self.__getAndClearRawQueue() queue = self.__getAndClearRawQueue()
messages = queue.deqMany(5) messages = queue.deqMany(5)
self.connection.commit() self.connection.commit()
self.assertEqual(messages, []) self.assertEqual(messages, [])
def testDeqWithWait(self): def test_2802_DeqWithWait(self):
"test bulk dequeue with wait" "2802 - test bulk dequeue with wait"
queue = self.__getAndClearRawQueue() queue = self.__getAndClearRawQueue()
results = [] results = []
thread = threading.Thread(target=self.__deqInThread, args=(results,)) thread = threading.Thread(target=self.__deqInThread, args=(results,))
@ -81,8 +83,8 @@ class TestCase(TestEnv.BaseTestCase):
thread.join() thread.join()
self.assertEqual(results, RAW_PAYLOAD_DATA) self.assertEqual(results, RAW_PAYLOAD_DATA)
def testEnqAndDeqMultipleTimes(self): def test_2803_EnqAndDeqMultipleTimes(self):
"test enqueue and dequeue multiple times" "2803 - test enqueue and dequeue multiple times"
queue = self.__getAndClearRawQueue() queue = self.__getAndClearRawQueue()
dataToEnqueue = RAW_PAYLOAD_DATA dataToEnqueue = RAW_PAYLOAD_DATA
for num in (2, 6, 4): for num in (2, 6, 4):
@ -99,8 +101,8 @@ class TestCase(TestEnv.BaseTestCase):
self.connection.commit() self.connection.commit()
self.assertEqual(allData, RAW_PAYLOAD_DATA) self.assertEqual(allData, RAW_PAYLOAD_DATA)
def testEnqAndDeqVisibility(self): def test_2804_EnqAndDeqVisibility(self):
"test visibility option for enqueue and dequeue" "2804 - test visibility option for enqueue and dequeue"
queue = self.__getAndClearRawQueue() queue = self.__getAndClearRawQueue()
# first test with ENQ_ON_COMMIT (commit required) # first test with ENQ_ON_COMMIT (commit required)

View File

@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing Rowids""" """
2900 - Module for testing Rowids
"""
import TestEnv import TestEnv
@ -21,16 +22,16 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(len(rows), 1) self.assertEqual(len(rows), 1)
self.assertEqual(rows[0][0], intVal) self.assertEqual(rows[0][0], intVal)
def testSelectRowidsRegular(self): def test_2900_SelectRowidsRegular(self):
"test selecting all rowids from a regular table" "2900 - test selecting all rowids from a regular table"
self.__TestSelectRowids("TestNumbers") self.__TestSelectRowids("TestNumbers")
def testSelectRowidsIndexOrganised(self): def test_2901_SelectRowidsIndexOrganised(self):
"test selecting all rowids from an index organised table" "2901 - test selecting all rowids from an index organised table"
self.__TestSelectRowids("TestUniversalRowids") self.__TestSelectRowids("TestUniversalRowids")
def testInsertInvalidRowid(self): def test_2902_InsertInvalidRowid(self):
"test inserting an invalid rowid" "2902 - test inserting an invalid rowid"
self.assertRaises(cx_Oracle.DatabaseError, self.cursor.execute, self.assertRaises(cx_Oracle.DatabaseError, self.cursor.execute,
"insert into TestRowids (IntCol, RowidCol) values (1, :rid)", "insert into TestRowids (IntCol, RowidCol) values (1, :rid)",
rid = 12345) rid = 12345)
@ -38,8 +39,8 @@ class TestCase(TestEnv.BaseTestCase):
"insert into TestRowids (IntCol, RowidCol) values (1, :rid)", "insert into TestRowids (IntCol, RowidCol) values (1, :rid)",
rid = "523lkhlf") rid = "523lkhlf")
def testInsertRowids(self): def test_2903_InsertRowids(self):
"test inserting rowids and verify they are inserted correctly" "2903 - test inserting rowids and verify they are inserted correctly"
self.cursor.execute("select IntCol, rowid from TestNumbers") self.cursor.execute("select IntCol, rowid from TestNumbers")
rows = self.cursor.fetchall() rows = self.cursor.fetchall()
self.cursor.execute("truncate table TestRowids") self.cursor.execute("truncate table TestRowids")
@ -59,4 +60,3 @@ class TestCase(TestEnv.BaseTestCase):
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -1,8 +1,10 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing subscriptions.""" """
3000 - Module for testing subscriptions
"""
import TestEnv import TestEnv
@ -36,8 +38,8 @@ class SubscriptionData(object):
class TestCase(TestEnv.BaseTestCase): class TestCase(TestEnv.BaseTestCase):
def testSubscription(self): def test_3000_Subscription(self):
"test Subscription for insert, update, delete and truncate" "3000 - test Subscription for insert, update, delete and truncate"
# skip if running on the Oracle Cloud, which does not support # skip if running on the Oracle Cloud, which does not support
# subscriptions currently # subscriptions currently
@ -111,4 +113,3 @@ class TestCase(TestEnv.BaseTestCase):
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -1,5 +1,5 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
# #
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -7,12 +7,17 @@
# Canada. All rights reserved. # Canada. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing boolean variables.""" """
3100 - Module for testing boolean variables
"""
import unittest
import TestEnv import TestEnv
import cx_Oracle import cx_Oracle
@unittest.skipUnless(TestEnv.GetClientVersion() >= (12, 1),
"unsupported client")
class TestCase(TestEnv.BaseTestCase): class TestCase(TestEnv.BaseTestCase):
def __testBindValueAsBoolean(self, value): def __testBindValueAsBoolean(self, value):
@ -23,48 +28,48 @@ class TestCase(TestEnv.BaseTestCase):
(var,)) (var,))
self.assertEqual(result, expectedResult) self.assertEqual(result, expectedResult)
def testBindFalse(self): def test_3100_BindFalse(self):
"test binding in a False value" "3100 - test binding in a False value"
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str, result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
(False,)) (False,))
self.assertEqual(result, "FALSE") self.assertEqual(result, "FALSE")
def testBindFloatAsBoolean(self): def test_3101_BindFloatAsBoolean(self):
"test binding in a float as a boolean" "3101 - test binding in a float as a boolean"
self.__testBindValueAsBoolean(0.0) self.__testBindValueAsBoolean(0.0)
self.__testBindValueAsBoolean(1.0) self.__testBindValueAsBoolean(1.0)
def testBindIntegerAsBoolean(self): def test_3102_BindIntegerAsBoolean(self):
"test binding in an integer as a boolean" "3102 - test binding in an integer as a boolean"
self.__testBindValueAsBoolean(0) self.__testBindValueAsBoolean(0)
self.__testBindValueAsBoolean(1) self.__testBindValueAsBoolean(1)
def testBindNull(self): def test_3103_BindNull(self):
"test binding in a null value" "3103 - test binding in a null value"
self.cursor.setinputsizes(None, bool) self.cursor.setinputsizes(None, bool)
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str, result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
(None,)) (None,))
self.assertEqual(result, "NULL") self.assertEqual(result, "NULL")
def testBindOutFalse(self): def test_3104_BindOutFalse(self):
"test binding out a boolean value (False)" "3104 - test binding out a boolean value (False)"
result = self.cursor.callfunc("pkg_TestBooleans.IsLessThan10", result = self.cursor.callfunc("pkg_TestBooleans.IsLessThan10",
cx_Oracle.DB_TYPE_BOOLEAN, (15,)) cx_Oracle.DB_TYPE_BOOLEAN, (15,))
self.assertEqual(result, False) self.assertEqual(result, False)
def testBindOutTrue(self): def test_3105_BindOutTrue(self):
"test binding out a boolean value (True)" "3105 - test binding out a boolean value (True)"
result = self.cursor.callfunc("pkg_TestBooleans.IsLessThan10", bool, result = self.cursor.callfunc("pkg_TestBooleans.IsLessThan10", bool,
(5,)) (5,))
self.assertEqual(result, True) self.assertEqual(result, True)
def testBindStringAsBoolean(self): def test_3106_BindStringAsBoolean(self):
"test binding in a string as a boolean" "3106 - test binding in a string as a boolean"
self.__testBindValueAsBoolean("") self.__testBindValueAsBoolean("")
self.__testBindValueAsBoolean("0") self.__testBindValueAsBoolean("0")
def testBindTrue(self): def test_3107_BindTrue(self):
"test binding in a True value" "3107 - test binding in a True value"
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str, result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
(True,)) (True,))
self.assertEqual(result, "TRUE") self.assertEqual(result, "TRUE")

View File

@ -1,5 +1,5 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
# #
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -7,17 +7,22 @@
# Canada. All rights reserved. # Canada. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing features introduced in 12.1""" """
3200 - Module for testing features introduced in 12.1
"""
import TestEnv import TestEnv
import cx_Oracle import cx_Oracle
import datetime import datetime
import unittest
@unittest.skipUnless(TestEnv.GetClientVersion() >= (12, 1),
"unsupported client")
class TestCase(TestEnv.BaseTestCase): class TestCase(TestEnv.BaseTestCase):
def testArrayDMLRowCountsOff(self): def test_3200_ArrayDMLRowCountsOff(self):
"test executing with arraydmlrowcounts mode disabled" "3200 - test executing with arraydmlrowcounts mode disabled"
self.cursor.execute("truncate table TestArrayDML") self.cursor.execute("truncate table TestArrayDML")
rows = [ (1, "First"), rows = [ (1, "First"),
(2, "Second") ] (2, "Second") ]
@ -31,8 +36,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertRaises(cx_Oracle.DatabaseError, self.assertRaises(cx_Oracle.DatabaseError,
self.cursor.getarraydmlrowcounts) self.cursor.getarraydmlrowcounts)
def testArrayDMLRowCountsOn(self): def test_3201_ArrayDMLRowCountsOn(self):
"test executing with arraydmlrowcounts mode enabled" "3201 - test executing with arraydmlrowcounts mode enabled"
self.cursor.execute("truncate table TestArrayDML") self.cursor.execute("truncate table TestArrayDML")
rows = [ ( 1, "First", 100), rows = [ ( 1, "First", 100),
( 2, "Second", 200), ( 2, "Second", 200),
@ -48,8 +53,8 @@ class TestCase(TestEnv.BaseTestCase):
count, = self.cursor.fetchone() count, = self.cursor.fetchone()
self.assertEqual(count, len(rows)) self.assertEqual(count, len(rows))
def testBindPLSQLBooleanCollectionIn(self): def test_3202_BindPLSQLBooleanCollectionIn(self):
"test binding a boolean collection (in)" "3202 - test binding a boolean collection (in)"
typeObj = self.connection.gettype("PKG_TESTBOOLEANS.UDT_BOOLEANLIST") typeObj = self.connection.gettype("PKG_TESTBOOLEANS.UDT_BOOLEANLIST")
obj = typeObj.newobject() obj = typeObj.newobject()
obj.setelement(1, True) obj.setelement(1, True)
@ -58,15 +63,15 @@ class TestCase(TestEnv.BaseTestCase):
(obj,)) (obj,))
self.assertEqual(result, 5) self.assertEqual(result, 5)
def testBindPLSQLBooleanCollectionOut(self): def test_3203_BindPLSQLBooleanCollectionOut(self):
"test binding a boolean collection (out)" "3203 - test binding a boolean collection (out)"
typeObj = self.connection.gettype("PKG_TESTBOOLEANS.UDT_BOOLEANLIST") typeObj = self.connection.gettype("PKG_TESTBOOLEANS.UDT_BOOLEANLIST")
obj = typeObj.newobject() obj = typeObj.newobject()
self.cursor.callproc("pkg_TestBooleans.TestOutArrays", (6, obj)) self.cursor.callproc("pkg_TestBooleans.TestOutArrays", (6, obj))
self.assertEqual(obj.aslist(), [True, False, True, False, True, False]) self.assertEqual(obj.aslist(), [True, False, True, False, True, False])
def testBindPLSQLDateCollectionIn(self): def test_3204_BindPLSQLDateCollectionIn(self):
"test binding a PL/SQL date collection (in)" "3204 - test binding a PL/SQL date collection (in)"
typeObj = self.connection.gettype("PKG_TESTDATEARRAYS.UDT_DATELIST") typeObj = self.connection.gettype("PKG_TESTDATEARRAYS.UDT_DATELIST")
obj = typeObj.newobject() obj = typeObj.newobject()
obj.setelement(1, datetime.datetime(2016, 2, 5)) obj.setelement(1, datetime.datetime(2016, 2, 5))
@ -76,8 +81,8 @@ class TestCase(TestEnv.BaseTestCase):
cx_Oracle.NUMBER, (2, datetime.datetime(2016, 2, 1), obj)) cx_Oracle.NUMBER, (2, datetime.datetime(2016, 2, 1), obj))
self.assertEqual(result, 24.75) self.assertEqual(result, 24.75)
def testBindPLSQLDateCollectionInOut(self): def test_3205_BindPLSQLDateCollectionInOut(self):
"test binding a PL/SQL date collection (in/out)" "3205 - test binding a PL/SQL date collection (in/out)"
typeObj = self.connection.gettype("PKG_TESTDATEARRAYS.UDT_DATELIST") typeObj = self.connection.gettype("PKG_TESTDATEARRAYS.UDT_DATELIST")
obj = typeObj.newobject() obj = typeObj.newobject()
obj.setelement(1, datetime.datetime(2016, 1, 1)) obj.setelement(1, datetime.datetime(2016, 1, 1))
@ -91,8 +96,8 @@ class TestCase(TestEnv.BaseTestCase):
datetime.datetime(2016, 1, 20), datetime.datetime(2016, 1, 20),
datetime.datetime(2016, 1, 26)]) datetime.datetime(2016, 1, 26)])
def testBindPLSQLDateCollectionOut(self): def test_3206_BindPLSQLDateCollectionOut(self):
"test binding a PL/SQL date collection (out)" "3206 - test binding a PL/SQL date collection (out)"
typeObj = self.connection.gettype("PKG_TESTDATEARRAYS.UDT_DATELIST") typeObj = self.connection.gettype("PKG_TESTDATEARRAYS.UDT_DATELIST")
obj = typeObj.newobject() obj = typeObj.newobject()
self.cursor.callproc("pkg_TestDateArrays.TestOutArrays", (3, obj)) self.cursor.callproc("pkg_TestDateArrays.TestOutArrays", (3, obj))
@ -101,8 +106,8 @@ class TestCase(TestEnv.BaseTestCase):
datetime.datetime(2002, 12, 14, 9, 36), datetime.datetime(2002, 12, 14, 9, 36),
datetime.datetime(2002, 12, 15, 14, 24)]) datetime.datetime(2002, 12, 15, 14, 24)])
def testBindPLSQLNumberCollectionIn(self): def test_3207_BindPLSQLNumberCollectionIn(self):
"test binding a PL/SQL number collection (in)" "3207 - test binding a PL/SQL number collection (in)"
typeObj = self.connection.gettype("PKG_TESTNUMBERARRAYS.UDT_NUMBERLIST") typeObj = self.connection.gettype("PKG_TESTNUMBERARRAYS.UDT_NUMBERLIST")
obj = typeObj.newobject() obj = typeObj.newobject()
obj.setelement(1, 10) obj.setelement(1, 10)
@ -111,8 +116,8 @@ class TestCase(TestEnv.BaseTestCase):
(5, obj)) (5, obj))
self.assertEqual(result, 155) self.assertEqual(result, 155)
def testBindPLSQLNumberCollectionInOut(self): def test_3208_BindPLSQLNumberCollectionInOut(self):
"test binding a PL/SQL number collection (in/out)" "3208 - test binding a PL/SQL number collection (in/out)"
typeObj = self.connection.gettype("PKG_TESTNUMBERARRAYS.UDT_NUMBERLIST") typeObj = self.connection.gettype("PKG_TESTNUMBERARRAYS.UDT_NUMBERLIST")
obj = typeObj.newobject() obj = typeObj.newobject()
obj.setelement(1, 5) obj.setelement(1, 5)
@ -120,15 +125,15 @@ class TestCase(TestEnv.BaseTestCase):
self.cursor.callproc("pkg_TestNumberArrays.TestInOutArrays", (4, obj)) self.cursor.callproc("pkg_TestNumberArrays.TestInOutArrays", (4, obj))
self.assertEqual(obj.aslist(), [50, 80, 30, 20]) self.assertEqual(obj.aslist(), [50, 80, 30, 20])
def testBindPLSQLNumberCollectionOut(self): def test_3209_BindPLSQLNumberCollectionOut(self):
"test binding a PL/SQL number collection (out)" "3209 - test binding a PL/SQL number collection (out)"
typeObj = self.connection.gettype("PKG_TESTNUMBERARRAYS.UDT_NUMBERLIST") typeObj = self.connection.gettype("PKG_TESTNUMBERARRAYS.UDT_NUMBERLIST")
obj = typeObj.newobject() obj = typeObj.newobject()
self.cursor.callproc("pkg_TestNumberArrays.TestOutArrays", (3, obj)) self.cursor.callproc("pkg_TestNumberArrays.TestOutArrays", (3, obj))
self.assertEqual(obj.aslist(), [100, 200, 300]) self.assertEqual(obj.aslist(), [100, 200, 300])
def testBindPLSQLRecordArray(self): def test_3210_BindPLSQLRecordArray(self):
"test binding an array of PL/SQL records (in)" "3210 - test binding an array of PL/SQL records (in)"
recType = self.connection.gettype("PKG_TESTRECORDS.UDT_RECORD") recType = self.connection.gettype("PKG_TESTRECORDS.UDT_RECORD")
arrayType = self.connection.gettype("PKG_TESTRECORDS.UDT_RECORDARRAY") arrayType = self.connection.gettype("PKG_TESTRECORDS.UDT_RECORDARRAY")
arrayObj = arrayType.newobject() arrayObj = arrayType.newobject()
@ -158,8 +163,8 @@ class TestCase(TestEnv.BaseTestCase):
"to_timestamp('2017-01-03 00:00:00', " \ "to_timestamp('2017-01-03 00:00:00', " \
"'YYYY-MM-DD HH24:MI:SS'), false, 10, 4)") "'YYYY-MM-DD HH24:MI:SS'), false, 10, 4)")
def testBindPLSQLRecordIn(self): def test_3211_BindPLSQLRecordIn(self):
"test binding a PL/SQL record (in)" "3211 - test binding a PL/SQL record (in)"
typeObj = self.connection.gettype("PKG_TESTRECORDS.UDT_RECORD") typeObj = self.connection.gettype("PKG_TESTRECORDS.UDT_RECORD")
obj = typeObj.newobject() obj = typeObj.newobject()
obj.NUMBERVALUE = 18 obj.NUMBERVALUE = 18
@ -177,8 +182,8 @@ class TestCase(TestEnv.BaseTestCase):
"to_timestamp('2016-02-12 14:25:36', " \ "to_timestamp('2016-02-12 14:25:36', " \
"'YYYY-MM-DD HH24:MI:SS'), false, 21, 5)") "'YYYY-MM-DD HH24:MI:SS'), false, 21, 5)")
def testBindPLSQLRecordOut(self): def test_3212_BindPLSQLRecordOut(self):
"test binding a PL/SQL record (out)" "3212 - test binding a PL/SQL record (out)"
typeObj = self.connection.gettype("PKG_TESTRECORDS.UDT_RECORD") typeObj = self.connection.gettype("PKG_TESTRECORDS.UDT_RECORD")
obj = typeObj.newobject() obj = typeObj.newobject()
obj.NUMBERVALUE = 5 obj.NUMBERVALUE = 5
@ -198,8 +203,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(obj.PLSINTEGERVALUE, 45) self.assertEqual(obj.PLSINTEGERVALUE, 45)
self.assertEqual(obj.BINARYINTEGERVALUE, 10) self.assertEqual(obj.BINARYINTEGERVALUE, 10)
def testBindPLSQLStringCollectionIn(self): def test_3213_BindPLSQLStringCollectionIn(self):
"test binding a PL/SQL string collection (in)" "3213 - test binding a PL/SQL string collection (in)"
typeObj = self.connection.gettype("PKG_TESTSTRINGARRAYS.UDT_STRINGLIST") typeObj = self.connection.gettype("PKG_TESTSTRINGARRAYS.UDT_STRINGLIST")
obj = typeObj.newobject() obj = typeObj.newobject()
obj.setelement(1, "First element") obj.setelement(1, "First element")
@ -209,8 +214,8 @@ class TestCase(TestEnv.BaseTestCase):
(5, obj)) (5, obj))
self.assertEqual(result, 45) self.assertEqual(result, 45)
def testBindPLSQLStringCollectionInOut(self): def test_3214_BindPLSQLStringCollectionInOut(self):
"test binding a PL/SQL string collection (in/out)" "3214 - test binding a PL/SQL string collection (in/out)"
typeObj = self.connection.gettype("PKG_TESTSTRINGARRAYS.UDT_STRINGLIST") typeObj = self.connection.gettype("PKG_TESTSTRINGARRAYS.UDT_STRINGLIST")
obj = typeObj.newobject() obj = typeObj.newobject()
obj.setelement(1, "The first element") obj.setelement(1, "The first element")
@ -222,8 +227,8 @@ class TestCase(TestEnv.BaseTestCase):
'Converted element # 2 originally had length 18', 'Converted element # 2 originally had length 18',
'Converted element # 3 originally had length 27']) 'Converted element # 3 originally had length 27'])
def testBindPLSQLStringCollectionOut(self): def test_3215_BindPLSQLStringCollectionOut(self):
"test binding a PL/SQL string collection (out)" "3215 - test binding a PL/SQL string collection (out)"
typeObj = self.connection.gettype("PKG_TESTSTRINGARRAYS.UDT_STRINGLIST") typeObj = self.connection.gettype("PKG_TESTSTRINGARRAYS.UDT_STRINGLIST")
obj = typeObj.newobject() obj = typeObj.newobject()
self.cursor.callproc("pkg_TestStringArrays.TestOutArrays", (4, obj)) self.cursor.callproc("pkg_TestStringArrays.TestOutArrays", (4, obj))
@ -233,8 +238,8 @@ class TestCase(TestEnv.BaseTestCase):
'Test out element # 3', 'Test out element # 3',
'Test out element # 4']) 'Test out element # 4'])
def testBindPLSQLStringCollectionOutWithHoles(self): def test_3216_BindPLSQLStringCollectionOutWithHoles(self):
"test binding a PL/SQL string collection (out with holes)" "3216 - test binding a PL/SQL string collection (out with holes)"
typeObj = self.connection.gettype("PKG_TESTSTRINGARRAYS.UDT_STRINGLIST") typeObj = self.connection.gettype("PKG_TESTSTRINGARRAYS.UDT_STRINGLIST")
obj = typeObj.newobject() obj = typeObj.newobject()
self.cursor.callproc("pkg_TestStringArrays.TestIndexBy", (obj,)) self.cursor.callproc("pkg_TestStringArrays.TestIndexBy", (obj,))
@ -261,8 +266,8 @@ class TestCase(TestEnv.BaseTestCase):
{ -1048576 : 'First element', { -1048576 : 'First element',
8388608: 'Fourth element' }) 8388608: 'Fourth element' })
def testExceptionInIteration(self): def test_3217_ExceptionInIteration(self):
"test executing with arraydmlrowcounts with exception" "3217 - test executing with arraydmlrowcounts with exception"
self.cursor.execute("truncate table TestArrayDML") self.cursor.execute("truncate table TestArrayDML")
rows = [ (1, "First"), rows = [ (1, "First"),
(2, "Second"), (2, "Second"),
@ -273,8 +278,8 @@ class TestCase(TestEnv.BaseTestCase):
sql, rows, arraydmlrowcounts = True) sql, rows, arraydmlrowcounts = True)
self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 1]) self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 1])
def testExecutingDelete(self): def test_3218_ExecutingDelete(self):
"test executing delete statement with arraydmlrowcount mode" "3218 - test executing delete statement with arraydmlrowcount mode"
self.cursor.execute("truncate table TestArrayDML") self.cursor.execute("truncate table TestArrayDML")
rows = [ (1, "First", 100), rows = [ (1, "First", 100),
(2, "Second", 200), (2, "Second", 200),
@ -293,8 +298,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 3, 2]) self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 3, 2])
self.assertEqual(self.cursor.rowcount, 6) self.assertEqual(self.cursor.rowcount, 6)
def testExecutingUpdate(self): def test_3219_ExecutingUpdate(self):
"test executing update statement with arraydmlrowcount mode" "3219 - test executing update statement with arraydmlrowcount mode"
self.cursor.execute("truncate table TestArrayDML") self.cursor.execute("truncate table TestArrayDML")
rows = [ (1, "First",100), rows = [ (1, "First",100),
(2, "Second",200), (2, "Second",200),
@ -316,8 +321,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 1, 3, 2]) self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 1, 3, 2])
self.assertEqual(self.cursor.rowcount, 7) self.assertEqual(self.cursor.rowcount, 7)
def testImplicitResults(self): def test_3220_ImplicitResults(self):
"test getimplicitresults() returns the correct data" "3220 - test getimplicitresults() returns the correct data"
self.cursor.execute(""" self.cursor.execute("""
declare declare
c1 sys_refcursor; c1 sys_refcursor;
@ -344,13 +349,13 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual([n for n, in results[0]], [3.75, 5, 6.25]) self.assertEqual([n for n, in results[0]], [3.75, 5, 6.25])
self.assertEqual([n for n, in results[1]], [8.75, 10, 11.25, 12.5]) self.assertEqual([n for n, in results[1]], [8.75, 10, 11.25, 12.5])
def testImplicitResultsNoStatement(self): def test_3221_ImplicitResultsNoStatement(self):
"test getimplicitresults() without executing a statement" "3221 - test getimplicitresults() without executing a statement"
self.assertRaises(cx_Oracle.InterfaceError, self.assertRaises(cx_Oracle.InterfaceError,
self.cursor.getimplicitresults) self.cursor.getimplicitresults)
def testInsertWithBatchError(self): def test_3222_InsertWithBatchError(self):
"test executing insert with multiple distinct batch errors" "3222 - test executing insert with multiple distinct batch errors"
self.cursor.execute("truncate table TestArrayDML") self.cursor.execute("truncate table TestArrayDML")
rows = [ (1, "First", 100), rows = [ (1, "First", 100),
(2, "Second", 200), (2, "Second", 200),
@ -373,8 +378,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(actualErrors, expectedErrors) self.assertEqual(actualErrors, expectedErrors)
self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 1, 0, 1, 0]) self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 1, 0, 1, 0])
def testBatchErrorFalse(self): def test_3223_BatchErrorFalse(self):
"test batcherrors mode set to False" "3223 - test batcherrors mode set to False"
self.cursor.execute("truncate table TestArrayDML") self.cursor.execute("truncate table TestArrayDML")
rows = [ (1, "First", 100), rows = [ (1, "First", 100),
(2, "Second", 200), (2, "Second", 200),
@ -384,8 +389,8 @@ class TestCase(TestEnv.BaseTestCase):
self.assertRaises(cx_Oracle.IntegrityError, self.assertRaises(cx_Oracle.IntegrityError,
self.cursor.executemany, sql, rows, batcherrors = False) self.cursor.executemany, sql, rows, batcherrors = False)
def testUpdatewithBatchError(self): def test_3224_UpdatewithBatchError(self):
"test executing in succession with batch error" "3224 - test executing in succession with batch error"
self.cursor.execute("truncate table TestArrayDML") self.cursor.execute("truncate table TestArrayDML")
rows = [ (1, "First", 100), rows = [ (1, "First", 100),
(2, "Second", 200), (2, "Second", 200),
@ -427,4 +432,3 @@ class TestCase(TestEnv.BaseTestCase):
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -1,14 +1,19 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing Simple Oracle Document Access (SODA) Database""" """
3300 - Module for testing Simple Oracle Document Access (SODA) Database
"""
import TestEnv import TestEnv
import cx_Oracle import cx_Oracle
import json import json
import unittest
@unittest.skipIf(TestEnv.SkipSodaTests(),
"unsupported client/server combination")
class TestCase(TestEnv.BaseTestCase): class TestCase(TestEnv.BaseTestCase):
def __dropExistingCollections(self, sodaDatabase): def __dropExistingCollections(self, sodaDatabase):
@ -25,9 +30,9 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(doc.key, key) self.assertEqual(doc.key, key)
self.assertEqual(doc.mediaType, mediaType) self.assertEqual(doc.mediaType, mediaType)
def testCreateDocumentWithJson(self): def test_3300_CreateDocumentWithJson(self):
"test creating documents with JSON data" "3300 - test creating documents with JSON data"
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
val = {"testKey1" : "testValue1", "testKey2" : "testValue2" } val = {"testKey1" : "testValue1", "testKey2" : "testValue2" }
strVal = json.dumps(val) strVal = json.dumps(val)
bytesVal = strVal.encode("UTF-8") bytesVal = strVal.encode("UTF-8")
@ -40,9 +45,9 @@ class TestCase(TestEnv.BaseTestCase):
doc = sodaDatabase.createDocument(bytesVal, key, mediaType) doc = sodaDatabase.createDocument(bytesVal, key, mediaType)
self.__verifyDocument(doc, bytesVal, strVal, val, key, mediaType) self.__verifyDocument(doc, bytesVal, strVal, val, key, mediaType)
def testCreateDocumentWithRaw(self): def test_3301_CreateDocumentWithRaw(self):
"test creating documents with raw data" "3301 - test creating documents with raw data"
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
val = b"<html/>" val = b"<html/>"
key = "MyRawKey" key = "MyRawKey"
mediaType = "text/html" mediaType = "text/html"
@ -53,9 +58,9 @@ class TestCase(TestEnv.BaseTestCase):
doc = sodaDatabase.createDocument(val, key, mediaType) doc = sodaDatabase.createDocument(val, key, mediaType)
self.__verifyDocument(doc, val, key=key, mediaType=mediaType) self.__verifyDocument(doc, val, key=key, mediaType=mediaType)
def testGetCollectionNames(self): def test_3302_GetCollectionNames(self):
"test getting collection names from the database" "3302 - test getting collection names from the database"
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
self.__dropExistingCollections(sodaDatabase) self.__dropExistingCollections(sodaDatabase)
self.assertEqual(sodaDatabase.getCollectionNames(), []) self.assertEqual(sodaDatabase.getCollectionNames(), [])
names = ["zCol", "dCol", "sCol", "aCol", "gCol"] names = ["zCol", "dCol", "sCol", "aCol", "gCol"]
@ -72,9 +77,9 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(sodaDatabase.getCollectionNames("z"), self.assertEqual(sodaDatabase.getCollectionNames("z"),
sortedNames[-1:]) sortedNames[-1:])
def testOpenCollection(self): def test_3303_OpenCollection(self):
"test opening a collection" "3303 - test opening a collection"
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
self.__dropExistingCollections(sodaDatabase) self.__dropExistingCollections(sodaDatabase)
coll = sodaDatabase.openCollection("CollectionThatDoesNotExist") coll = sodaDatabase.openCollection("CollectionThatDoesNotExist")
self.assertEqual(coll, None) self.assertEqual(coll, None)
@ -83,19 +88,19 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(coll.name, createdColl.name) self.assertEqual(coll.name, createdColl.name)
coll.drop() coll.drop()
def testRepr(self): def test_3304_Repr(self):
"test SodaDatabase representation" "3304 - test SodaDatabase representation"
con1 = self.connection con1 = self.connection
con2 = TestEnv.GetConnection() con2 = TestEnv.GetConnection()
sodaDatabase1 = self.getSodaDatabase() sodaDatabase1 = self.connection.getSodaDatabase()
sodaDatabase2 = con1.getSodaDatabase() sodaDatabase2 = con1.getSodaDatabase()
sodaDatabase3 = con2.getSodaDatabase() sodaDatabase3 = con2.getSodaDatabase()
self.assertEqual(str(sodaDatabase1), str(sodaDatabase2)) self.assertEqual(str(sodaDatabase1), str(sodaDatabase2))
self.assertEqual(str(sodaDatabase2), str(sodaDatabase3)) self.assertEqual(str(sodaDatabase2), str(sodaDatabase3))
def testNegative(self): def test_3305_Negative(self):
"test negative cases for SODA database methods" "3305 - test negative cases for SODA database methods"
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
self.assertRaises(TypeError, sodaDatabase.createCollection) self.assertRaises(TypeError, sodaDatabase.createCollection)
self.assertRaises(TypeError, sodaDatabase.createCollection, 1) self.assertRaises(TypeError, sodaDatabase.createCollection, 1)
self.assertRaises(cx_Oracle.DatabaseError, self.assertRaises(cx_Oracle.DatabaseError,

View File

@ -1,13 +1,18 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
"""Module for testing Simple Oracle Document Access (SODA) Collections""" """
3400 - Module for testing Simple Oracle Document Access (SODA) Collections
"""
import TestEnv import TestEnv
import cx_Oracle import cx_Oracle
import unittest
@unittest.skipIf(TestEnv.SkipSodaTests(),
"unsupported client/server combination")
class TestCase(TestEnv.BaseTestCase): class TestCase(TestEnv.BaseTestCase):
def __testSkip(self, coll, numToSkip, expectedContent): def __testSkip(self, coll, numToSkip, expectedContent):
@ -16,18 +21,18 @@ class TestCase(TestEnv.BaseTestCase):
content = doc.getContent() if doc is not None else None content = doc.getContent() if doc is not None else None
self.assertEqual(content, expectedContent) self.assertEqual(content, expectedContent)
def testInvalidJson(self): def test_3400_InvalidJson(self):
"test inserting invalid JSON value into SODA collection" "3400 - test inserting invalid JSON value into SODA collection"
invalidJson = "{testKey:testValue}" invalidJson = "{testKey:testValue}"
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
coll = sodaDatabase.createCollection("cxoInvalidJSON") coll = sodaDatabase.createCollection("cxoInvalidJSON")
doc = sodaDatabase.createDocument(invalidJson) doc = sodaDatabase.createDocument(invalidJson)
self.assertRaises(cx_Oracle.IntegrityError, coll.insertOne, doc) self.assertRaises(cx_Oracle.IntegrityError, coll.insertOne, doc)
coll.drop() coll.drop()
def testInsertDocuments(self): def test_3401_InsertDocuments(self):
"test inserting documents into a SODA collection" "3401 - test inserting documents into a SODA collection"
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
coll = sodaDatabase.createCollection("cxoInsertDocs") coll = sodaDatabase.createCollection("cxoInsertDocs")
coll.find().remove() coll.find().remove()
valuesToInsert = [ valuesToInsert = [
@ -47,9 +52,9 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(doc.getContent(), value) self.assertEqual(doc.getContent(), value)
coll.drop() coll.drop()
def testSkipDocuments(self): def test_3402_SkipDocuments(self):
"test skipping documents in a SODA collection" "3402 - test skipping documents in a SODA collection"
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
coll = sodaDatabase.createCollection("cxoSkipDocs") coll = sodaDatabase.createCollection("cxoSkipDocs")
coll.find().remove() coll.find().remove()
valuesToInsert = [ valuesToInsert = [
@ -67,9 +72,9 @@ class TestCase(TestEnv.BaseTestCase):
self.__testSkip(coll, 4, None) self.__testSkip(coll, 4, None)
self.__testSkip(coll, 125, None) self.__testSkip(coll, 125, None)
def testReplaceDocument(self): def test_3403_ReplaceDocument(self):
"test replace documents in SODA collection" "3403 - test replace documents in SODA collection"
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
coll = sodaDatabase.createCollection("cxoReplaceDoc") coll = sodaDatabase.createCollection("cxoReplaceDoc")
coll.find().remove() coll.find().remove()
content = {'name': 'John', 'address': {'city': 'Sydney'}} content = {'name': 'John', 'address': {'city': 'Sydney'}}
@ -81,9 +86,9 @@ class TestCase(TestEnv.BaseTestCase):
newContent) newContent)
coll.drop() coll.drop()
def testSearchDocumentsWithContent(self): def test_3404_SearchDocumentsWithContent(self):
"test search documents with content using $like and $regex" "3404 - test search documents with content using $like and $regex"
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
coll = sodaDatabase.createCollection("cxoSearchDocContent") coll = sodaDatabase.createCollection("cxoSearchDocContent")
coll.find().remove() coll.find().remove()
data = [ data = [
@ -118,9 +123,9 @@ class TestCase(TestEnv.BaseTestCase):
expectedCount, filterSpec) expectedCount, filterSpec)
coll.drop() coll.drop()
def testDocumentRemove(self): def test_3405_DocumentRemove(self):
"test removing documents" "3405 - test removing documents"
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
coll = sodaDatabase.createCollection("cxoRemoveDocs") coll = sodaDatabase.createCollection("cxoRemoveDocs")
coll.find().remove() coll.find().remove()
data = [ data = [
@ -143,8 +148,8 @@ class TestCase(TestEnv.BaseTestCase):
self.connection.commit() self.connection.commit()
coll.drop() coll.drop()
def testCreateAndDropIndex(self): def test_3406_CreateAndDropIndex(self):
"test create and drop Index" "3406 - test create and drop Index"
indexName = "cxoTestIndexes_ix_1" indexName = "cxoTestIndexes_ix_1"
indexSpec = { indexSpec = {
'name': indexName, 'name': indexName,
@ -156,7 +161,7 @@ class TestCase(TestEnv.BaseTestCase):
} }
] ]
} }
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
coll = sodaDatabase.createCollection("cxoTestIndexes") coll = sodaDatabase.createCollection("cxoTestIndexes")
coll.find().remove() coll.find().remove()
self.connection.commit() self.connection.commit()
@ -167,10 +172,10 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(coll.dropIndex(indexName), False) self.assertEqual(coll.dropIndex(indexName), False)
coll.drop() coll.drop()
def testGetDocuments(self): def test_3407_GetDocuments(self):
"test getting documents from Collection" "3407 - test getting documents from Collection"
self.connection.autocommit = True self.connection.autocommit = True
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
coll = sodaDatabase.createCollection("cxoTestGetDocs") coll = sodaDatabase.createCollection("cxoTestGetDocs")
coll.find().remove() coll.find().remove()
data = [ data = [
@ -185,10 +190,10 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(fetchedKeys, insertedKeys) self.assertEqual(fetchedKeys, insertedKeys)
coll.drop() coll.drop()
def testCursor(self): def test_3408_Cursor(self):
"test fetching documents from a cursor" "3408 - test fetching documents from a cursor"
self.connection.autocommit = True self.connection.autocommit = True
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
coll = sodaDatabase.createCollection("cxoFindViaCursor") coll = sodaDatabase.createCollection("cxoFindViaCursor")
coll.find().remove() coll.find().remove()
data = [ data = [
@ -201,9 +206,9 @@ class TestCase(TestEnv.BaseTestCase):
self.assertEqual(fetchedKeys, insertedKeys) self.assertEqual(fetchedKeys, insertedKeys)
coll.drop() coll.drop()
def testMultipleDocumentRemove(self): def test_3409_MultipleDocumentRemove(self):
"test removing multiple documents using multiple keys" "3409 - test removing multiple documents using multiple keys"
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
coll = sodaDatabase.createCollection("cxoRemoveMultipleDocs") coll = sodaDatabase.createCollection("cxoRemoveMultipleDocs")
coll.find().remove() coll.find().remove()
data = [ data = [
@ -222,9 +227,9 @@ class TestCase(TestEnv.BaseTestCase):
self.connection.commit() self.connection.commit()
coll.drop() coll.drop()
def testDocumentVersion(self): def test_3410_DocumentVersion(self):
"test using version to get documents and remove them" "3410 - test using version to get documents and remove them"
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
coll = sodaDatabase.createCollection("cxoDocumentVersion") coll = sodaDatabase.createCollection("cxoDocumentVersion")
coll.find().remove() coll.find().remove()
content = {'name': 'John', 'address': {'city': 'Bangalore'}} content = {'name': 'John', 'address': {'city': 'Bangalore'}}
@ -246,9 +251,9 @@ class TestCase(TestEnv.BaseTestCase):
self.connection.commit() self.connection.commit()
coll.drop() coll.drop()
def testGetCursor(self): def test_3411_GetCursor(self):
"test keys with GetCursor" "3411 - test keys with GetCursor"
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
coll = sodaDatabase.createCollection("cxoKeysWithGetCursor") coll = sodaDatabase.createCollection("cxoKeysWithGetCursor")
coll.find().remove() coll.find().remove()
data = [ data = [
@ -266,18 +271,20 @@ class TestCase(TestEnv.BaseTestCase):
self.connection.commit() self.connection.commit()
coll.drop() coll.drop()
def testCreatedOn(self): def test_3412_CreatedOn(self):
"test createdOn attribute of Document" "3412 - test createdOn attribute of Document"
sodaDatabase = self.getSodaDatabase() sodaDatabase = self.connection.getSodaDatabase()
coll = sodaDatabase.createCollection("cxoCreatedOn") coll = sodaDatabase.createCollection("cxoCreatedOn")
coll.find().remove() coll.find().remove()
data = {'name': 'John', 'address': {'city': 'Bangalore'}} data = {'name': 'John', 'address': {'city': 'Bangalore'}}
doc = coll.insertOneAndGet(data) doc = coll.insertOneAndGet(data)
self.assertEqual(doc.createdOn, doc.lastModified) self.assertEqual(doc.createdOn, doc.lastModified)
def testSodaTruncate(self): @unittest.skipIf(TestEnv.GetClientVersion() < (20, 1),
"test Soda truncate" "unsupported client")
sodaDatabase = self.getSodaDatabase(minclient=(20,1)) def test_3413_SodaTruncate(self):
"3413 - test Soda truncate"
sodaDatabase = self.connection.getSodaDatabase()
coll = sodaDatabase.createCollection("cxoTruncateDocs") coll = sodaDatabase.createCollection("cxoTruncateDocs")
coll.find().remove() coll.find().remove()
valuesToInsert = [ valuesToInsert = [
@ -296,4 +303,3 @@ class TestCase(TestEnv.BaseTestCase):
if __name__ == "__main__": if __name__ == "__main__":
TestEnv.RunTestCases() TestEnv.RunTestCases()

View File

@ -1,56 +0,0 @@
#------------------------------------------------------------------------------
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
#
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
#
# Portions Copyright 2001-2007, Computronix (Canada) Ltd., Edmonton, Alberta,
# Canada. All rights reserved.
#------------------------------------------------------------------------------
"""Driver specific portion of the DB API test suite provided by Stuart Bishop
available at http://stuartbishop.net/Software/DBAPI20TestSuite/"""
import cx_Oracle
import dbapi20
import unittest
import TestEnv
class TestSuite(dbapi20.DatabaseAPI20Test):
connect_args = (TestEnv.GetMainUser(), TestEnv.GetMainPassword(),
TestEnv.GetConnectString())
driver = cx_Oracle
# not implemented; see cx_Oracle specific test suite instead
def test_callproc(self):
pass
# not implemented; see cx_Oracle specific test suite instead
def test_fetchmany(self):
pass
# not implemented; Oracle does not support the concept
def test_nextset(self):
pass
# not implemented; see cx_Oracle specific test suite instead
def test_rowcount(self):
pass
# not implemented; see cx_Oracle specific test suite instead
def test_setinputsizes(self):
pass
# not implemented; not used by cx_Oracle
def test_setoutputsize(self):
pass
# not implemented; Oracle does not support the concept
def test_Time(self):
pass
if __name__ == "__main__":
print("Testing cx_Oracle version", cx_Oracle.__version__)
TestEnv.RunTestCases()

15
tox.ini Normal file
View File

@ -0,0 +1,15 @@
[tox]
envlist = py{36,37,38,39}
[testenv]
commands = {envpython} test/TestEnv.py
passenv =
CX_ORACLE_TEST_MAIN_USER
CX_ORACLE_TEST_MAIN_PASSWORD
CX_ORACLE_TEST_PROXY_USER
CX_ORACLE_TEST_PROXY_PASSWORD
CX_ORACLE_TEST_CONNECT_STRING
CX_ORACLE_TEST_ADMIN_USER
CX_ORACLE_TEST_ADMIN_PASSWORD
DPI_DEBUG_LEVEL
ORACLE_HOME