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
   "<expected>, <actual>" convention used in our assert*Equal calls
   elsewhere throughout the test corpus.

 - Internal implementation simplifications.
pull/12603/head
Nathaniel Manista 7 years ago
parent 8d3cc5ff0c
commit 44038eb9b6
  1. 0
      src/python/grpcio_tests/tests/_sanity/__init__.py
  2. 17
      src/python/grpcio_tests/tests/_sanity/_sanity_test.py
  3. 2
      src/python/grpcio_tests/tests/tests.json

@ -21,24 +21,25 @@ import six
import tests
class Sanity(unittest.TestCase):
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 = [
test_suite_names = sorted({
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)
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__':

@ -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",

Loading…
Cancel
Save