diff --git a/test/data/testrepo.zip b/test/data/testrepo.zip new file mode 100644 index 0000000..aac9a62 Binary files /dev/null and b/test/data/testrepo.zip differ diff --git a/test/test_blob.py b/test/test_blob.py index 2f66609..65082af 100644 --- a/test/test_blob.py +++ b/test/test_blob.py @@ -37,7 +37,7 @@ import utils BLOB_SHA = 'af431f20fc541ed6d5afede3e2dc7160f6f01f16' -class BlobTest(utils.TestRepoTestCase): +class BlobTest(utils.BareRepoTestCase): def test_read_blob(self): blob = self.repo[BLOB_SHA] diff --git a/test/test_commit.py b/test/test_commit.py index 4160f92..245490e 100644 --- a/test/test_commit.py +++ b/test/test_commit.py @@ -37,7 +37,7 @@ import utils COMMIT_SHA = '5fe808e8953c12735680c257f56600cb0de44b10' -class CommitTest(utils.TestRepoTestCase): +class CommitTest(utils.BareRepoTestCase): def test_read_commit(self): commit = self.repo[COMMIT_SHA] diff --git a/test/test_index.py b/test/test_index.py index a4a05c1..9040f41 100644 --- a/test/test_index.py +++ b/test/test_index.py @@ -36,11 +36,17 @@ import pygit2 import utils -class IndexTest(utils.TestRepoTestCase): +class IndexBareTest(utils.BareRepoTestCase): def test_bare(self): self.assertEqual(None, self.repo.index) +class IndexTest(utils.RepoTestCase): + + def test_index(self): + self.assertNotEqual(None, self.repo.index) + + if __name__ == '__main__': unittest.main() diff --git a/test/test_repository.py b/test/test_repository.py index 1df813e..58030ce 100644 --- a/test/test_repository.py +++ b/test/test_repository.py @@ -39,7 +39,7 @@ A_HEX_SHA = 'af431f20fc541ed6d5afede3e2dc7160f6f01f16' A_BIN_SHA = binascii.unhexlify(A_HEX_SHA) -class RepositoryTest(utils.TestRepoTestCase): +class RepositoryTest(utils.BareRepoTestCase): def test_read(self): self.assertRaises(TypeError, self.repo.read, 123) diff --git a/test/test_tag.py b/test/test_tag.py index fc4cbc7..d98037d 100644 --- a/test/test_tag.py +++ b/test/test_tag.py @@ -37,7 +37,7 @@ import utils TAG_SHA = '3d2962987c695a29f1f80b6c3aa4ec046ef44369' -class TagTest(utils.TestRepoTestCase): +class TagTest(utils.BareRepoTestCase): def test_read_tag(self): tag = self.repo[TAG_SHA] diff --git a/test/test_tree.py b/test/test_tree.py index 2fde234..7f3d8b8 100644 --- a/test/test_tree.py +++ b/test/test_tree.py @@ -38,7 +38,7 @@ TREE_SHA = '967fce8df97cc71722d3c2a5930ef3e6f1d27b12' SUBTREE_SHA = '614fd9a3094bf618ea938fffc00e7d1a54f89ad0' -class TreeTest(utils.TestRepoTestCase): +class TreeTest(utils.BareRepoTestCase): def assertTreeEntryEqual(self, entry, sha, name, attributes): self.assertEqual(entry.sha, sha) diff --git a/test/utils.py b/test/utils.py index 8cdc9f9..bf18579 100644 --- a/test/utils.py +++ b/test/utils.py @@ -31,6 +31,7 @@ import os import shutil import tempfile import unittest +import zipfile import pygit2 @@ -43,7 +44,7 @@ def open_repo(repo_dir): return temp_dir, pygit2.Repository(temp_repo_path) -class TestRepoTestCase(unittest.TestCase): +class BareRepoTestCase(unittest.TestCase): def setUp(self): self._temp_dir, self.repo = open_repo('testrepo.git') @@ -58,3 +59,20 @@ class TestRepoTestCase(unittest.TestCase): self.assertEqual((arg,), e.args) else: self.fail('%s(%r) not raised' % (exc_class.__name__, arg)) + + +class RepoTestCase(unittest.TestCase): + + def setUp(self): + repo_dir = 'testrepo' + repo_path = os.path.join(os.path.dirname(__file__), 'data', repo_dir) + temp_dir = tempfile.mkdtemp() + z = zipfile.ZipFile(repo_path + '.zip') + z.extractall(temp_dir) + z.close() + self._temp_dir = temp_dir + temp_repo_path = os.path.join(temp_dir, repo_dir, '.git') + self.repo = pygit2.Repository(temp_repo_path) + + def tearDown(self): + shutil.rmtree(self._temp_dir)