2
0
Эх сурвалжийг харах

Add tests for stderr parsing.

Jelmer Vernooij 4 жил өмнө
parent
commit
4f5b6f5a3d

+ 0 - 1
dulwich/client.py

@@ -779,7 +779,6 @@ def _remote_error_from_stderr(stderr):
         if line.startswith(b'ERROR: '):
             raise GitProtocolError(
                 line[len(b'ERROR: '):].decode('utf-8', 'replace'))
-        raise GitProtocolError(line.decode('utf-8', 'replace'))
     raise HangupException(lines)
 
 

+ 28 - 0
dulwich/tests/test_client.py

@@ -54,6 +54,7 @@ from dulwich.client import (
     get_transport_and_path,
     get_transport_and_path_from_url,
     parse_rsync_url,
+    _remote_error_from_stderr,
     )
 from dulwich.config import (
     ConfigDict,
@@ -1357,3 +1358,30 @@ class GitCredentialStoreTests(TestCase):
             get_credentials_from_store(
                 b'https', b'example.org', b'otheruser', fnames=[self.fname]),
             None)
+
+
+class RemoteErrorFromStderrTests(TestCase):
+
+    def test_nothing(self):
+        self.assertIs(_remote_error_from_stderr(None), None)
+
+    def test_error_line(self):
+        b = BytesIO(b"""\
+This is some random output.
+ERROR: This is the actual error
+with a tail
+""")
+        self.assertEqual(
+            _remote_error_from_stderr(b),
+            "This is the actual error")
+
+    def test_no_error_line(self):
+        b = BytesIO(b"""\
+This is output without an error line.
+And this line is just random noise, too.
+""")
+        self.assertEqual(
+            _remote_error_from_stderr(b),
+            HangupException([
+                b"This is output without an error line.",
+                b"And this line is just random noise, too."]))