From 44038eb9b630eafad57e30e09d021de8d68e94d5 Mon Sep 17 00:00:00 2001 From: Nathaniel Manista Date: Sat, 16 Sep 2017 16:13:09 +0000 Subject: Tweak Python sanity test - Move it out of the "unit" package, as it's not itself a unit test. - Suffix the test class with "Test" as we do with every other subclass of unittest.TestCase. - Add a larger-than-we'll-need-any-time-soon maxDiff so that failures are fully described. - Relax the assertion from assertListEqual to assertSequenceEqual since we don't actually care whether or not the sequences being compared are list instances. - Change the order of the assertions arguments to match the ", " convention used in our assert*Equal calls elsewhere throughout the test corpus. - Internal implementation simplifications. --- src/python/grpcio_tests/tests/_sanity/__init__.py | 13 ++++++ .../grpcio_tests/tests/_sanity/_sanity_test.py | 46 ++++++++++++++++++++++ src/python/grpcio_tests/tests/tests.json | 2 +- .../grpcio_tests/tests/unit/_sanity/__init__.py | 13 ------ .../tests/unit/_sanity/_sanity_test.py | 45 --------------------- 5 files changed, 60 insertions(+), 59 deletions(-) create mode 100644 src/python/grpcio_tests/tests/_sanity/__init__.py create mode 100644 src/python/grpcio_tests/tests/_sanity/_sanity_test.py delete mode 100644 src/python/grpcio_tests/tests/unit/_sanity/__init__.py delete mode 100644 src/python/grpcio_tests/tests/unit/_sanity/_sanity_test.py diff --git a/src/python/grpcio_tests/tests/_sanity/__init__.py b/src/python/grpcio_tests/tests/_sanity/__init__.py new file mode 100644 index 0000000000..5772620b60 --- /dev/null +++ b/src/python/grpcio_tests/tests/_sanity/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2016 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/src/python/grpcio_tests/tests/_sanity/_sanity_test.py b/src/python/grpcio_tests/tests/_sanity/_sanity_test.py new file mode 100644 index 0000000000..b4079850ff --- /dev/null +++ b/src/python/grpcio_tests/tests/_sanity/_sanity_test.py @@ -0,0 +1,46 @@ +# Copyright 2016 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json +import unittest + +import pkg_resources +import six + +import tests + + +class SanityTest(unittest.TestCase): + + maxDiff = 32768 + + def testTestsJsonUpToDate(self): + """Autodiscovers all test suites and checks that tests.json is up to date""" + loader = tests.Loader() + loader.loadTestsFromNames(['tests']) + test_suite_names = sorted({ + test_case_class.id().rsplit('.', 1)[0] + for test_case_class in tests._loader.iterate_suite_cases( + loader.suite) + }) + + tests_json_string = pkg_resources.resource_string('tests', 'tests.json') + tests_json = json.loads(tests_json_string.decode() + if six.PY3 else tests_json_string) + + self.assertSequenceEqual(tests_json, test_suite_names) + + +if __name__ == '__main__': + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/tests.json b/src/python/grpcio_tests/tests/tests.json index 4c078e6c22..a3f2a9d820 100644 --- a/src/python/grpcio_tests/tests/tests.json +++ b/src/python/grpcio_tests/tests/tests.json @@ -1,4 +1,5 @@ [ + "_sanity._sanity_test.SanityTest", "health_check._health_servicer_test.HealthServicerTest", "interop._insecure_intraop_test.InsecureIntraopTest", "interop._secure_intraop_test.SecureIntraopTest", @@ -41,7 +42,6 @@ "unit._reconnect_test.ReconnectTest", "unit._resource_exhausted_test.ResourceExhaustedTest", "unit._rpc_test.RPCTest", - "unit._sanity._sanity_test.Sanity", "unit._thread_cleanup_test.CleanupThreadTest", "unit.beta._beta_features_test.BetaFeaturesTest", "unit.beta._beta_features_test.ContextManagementAndLifecycleTest", diff --git a/src/python/grpcio_tests/tests/unit/_sanity/__init__.py b/src/python/grpcio_tests/tests/unit/_sanity/__init__.py deleted file mode 100644 index 5772620b60..0000000000 --- a/src/python/grpcio_tests/tests/unit/_sanity/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright 2016 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/src/python/grpcio_tests/tests/unit/_sanity/_sanity_test.py b/src/python/grpcio_tests/tests/unit/_sanity/_sanity_test.py deleted file mode 100644 index 19bc8801eb..0000000000 --- a/src/python/grpcio_tests/tests/unit/_sanity/_sanity_test.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2016 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import json -import unittest - -import pkg_resources -import six - -import tests - - -class Sanity(unittest.TestCase): - - def testTestsJsonUpToDate(self): - """Autodiscovers all test suites and checks that tests.json is up to date""" - loader = tests.Loader() - loader.loadTestsFromNames(['tests']) - test_suite_names = [ - test_case_class.id().rsplit('.', 1)[0] - for test_case_class in tests._loader.iterate_suite_cases( - loader.suite) - ] - test_suite_names = sorted(set(test_suite_names)) - - tests_json_string = pkg_resources.resource_string('tests', 'tests.json') - if six.PY3: - tests_json_string = tests_json_string.decode() - tests_json = json.loads(tests_json_string) - self.assertListEqual(test_suite_names, tests_json) - - -if __name__ == '__main__': - unittest.main(verbosity=2) -- cgit v1.2.3