summaryrefslogtreecommitdiffstats
path: root/tests/test_error.py
diff options
context:
space:
mode:
authorGavin Mak <gavinmak@google.com>2023-03-11 06:46:20 +0000
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-22 17:46:28 +0000
commitea2e330e43c182dc16b0111ebc69ee5a71ee4ce1 (patch)
treedc33ba0e56825b3e007d0589891756724725a465 /tests/test_error.py
parent1604cf255f8c1786a23388db6d5277ac7949a24a (diff)
downloadgit-repo-ea2e330e43c182dc16b0111ebc69ee5a71ee4ce1.tar.gz
Format codebase with black and check formatting in CQ
Apply rules set by https://gerrit-review.googlesource.com/c/git-repo/+/362954/ across the codebase and fix any lingering errors caught by flake8. Also check black formatting in run_tests (and CQ). Bug: b/267675342 Change-Id: I972d77649dac351150dcfeb1cd1ad0ea2efc1956 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/363474 Reviewed-by: Mike Frysinger <vapier@google.com> Tested-by: Gavin Mak <gavinmak@google.com> Commit-Queue: Gavin Mak <gavinmak@google.com>
Diffstat (limited to 'tests/test_error.py')
-rw-r--r--tests/test_error.py60
1 files changed, 31 insertions, 29 deletions
diff --git a/tests/test_error.py b/tests/test_error.py
index 82b00c24..784e2d57 100644
--- a/tests/test_error.py
+++ b/tests/test_error.py
@@ -22,32 +22,34 @@ import error
22 22
23 23
24class PickleTests(unittest.TestCase): 24class PickleTests(unittest.TestCase):
25 """Make sure all our custom exceptions can be pickled.""" 25 """Make sure all our custom exceptions can be pickled."""
26 26
27 def getExceptions(self): 27 def getExceptions(self):
28 """Return all our custom exceptions.""" 28 """Return all our custom exceptions."""
29 for name in dir(error): 29 for name in dir(error):
30 cls = getattr(error, name) 30 cls = getattr(error, name)
31 if isinstance(cls, type) and issubclass(cls, Exception): 31 if isinstance(cls, type) and issubclass(cls, Exception):
32 yield cls 32 yield cls
33 33
34 def testExceptionLookup(self): 34 def testExceptionLookup(self):
35 """Make sure our introspection logic works.""" 35 """Make sure our introspection logic works."""
36 classes = list(self.getExceptions()) 36 classes = list(self.getExceptions())
37 self.assertIn(error.HookError, classes) 37 self.assertIn(error.HookError, classes)
38 # Don't assert the exact number to avoid being a change-detector test. 38 # Don't assert the exact number to avoid being a change-detector test.
39 self.assertGreater(len(classes), 10) 39 self.assertGreater(len(classes), 10)
40 40
41 def testPickle(self): 41 def testPickle(self):
42 """Try to pickle all the exceptions.""" 42 """Try to pickle all the exceptions."""
43 for cls in self.getExceptions(): 43 for cls in self.getExceptions():
44 args = inspect.getfullargspec(cls.__init__).args[1:] 44 args = inspect.getfullargspec(cls.__init__).args[1:]
45 obj = cls(*args) 45 obj = cls(*args)
46 p = pickle.dumps(obj) 46 p = pickle.dumps(obj)
47 try: 47 try:
48 newobj = pickle.loads(p) 48 newobj = pickle.loads(p)
49 except Exception as e: # pylint: disable=broad-except 49 except Exception as e: # pylint: disable=broad-except
50 self.fail('Class %s is unable to be pickled: %s\n' 50 self.fail(
51 'Incomplete super().__init__(...) call?' % (cls, e)) 51 "Class %s is unable to be pickled: %s\n"
52 self.assertIsInstance(newobj, cls) 52 "Incomplete super().__init__(...) call?" % (cls, e)
53 self.assertEqual(str(obj), str(newobj)) 53 )
54 self.assertIsInstance(newobj, cls)
55 self.assertEqual(str(obj), str(newobj))