Quellcode durchsuchen

Always import TestCase from dulwich.tests so it can be extended or overridden.

Jelmer Vernooij vor 15 Jahren
Ursprung
Commit
17a735460f

+ 2 - 0
dulwich/tests/__init__.py

@@ -21,6 +21,8 @@
 
 import unittest
 
+from unittest import TestCase
+
 try:
     # If Python itself provides an exception, use that
     from unittest import SkipTest as TestSkipped

+ 0 - 1
dulwich/tests/compat/test_client.py

@@ -29,7 +29,6 @@ from dulwich import errors
 from dulwich import file
 from dulwich import index
 from dulwich import protocol
-from dulwich import object_store
 from dulwich import objects
 from dulwich import repo
 from dulwich.tests import (

+ 0 - 3
dulwich/tests/compat/test_server.py

@@ -30,9 +30,6 @@ from dulwich.server import (
     DictBackend,
     TCPGitServer,
     )
-from dulwich.tests import (
-    TestSkipped,
-    )
 from server_utils import (
     ServerTests,
     ShutdownServerMixIn,

+ 2 - 2
dulwich/tests/compat/utils.py

@@ -25,12 +25,12 @@ import socket
 import subprocess
 import tempfile
 import time
-import unittest
 
 from dulwich.repo import Repo
 from dulwich.protocol import TCP_GIT_PORT
 
 from dulwich.tests import (
+    TestCase,
     TestSkipped,
     )
 
@@ -171,7 +171,7 @@ def check_for_daemon(limit=10, delay=0.1, timeout=0.1, port=TCP_GIT_PORT):
     return False
 
 
-class CompatTestCase(unittest.TestCase):
+class CompatTestCase(TestCase):
     """Test case that requires git for compatibility checks.
 
     Subclasses can change the git version required by overriding

+ 3 - 1
dulwich/tests/test_client.py

@@ -17,11 +17,13 @@
 # MA  02110-1301, USA.
 
 from cStringIO import StringIO
-from unittest import TestCase
 
 from dulwich.client import (
     GitClient,
     )
+from dulwich.tests import (
+    TestCase,
+    )
 
 
 # TODO(durin42): add unit-level tests of GitClient

+ 3 - 1
dulwich/tests/test_fastexport.py

@@ -19,7 +19,6 @@
 
 from cStringIO import StringIO
 import stat
-from unittest import TestCase
 
 from dulwich.fastexport import (
     FastExporter,
@@ -32,6 +31,9 @@ from dulwich.objects import (
     Commit,
     Tree,
     )
+from dulwich.tests import (
+    TestCase,
+    )
 
 
 class FastExporterTests(TestCase):

+ 6 - 4
dulwich/tests/test_file.py

@@ -21,13 +21,15 @@ import os
 import shutil
 import sys
 import tempfile
-import unittest
 
 from dulwich.file import GitFile, fancy_rename
-from dulwich.tests import TestSkipped
+from dulwich.tests import (
+    TestCase,
+    TestSkipped,
+    )
 
 
-class FancyRenameTests(unittest.TestCase):
+class FancyRenameTests(TestCase):
 
     def setUp(self):
         self._tempdir = tempfile.mkdtemp()
@@ -82,7 +84,7 @@ class FancyRenameTests(unittest.TestCase):
         new_f.close()
 
 
-class GitFileTests(unittest.TestCase):
+class GitFileTests(TestCase):
 
     def setUp(self):
         self._tempdir = tempfile.mkdtemp()

+ 1 - 1
dulwich/tests/test_index.py

@@ -27,7 +27,6 @@ import shutil
 import stat
 import struct
 import tempfile
-from unittest import TestCase
 
 from dulwich.index import (
     Index,
@@ -43,6 +42,7 @@ from dulwich.object_store import (
 from dulwich.objects import (
     Blob,
     )
+from dulwich.tests import TestCase
 
 
 class IndexTestCase(TestCase):

+ 5 - 3
dulwich/tests/test_lru_cache.py

@@ -19,10 +19,12 @@
 from dulwich import (
     lru_cache,
     )
-import unittest
+from dulwich.tests import (
+    TestCase,
+    )
 
 
-class TestLRUCache(unittest.TestCase):
+class TestLRUCache(TestCase):
     """Test that LRU cache properly keeps track of entries."""
 
     def test_cache_size(self):
@@ -285,7 +287,7 @@ class TestLRUCache(unittest.TestCase):
         self.assertEqual([6, 7, 8, 9, 10, 11], sorted(cache.keys()))
 
 
-class TestLRUSizeCache(unittest.TestCase):
+class TestLRUSizeCache(TestCase):
 
     def test_basic_init(self):
         cache = lru_cache.LRUSizeCache()

+ 3 - 1
dulwich/tests/test_object_store.py

@@ -22,7 +22,6 @@
 import os
 import shutil
 import tempfile
-from unittest import TestCase
 
 from dulwich.objects import (
     Blob,
@@ -31,6 +30,9 @@ from dulwich.object_store import (
     DiskObjectStore,
     MemoryObjectStore,
     )
+from dulwich.tests import (
+    TestCase,
+    )
 from utils import (
     make_object,
     )

+ 8 - 9
dulwich/tests/test_objects.py

@@ -25,10 +25,8 @@
 import datetime
 import os
 import stat
-import unittest
 
 from dulwich.errors import (
-    ChecksumMismatch,
     ObjectFormatException,
     )
 from dulwich.objects import (
@@ -49,6 +47,7 @@ from dulwich.objects import (
     _sorted_tree_items_py,
     )
 from dulwich.tests import (
+    TestCase,
     TestSkipped,
     )
 from utils import (
@@ -97,7 +96,7 @@ except ImportError:
                 return
 
 
-class TestHexToSha(unittest.TestCase):
+class TestHexToSha(TestCase):
 
     def test_simple(self):
         self.assertEquals("\xab\xcd" * 10, hex_to_sha("abcd" * 10))
@@ -106,7 +105,7 @@ class TestHexToSha(unittest.TestCase):
         self.assertEquals("abcd" * 10, sha_to_hex("\xab\xcd" * 10))
 
 
-class BlobReadTests(unittest.TestCase):
+class BlobReadTests(TestCase):
     """Test decompression of blobs"""
 
     def get_sha_file(self, cls, base, sha):
@@ -229,7 +228,7 @@ class BlobReadTests(unittest.TestCase):
         self.assertEqual(c.message, 'Merge ../b\n')
 
 
-class ShaFileCheckTests(unittest.TestCase):
+class ShaFileCheckTests(TestCase):
 
     def assertCheckFails(self, cls, data):
         obj = cls()
@@ -244,7 +243,7 @@ class ShaFileCheckTests(unittest.TestCase):
         self.assertEqual(None, obj.check())
 
 
-class CommitSerializationTests(unittest.TestCase):
+class CommitSerializationTests(TestCase):
 
     def make_commit(self, **kwargs):
         attrs = {'tree': 'd80c186a03f423a81b39df39dc87fd269736ca86',
@@ -517,7 +516,7 @@ class TreeTests(ShaFileCheckTests):
         self.assertEquals(set(["foo"]), set(t))
 
 
-class TagSerializeTests(unittest.TestCase):
+class TagSerializeTests(TestCase):
 
     def test_serialize_simple(self):
         x = make_object(Tag,
@@ -629,7 +628,7 @@ class TagParseTests(ShaFileCheckTests):
                 self.assertCheckFails(Tag, text)
 
 
-class CheckTests(unittest.TestCase):
+class CheckTests(TestCase):
 
     def test_check_hexsha(self):
         check_hexsha(a_sha, "failed to check good sha")
@@ -660,7 +659,7 @@ class CheckTests(unittest.TestCase):
                           "trailing characters")
 
 
-class TimezoneTests(unittest.TestCase):
+class TimezoneTests(TestCase):
 
     def test_parse_timezone_utc(self):
         self.assertEquals((0, False), parse_timezone("+0000"))

+ 12 - 12
dulwich/tests/test_pack.py

@@ -24,7 +24,6 @@ from cStringIO import StringIO
 import os
 import shutil
 import tempfile
-import unittest
 import zlib
 
 from dulwich.errors import (
@@ -41,13 +40,14 @@ from dulwich.pack import (
     apply_delta,
     create_delta,
     load_pack_index,
-    hex_to_sha,
     read_zlib_chunks,
-    sha_to_hex,
     write_pack_index_v1,
     write_pack_index_v2,
     write_pack,
     )
+from dulwich.tests import (
+    TestCase,
+    )
 
 pack1_sha = 'bc63ddad95e7321ee734ea11a7a62d314e0d7481'
 
@@ -56,7 +56,7 @@ tree_sha = 'b2a2766a2879c209ab1176e7e778b81ae422eeaa'
 commit_sha = 'f18faa16531ac570a3fdc8c7ca16682548dafd12'
 
 
-class PackTests(unittest.TestCase):
+class PackTests(TestCase):
     """Base class for testing packs"""
 
     def setUp(self):
@@ -125,7 +125,7 @@ class PackIndexTests(PackTests):
         self.assertEquals(set([tree_sha, commit_sha, a_sha]), set(p))
 
 
-class TestPackDeltas(unittest.TestCase):
+class TestPackDeltas(TestCase):
 
     test_string1 = 'The answer was flailing in the wind'
     test_string2 = 'The answer was falling down the pipe'
@@ -320,35 +320,35 @@ class BaseTestPackIndexWriting(object):
                 self.assertTrue(actual_crc is None)
 
 
-class TestPackIndexWritingv1(unittest.TestCase, BaseTestPackIndexWriting):
+class TestPackIndexWritingv1(TestCase, BaseTestPackIndexWriting):
 
     def setUp(self):
-        unittest.TestCase.setUp(self)
+        TestCase.setUp(self)
         BaseTestPackIndexWriting.setUp(self)
         self._has_crc32_checksum = False
         self._expected_version = 1
         self._write_fn = write_pack_index_v1
 
     def tearDown(self):
-        unittest.TestCase.tearDown(self)
+        TestCase.tearDown(self)
         BaseTestPackIndexWriting.tearDown(self)
 
 
-class TestPackIndexWritingv2(unittest.TestCase, BaseTestPackIndexWriting):
+class TestPackIndexWritingv2(TestCase, BaseTestPackIndexWriting):
 
     def setUp(self):
-        unittest.TestCase.setUp(self)
+        TestCase.setUp(self)
         BaseTestPackIndexWriting.setUp(self)
         self._has_crc32_checksum = True
         self._expected_version = 2
         self._write_fn = write_pack_index_v2
 
     def tearDown(self):
-        unittest.TestCase.tearDown(self)
+        TestCase.tearDown(self)
         BaseTestPackIndexWriting.tearDown(self)
 
 
-class ReadZlibTests(unittest.TestCase):
+class ReadZlibTests(TestCase):
 
     decomp = (
       'tree 4ada885c9196b6b6fa08744b5862bf92896fc002\n'

+ 1 - 1
dulwich/tests/test_patch.py

@@ -19,7 +19,6 @@
 """Tests for patch.py."""
 
 from cStringIO import StringIO
-from unittest import TestCase
 
 from dulwich.objects import (
     Commit,
@@ -29,6 +28,7 @@ from dulwich.patch import (
     git_am_patch_split,
     write_commit_patch,
     )
+from dulwich.tests import TestCase
 
 
 class WriteCommitPatchTests(TestCase):

+ 2 - 1
dulwich/tests/test_protocol.py

@@ -20,7 +20,6 @@
 
 
 from StringIO import StringIO
-from unittest import TestCase
 
 from dulwich.protocol import (
     Protocol,
@@ -32,6 +31,8 @@ from dulwich.protocol import (
     MULTI_ACK,
     MULTI_ACK_DETAILED,
     )
+from dulwich.tests import TestCase
+
 
 class BaseProtocolTests(object):
 

+ 10 - 8
dulwich/tests/test_repository.py

@@ -23,7 +23,6 @@ from cStringIO import StringIO
 import os
 import shutil
 import tempfile
-import unittest
 import warnings
 
 from dulwich import errors
@@ -41,6 +40,9 @@ from dulwich.repo import (
     write_packed_refs,
     _split_ref_line,
     )
+from dulwich.tests import (
+    TestCase,
+    )
 from dulwich.tests.utils import (
     open_repo,
     tear_down_repo,
@@ -49,7 +51,7 @@ from dulwich.tests.utils import (
 missing_sha = 'b91fa4d900e17e99b433218e988c4eb4a3e9a097'
 
 
-class CreateRepositoryTests(unittest.TestCase):
+class CreateRepositoryTests(TestCase):
 
     def assertFileContentsEqual(self, expected, repo, path):
         f = repo.get_named_file(path)
@@ -81,7 +83,7 @@ class CreateRepositoryTests(unittest.TestCase):
         self._check_repo_contents(repo)
 
 
-class RepositoryTests(unittest.TestCase):
+class RepositoryTests(TestCase):
 
     def setUp(self):
         self._repo = None
@@ -328,7 +330,7 @@ class RepositoryTests(unittest.TestCase):
             shutil.rmtree(r2_dir)
 
 
-class BuildRepoTests(unittest.TestCase):
+class BuildRepoTests(TestCase):
     """Tests that build on-disk repos from scratch.
 
     Repos live in a temp dir and are torn down after each test. They start with
@@ -431,7 +433,7 @@ class BuildRepoTests(unittest.TestCase):
         r.stage(['a'])  # double-stage a deleted path
 
 
-class CheckRefFormatTests(unittest.TestCase):
+class CheckRefFormatTests(TestCase):
     """Tests for the check_ref_format function.
 
     These are the same tests as in the git test suite.
@@ -462,7 +464,7 @@ TWOS = "2" * 40
 THREES = "3" * 40
 FOURS = "4" * 40
 
-class PackedRefsFileTests(unittest.TestCase):
+class PackedRefsFileTests(TestCase):
 
     def test_split_ref_line_errors(self):
         self.assertRaises(errors.PackedRefsException, _split_ref_line,
@@ -619,13 +621,13 @@ class RefsContainerTests(object):
         self.assertFalse('refs/tags/refs-0.2' in self._refs)
 
 
-class DictRefsContainerTests(RefsContainerTests, unittest.TestCase):
+class DictRefsContainerTests(RefsContainerTests, TestCase):
 
     def setUp(self):
         self._refs = DictRefsContainer(dict(_TEST_REFS))
 
 
-class DiskRefsContainerTests(RefsContainerTests, unittest.TestCase):
+class DiskRefsContainerTests(RefsContainerTests, TestCase):
 
     def setUp(self):
         self._repo = open_repo('refs.git')

+ 2 - 2
dulwich/tests/test_server.py

@@ -19,8 +19,6 @@
 """Tests for the smart protocol server."""
 
 
-from unittest import TestCase
-
 from dulwich.errors import (
     GitProtocolError,
     )
@@ -35,6 +33,8 @@ from dulwich.server import (
     SingleAckGraphWalkerImpl,
     UploadPackHandler,
     )
+from dulwich.tests import TestCase
+
 
 
 ONE = '1' * 40

+ 3 - 1
dulwich/tests/test_web.py

@@ -20,11 +20,13 @@
 
 from cStringIO import StringIO
 import re
-from unittest import TestCase
 
 from dulwich.objects import (
     Blob,
     )
+from dulwich.tests import (
+    TestCase,
+    )
 from dulwich.web import (
     HTTP_OK,
     HTTP_NOT_FOUND,