diff options
Diffstat (limited to 'test/test_exc.py')
-rw-r--r-- | test/test_exc.py | 83 |
1 files changed, 47 insertions, 36 deletions
diff --git a/test/test_exc.py b/test/test_exc.py index c77be782..6c3353fc 100644 --- a/test/test_exc.py +++ b/test/test_exc.py @@ -29,34 +29,43 @@ import itertools as itt _cmd_argvs = ( - ('cmd', ), - ('θνιψοδε', ), - ('θνιψοδε', 'normal', 'argvs'), - ('cmd', 'ελληνικα', 'args'), - ('θνιψοδε', 'κι', 'αλλα', 'strange', 'args'), - ('θνιψοδε', 'κι', 'αλλα', 'non-unicode', 'args'), - ('git', 'clone', '-v', 'https://fakeuser:fakepassword1234@fakerepo.example.com/testrepo'), + ("cmd",), + ("θνιψοδε",), + ("θνιψοδε", "normal", "argvs"), + ("cmd", "ελληνικα", "args"), + ("θνιψοδε", "κι", "αλλα", "strange", "args"), + ("θνιψοδε", "κι", "αλλα", "non-unicode", "args"), + ( + "git", + "clone", + "-v", + "https://fakeuser:fakepassword1234@fakerepo.example.com/testrepo", + ), ) _causes_n_substrings = ( - (None, None), # noqa: E241 @IgnorePep8 - (7, "exit code(7)"), # noqa: E241 @IgnorePep8 - ('Some string', "'Some string'"), # noqa: E241 @IgnorePep8 - ('παλιο string', "'παλιο string'"), # noqa: E241 @IgnorePep8 - (Exception("An exc."), "Exception('An exc.')"), # noqa: E241 @IgnorePep8 - (Exception("Κακια exc."), "Exception('Κακια exc.')"), # noqa: E241 @IgnorePep8 - (object(), "<object object at "), # noqa: E241 @IgnorePep8 + (None, None), # noqa: E241 @IgnorePep8 + (7, "exit code(7)"), # noqa: E241 @IgnorePep8 + ("Some string", "'Some string'"), # noqa: E241 @IgnorePep8 + ("παλιο string", "'παλιο string'"), # noqa: E241 @IgnorePep8 + (Exception("An exc."), "Exception('An exc.')"), # noqa: E241 @IgnorePep8 + (Exception("Κακια exc."), "Exception('Κακια exc.')"), # noqa: E241 @IgnorePep8 + (object(), "<object object at "), # noqa: E241 @IgnorePep8 ) -_streams_n_substrings = (None, 'steram', 'ομορφο stream', ) +_streams_n_substrings = ( + None, + "steram", + "ομορφο stream", +) @ddt.ddt class TExc(TestBase): - def test_ExceptionsHaveBaseClass(self): from git.exc import GitError + self.assertIsInstance(GitError(), Exception) - + exception_classes = [ InvalidGitRepositoryError, WorkTreeRepositoryUnsupported, @@ -73,7 +82,9 @@ class TExc(TestBase): for ex_class in exception_classes: self.assertTrue(issubclass(ex_class, GitError)) - @ddt.data(*list(itt.product(_cmd_argvs, _causes_n_substrings, _streams_n_substrings))) + @ddt.data( + *list(itt.product(_cmd_argvs, _causes_n_substrings, _streams_n_substrings)) + ) def test_CommandError_unicode(self, case): argv, (cause, subs), stream = case cls = CommandError @@ -81,7 +92,7 @@ class TExc(TestBase): s = str(c) self.assertIsNotNone(c._msg) - self.assertIn(' cmdline: ', s) + self.assertIn(" cmdline: ", s) for a in remove_password_if_present(argv): self.assertIn(a, s) @@ -112,17 +123,17 @@ class TExc(TestBase): self.assertIn(" stdout:", s) self.assertIn(stream, s) - c = cls(argv, cause, stream, stream + 'no2') + c = cls(argv, cause, stream, stream + "no2") s = str(c) self.assertIn(" stderr:", s) self.assertIn(stream, s) self.assertIn(" stdout:", s) - self.assertIn(stream + 'no2', s) + self.assertIn(stream + "no2", s) @ddt.data( - (['cmd1'], None), - (['cmd1'], "some cause"), - (['cmd1'], Exception()), + (["cmd1"], None), + (["cmd1"], "some cause"), + (["cmd1"], Exception()), ) def test_GitCommandNotFound(self, init_args): argv, cause = init_args @@ -131,15 +142,15 @@ class TExc(TestBase): self.assertIn(argv[0], s) if cause: - self.assertIn(' not found due to: ', s) + self.assertIn(" not found due to: ", s) self.assertIn(str(cause), s) else: - self.assertIn(' not found!', s) + self.assertIn(" not found!", s) @ddt.data( - (['cmd1'], None), - (['cmd1'], "some cause"), - (['cmd1', 'https://fakeuser@fakerepo.example.com/testrepo'], Exception()), + (["cmd1"], None), + (["cmd1"], "some cause"), + (["cmd1", "https://fakeuser@fakerepo.example.com/testrepo"], Exception()), ) def test_GitCommandError(self, init_args): argv, cause = init_args @@ -149,15 +160,15 @@ class TExc(TestBase): for arg in remove_password_if_present(argv): self.assertIn(arg, s) if cause: - self.assertIn(' failed due to: ', s) + self.assertIn(" failed due to: ", s) self.assertIn(str(cause), s) else: - self.assertIn(' failed!', s) + self.assertIn(" failed!", s) @ddt.data( - (['cmd1'], None), - (['cmd1'], "some cause"), - (['cmd1'], Exception()), + (["cmd1"], None), + (["cmd1"], "some cause"), + (["cmd1"], Exception()), ) def test_HookExecutionError(self, init_args): argv, cause = init_args @@ -166,7 +177,7 @@ class TExc(TestBase): self.assertIn(argv[0], s) if cause: - self.assertTrue(s.startswith('Hook('), s) + self.assertTrue(s.startswith("Hook("), s) self.assertIn(str(cause), s) else: - self.assertIn(' failed!', s) + self.assertIn(" failed!", s) |