|
| 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 | + |
1 | 72 | class ExtraAssertions: |
2 | 73 | """ |
3 | 74 | Additional assert methods for unittest. |
|
0 commit comments