summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2011-05-30 18:19:44 +0200
committerSebastian Thiel <byronimo@gmail.com>2011-05-30 18:20:48 +0200
commitc192638aae09c1b5c087d67cc99dd4c7ec4ed916 (patch)
tree470ec82de0142c26ea333a11d954a04c6f631f9f
parent2bfc2e99111ef0e31f2bfda8a01c261a4f3f67cf (diff)
downloadgitpython-c192638aae09c1b5c087d67cc99dd4c7ec4ed916.tar.gz
Fixed all remaining python repository tests
-rw-r--r--git/test/db/lib.py42
-rw-r--r--git/test/db/py/test_git.py8
-rw-r--r--git/test/db/py/test_loose.py6
-rw-r--r--git/test/db/py/test_mem.py10
-rw-r--r--git/test/db/py/test_pack.py8
-rw-r--r--git/test/db/py/test_ref.py8
-rw-r--r--git/test/db/test_base.py4
-rw-r--r--git/test/lib/base.py11
-rw-r--r--git/test/lib/helper.py44
9 files changed, 77 insertions, 64 deletions
diff --git a/git/test/db/lib.py b/git/test/db/lib.py
index 5aebcd5c..499ca252 100644
--- a/git/test/db/lib.py
+++ b/git/test/db/lib.py
@@ -8,7 +8,8 @@ from git.test.lib import (
with_packs_rw,
ZippedStoreShaWriter,
fixture_path,
- TestBase
+ TestBase,
+ rorepo_dir,
)
from git.stream import Sha1Writer
@@ -29,12 +30,49 @@ from struct import pack
__all__ = ('TestDBBase', 'with_rw_directory', 'with_packs_rw', 'fixture_path')
class TestDBBase(TestBase):
- """Base class providing testing routines on databases"""
+ """Base Class providing default functionality to all tests such as:
+
+ - Utility functions provided by the TestCase base of the unittest method such as::
+ self.fail("todo")
+ self.failUnlessRaises(...)
+
+ - Class level repository which is considered read-only as it is shared among
+ all test cases in your type.
+ Access it using::
+ self.rorepo # 'ro' stands for read-only
+
+ The rorepo is in fact your current project's git repo. If you refer to specific
+ shas for your objects, be sure you choose some that are part of the immutable portion
+ of the project history ( to assure tests don't fail for others ).
+
+ Derived types can override the default repository type to create a different
+ read-only repo, allowing to test their specific type
+ """
# data
two_lines = "1234\nhello world"
all_data = (two_lines, )
+ #{ Configuration
+ # The repository type to instantiate. It takes at least a path to operate upon
+ # during instantiation.
+ RepoCls = None
+
+ # if True, a read-only repo will be provided and RepoCls must be set.
+ # Otherwise it may remain unset
+ needs_ro_repo = True
+ #} END configuration
+
+ @classmethod
+ def setUpAll(cls):
+ """
+ Dynamically add a read-only repository to our actual type. This way
+ each test type has its own repository
+ """
+ if cls.needs_ro_repo:
+ assert cls.RepoCls is not None, "RepoCls class member must be set"
+ cls.rorepo = cls.RepoCls(rorepo_dir())
+ #END handle rorepo
def _assert_object_writing_simple(self, db):
# write a bunch of objects and query their streams and info
diff --git a/git/test/db/py/test_git.py b/git/test/db/py/test_git.py
index 524d4080..ecaa5c8f 100644
--- a/git/test/db/py/test_git.py
+++ b/git/test/db/py/test_git.py
@@ -3,7 +3,7 @@
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
from git.test.lib import rorepo_dir
-from git.test.db.lib import *
+from git.test.db.lib import TestDBBase, with_rw_directory
from git.exc import BadObject
from git.db.py.complex import PureGitODB
from git.base import OStream, OInfo
@@ -12,10 +12,10 @@ from git.util import hex_to_bin, bin_to_hex
import os
class TestGitDB(TestDBBase):
- RepoCls = PureGitODB
+ needs_ro_repo = False
def test_reading(self):
- gdb = self.RepoCls(os.path.join(rorepo_dir(), 'objects'))
+ gdb = PureGitODB(os.path.join(rorepo_dir(), 'objects'))
# we have packs and loose objects, alternates doesn't necessarily exist
assert 1 < len(gdb.databases()) < 4
@@ -44,7 +44,7 @@ class TestGitDB(TestDBBase):
@with_rw_directory
def test_writing(self, path):
- gdb = self.RepoCls(path)
+ gdb = PureGitODB(path)
# its possible to write objects
self._assert_object_writing(gdb)
diff --git a/git/test/db/py/test_loose.py b/git/test/db/py/test_loose.py
index eb18c05d..0c9b4831 100644
--- a/git/test/db/py/test_loose.py
+++ b/git/test/db/py/test_loose.py
@@ -2,18 +2,18 @@
#
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
-from git.test.db.lib import *
+from git.test.db.lib import TestDBBase, with_rw_directory
from git.db.py.loose import PureLooseObjectODB
from git.exc import BadObject
from git.util import bin_to_hex
class TestLooseDB(TestDBBase):
- RepoCls = PureLooseObjectODB
+ needs_ro_repo = False
@with_rw_directory
def test_basics(self, path):
- ldb = self.RepoCls(path)
+ ldb = PureLooseObjectODB(path)
# write data
self._assert_object_writing(ldb)
diff --git a/git/test/db/py/test_mem.py b/git/test/db/py/test_mem.py
index ed14cc21..bc98dc56 100644
--- a/git/test/db/py/test_mem.py
+++ b/git/test/db/py/test_mem.py
@@ -2,14 +2,14 @@
#
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
-from lib import *
-from git.db.py import (
- PureMemoryDB,
- PureLooseObjectODB
- )
+from git.test.db.lib import TestDBBase, with_rw_directory
+from git.db.py.mem import PureMemoryDB
+from git.db.py.loose import PureLooseObjectODB
class TestPureMemoryDB(TestDBBase):
+ needs_ro_repo = False
+
@with_rw_directory
def test_writing(self, path):
mdb = PureMemoryDB()
diff --git a/git/test/db/py/test_pack.py b/git/test/db/py/test_pack.py
index 4854c4e7..5043f446 100644
--- a/git/test/db/py/test_pack.py
+++ b/git/test/db/py/test_pack.py
@@ -2,8 +2,9 @@
#
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
-from lib import *
-from git.db.py import PurePackedODB
+from git.test.db.lib import TestDBBase, with_packs_rw
+
+from git.db.py.pack import PurePackedODB
from git.test.lib import fixture_path
from git.exc import BadObject, AmbiguousObjectName
@@ -13,12 +14,15 @@ import random
class TestPackDB(TestDBBase):
+ needs_ro_repo = False
+
@with_packs_rw
def test_writing(self, path):
pdb = PurePackedODB(path)
# on demand, we init our pack cache
num_packs = len(pdb.entities())
+ assert num_packs
assert pdb._st_mtime != 0
# test pack directory changed:
diff --git a/git/test/db/py/test_ref.py b/git/test/db/py/test_ref.py
index 43fbb48f..c5374dc9 100644
--- a/git/test/db/py/test_ref.py
+++ b/git/test/db/py/test_ref.py
@@ -2,8 +2,8 @@
#
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
-from lib import *
-from git.db.py import PureReferenceDB
+from git.test.db.lib import *
+from git.db.py.ref import PureReferenceDB
from git.util import (
NULL_BIN_SHA,
@@ -14,6 +14,8 @@ import os
class TestPureReferenceDB(TestDBBase):
+ needs_ro_repo = False
+
def make_alt_file(self, alt_path, alt_list):
"""Create an alternates file which contains the given alternates.
The list can be empty"""
@@ -44,7 +46,7 @@ class TestPureReferenceDB(TestDBBase):
assert len(rdb.databases()) == 1
# we should now find a default revision of ours
- git_sha = hex_to_bin("5690fd0d3304f378754b23b098bd7cb5f4aa1976")
+ git_sha = hex_to_bin("5aebcd5cb3340fb31776941d7e4d518a712a8655")
assert rdb.has_object(git_sha)
# remove valid
diff --git a/git/test/db/test_base.py b/git/test/db/test_base.py
index 1dbf6fe7..2a882d0a 100644
--- a/git/test/db/test_base.py
+++ b/git/test/db/test_base.py
@@ -6,7 +6,9 @@ from lib import *
from git.db import RefSpec
class TestBase(TestDBBase):
-
+
+ needs_ro_repo = False
+
@with_rw_directory
def test_basics(self, path):
self.failUnlessRaises(ValueError, RefSpec, None, None)
diff --git a/git/test/lib/base.py b/git/test/lib/base.py
index 7bd9215e..bc160783 100644
--- a/git/test/lib/base.py
+++ b/git/test/lib/base.py
@@ -86,6 +86,7 @@ def with_packs_rw(func):
:note: needs with_rw_directory wrapped around it"""
def wrapper(self, path):
src_pack_glob = fixture_path('packs/*')
+ print src_pack_glob
copy_files_globbed(src_pack_glob, path, hard_link_ok=True)
return func(self, path)
# END wrapper
@@ -103,7 +104,6 @@ def rorepo_dir():
base = os.path.join(dirname(dirname(dirname(dirname(__file__)))), '.git')
assert os.path.isdir(base)
return base
-
def maketemp(*args, **kwargs):
"""Wrapper around default tempfile.mktemp to fix an osx issue"""
@@ -116,8 +116,15 @@ def fixture_path(relapath=''):
""":return: absolute path into the fixture directory
:param relapath: relative path into the fixtures directory, or ''
to obtain the fixture directory itself"""
- return os.path.join(dirname(__file__), 'fixtures', relapath)
+ test_dir = os.path.dirname(os.path.dirname(__file__))
+ return os.path.join(test_dir, "fixtures", relapath)
+def fixture(name):
+ return open(fixture_path(name), 'rb').read()
+
+def absolute_project_path():
+ return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
+
def copy_files_globbed(source_glob, target_dir, hard_link_ok=False):
"""Copy all files found according to the given source glob into the target directory
:param hard_link_ok: if True, hard links will be created if possible. Otherwise
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index 4fd82899..f365e5b4 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -19,24 +19,11 @@ from base import (
__all__ = (
- 'fixture_path', 'fixture', 'absolute_project_path', 'StringProcessAdapter',
+ 'StringProcessAdapter', 'GlobalsItemDeletorMetaCls',
'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase',
- 'GlobalsItemDeletorMetaCls'
- )
+ )
-#{ Routines
-def fixture_path(name):
- test_dir = os.path.dirname(os.path.dirname(__file__))
- return os.path.join(test_dir, "fixtures", name)
-
-def fixture(name):
- return open(fixture_path(name), 'rb').read()
-
-def absolute_project_path():
- return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
-
-#} END routines
#{ Adapters
@@ -227,37 +214,10 @@ class GlobalsItemDeletorMetaCls(type):
class TestBase(TestCase):
"""
Base Class providing default functionality to all tests such as:
-
- Utility functions provided by the TestCase base of the unittest method such as::
self.fail("todo")
self.failUnlessRaises(...)
-
- - Class level repository which is considered read-only as it is shared among
- all test cases in your type.
- Access it using::
- self.rorepo # 'ro' stands for read-only
-
- The rorepo is in fact your current project's git repo. If you refer to specific
- shas for your objects, be sure you choose some that are part of the immutable portion
- of the project history ( to assure tests don't fail for others ).
-
- Derived types can override the default repository type to create a differnt
- read-only repo, allowing to test their specific type
"""
- #{ Configuration
- # The repository type to instantiate. It takes at least a path to operate upon
- # during instantiation.
- RepoCls = None
- #} END configuration
-
- @classmethod
- def setUpAll(cls):
- """
- Dynamically add a read-only repository to our actual type. This way
- each test type has its own repository
- """
- assert cls.RepoCls is not None, "RepoCls class member must be set"
- cls.rorepo = cls.RepoCls(rorepo_dir())
def _make_file(self, rela_path, data, repo=None):
"""