Skip to content

Commit 928c1b9

Browse files
committed
Testing: Refactor software tests into dedicated directory tests
git mv src/crate/client/test* tests/client/ git mv src/crate/testing/test* tests/testing/
1 parent 915f9a0 commit 928c1b9

30 files changed

+134
-132
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Unreleased
1212
"Threads may share the module, but not connections."
1313
- Added ``error_trace`` to string representation of an Error to relay
1414
server stacktraces into exception messages.
15+
- Refactoring: The module namespace ``crate.client.test_util`` has been
16+
renamed to ``crate.testing.util``.
1517

1618
.. _Migrate from crate.client to sqlalchemy-cratedb: https://cratedb.com/docs/sqlalchemy-cratedb/migrate-from-crate-client.html
1719
.. _sqlalchemy-cratedb: https://pypi.org/project/sqlalchemy-cratedb/

DEVELOP.rst

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,40 @@ see, for example, `useful command-line options for zope-testrunner`_.
3232

3333
Run all tests::
3434

35-
./bin/test -vvvv
35+
bin/test
3636

3737
Run specific tests::
3838

39-
./bin/test -vvvv -t test_score
39+
# Select modules.
40+
bin/test -t test_cursor
41+
bin/test -t client
42+
bin/test -t testing
43+
44+
# Select doctests.
45+
bin/test -t http.rst
4046

4147
Ignore specific test directories::
4248

43-
./bin/test -vvvv --ignore_dir=testing
49+
bin/test --ignore_dir=testing
4450

4551
The ``LayerTest`` test cases have quite some overhead. Omitting them will save
4652
a few cycles (~70 seconds runtime)::
4753

48-
./bin/test -t '!LayerTest'
54+
bin/test -t '!LayerTest'
4955

50-
Invoke all tests without integration tests (~15 seconds runtime)::
56+
Invoke all tests without integration tests (~10 seconds runtime)::
5157

52-
./bin/test --layer '!crate.testing.layer.crate' --test '!LayerTest'
58+
bin/test --layer '!crate.testing.layer.crate' --test '!LayerTest'
5359

54-
Yet ~130 test cases, but only ~5 seconds runtime::
60+
Yet ~60 test cases, but only ~1 second runtime::
5561

56-
./bin/test --layer '!crate.testing.layer.crate' --test '!LayerTest' \
62+
bin/test --layer '!crate.testing.layer.crate' --test '!LayerTest' \
5763
-t '!test_client_threaded' -t '!test_no_retry_on_read_timeout' \
5864
-t '!test_wait_for_http' -t '!test_table_clustered_by'
5965

6066
To inspect the whole list of test cases, run::
6167

62-
./bin/test --list-tests
68+
bin/test --list-tests
6369

6470
You can run the tests against multiple Python interpreters with `tox`_::
6571

bin/test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ sys.argv[0] = os.path.abspath(sys.argv[0])
1212

1313
if __name__ == '__main__':
1414
zope.testrunner.run([
15-
'-vvv', '--auto-color',
16-
'--test-path', join(base, 'src')],
17-
)
15+
'-vvvv', '--auto-color',
16+
'--path', join(base, 'tests'),
17+
])

docs/by-example/connection.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ connect()
2121
This section sets up a connection object, and inspects some of its attributes.
2222

2323
>>> from crate.client import connect
24-
>>> from crate.client.test_util import ClientMocked
24+
>>> from crate.testing.util import ClientMocked
2525

2626
>>> connection = connect(client=ClientMocked())
2727
>>> connection.lowest_server_version.version

docs/by-example/cursor.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ up the response for subsequent cursor operations.
2323
>>> from crate.client import connect
2424
>>> from crate.client.converter import DefaultTypeConverter
2525
>>> from crate.client.cursor import Cursor
26-
>>> from crate.client.test_util import ClientMocked
26+
>>> from crate.testing.util import ClientMocked
2727

2828
>>> connection = connect(client=ClientMocked())
2929
>>> cursor = connection.cursor()

src/crate/client/test_util.py

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/crate/testing/util.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,74 @@
1+
# -*- coding: utf-8; -*-
2+
#
3+
# Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
4+
# license agreements. See the NOTICE file distributed with this work for
5+
# additional information regarding copyright ownership. Crate licenses
6+
# this file to you under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License. You may
8+
# obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
# License for the specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
# However, if you have executed another commercial license agreement
19+
# with Crate these terms will supersede the license and you may use the
20+
# software solely pursuant to the terms of the relevant commercial agreement.
21+
import unittest
22+
23+
24+
class ClientMocked(object):
25+
26+
active_servers = ["http://localhost:4200"]
27+
28+
def __init__(self):
29+
self.response = {}
30+
self._server_infos = ("http://localhost:4200", "my server", "2.0.0")
31+
32+
def sql(self, stmt=None, parameters=None, bulk_parameters=None):
33+
return self.response
34+
35+
def server_infos(self, server):
36+
return self._server_infos
37+
38+
def set_next_response(self, response):
39+
self.response = response
40+
41+
def set_next_server_infos(self, server, server_name, version):
42+
self._server_infos = (server, server_name, version)
43+
44+
def close(self):
45+
pass
46+
47+
48+
class ParametrizedTestCase(unittest.TestCase):
49+
"""
50+
TestCase classes that want to be parametrized should
51+
inherit from this class.
52+
53+
https://eli.thegreenplace.net/2011/08/02/python-unit-testing-parametrized-test-cases
54+
"""
55+
def __init__(self, methodName="runTest", param=None):
56+
super(ParametrizedTestCase, self).__init__(methodName)
57+
self.param = param
58+
59+
@staticmethod
60+
def parametrize(testcase_klass, param=None):
61+
""" Create a suite containing all tests taken from the given
62+
subclass, passing them the parameter 'param'.
63+
"""
64+
testloader = unittest.TestLoader()
65+
testnames = testloader.getTestCaseNames(testcase_klass)
66+
suite = unittest.TestSuite()
67+
for name in testnames:
68+
suite.addTest(testcase_klass(name, param=param))
69+
return suite
70+
71+
172
class ExtraAssertions:
273
"""
374
Additional assert methods for unittest.

tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)