summaryrefslogtreecommitdiff
path: root/gitdb
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-01-08 17:34:53 +0100
committerSebastian Thiel <byronimo@gmail.com>2015-01-08 17:34:53 +0100
commit7bde7b098b07291227fcbc4eb900ebf13c9191a2 (patch)
treea368f0bc387f8ed7c987c7efd8e77094846e17f8 /gitdb
parentbe294278a0087f21d565a1084fb220ff936ae0bd (diff)
downloadgitdb-7bde7b098b07291227fcbc4eb900ebf13c9191a2.tar.gz
Fixed up tests to use the GITDB_TEST_GIT_REPO_BASE at all times
I have verified that all tests are working, even without a parent git repository, as long as the said environment variable is set. Fixes #16
Diffstat (limited to 'gitdb')
-rw-r--r--gitdb/exc.py12
-rw-r--r--gitdb/test/db/test_git.py3
-rw-r--r--gitdb/test/db/test_ref.py2
-rw-r--r--gitdb/test/lib.py29
-rw-r--r--gitdb/test/performance/lib.py30
-rw-r--r--gitdb/test/test_example.py8
6 files changed, 43 insertions, 41 deletions
diff --git a/gitdb/exc.py b/gitdb/exc.py
index d58442f..817ac7b 100644
--- a/gitdb/exc.py
+++ b/gitdb/exc.py
@@ -12,12 +12,10 @@ class ODBError(Exception):
class InvalidDBRoot(ODBError):
-
"""Thrown if an object database cannot be initialized at the given path"""
class BadObject(ODBError):
-
"""The object with the given SHA does not exist. Instantiate with the
failed sha"""
@@ -25,19 +23,23 @@ class BadObject(ODBError):
return "BadObject: %s" % to_hex_sha(self.args[0])
-class ParseError(ODBError):
+class BadName(ODBError):
+ """A name provided to rev_parse wasn't understood"""
+
+ def __str__(self):
+ return "Ref '%s' did not resolve to an object" % self.args[0]
+
+class ParseError(ODBError):
"""Thrown if the parsing of a file failed due to an invalid format"""
class AmbiguousObjectName(ODBError):
-
"""Thrown if a possibly shortened name does not uniquely represent a single object
in the database"""
class BadObjectType(ODBError):
-
"""The object had an unsupported type"""
diff --git a/gitdb/test/db/test_git.py b/gitdb/test/db/test_git.py
index f962067..f28ffb7 100644
--- a/gitdb/test/db/test_git.py
+++ b/gitdb/test/db/test_git.py
@@ -2,6 +2,7 @@
#
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
+import os
from gitdb.test.db.lib import (
TestDBBase,
fixture_path,
@@ -16,7 +17,7 @@ from gitdb.util import hex_to_bin, bin_to_hex
class TestGitDB(TestDBBase):
def test_reading(self):
- gdb = GitDB(fixture_path('../../../.git/objects'))
+ gdb = GitDB(os.path.join(self.gitrepopath, 'objects'))
# we have packs and loose objects, alternates doesn't necessarily exist
assert 1 < len(gdb.databases()) < 4
diff --git a/gitdb/test/db/test_ref.py b/gitdb/test/db/test_ref.py
index b774baf..25cf37d 100644
--- a/gitdb/test/db/test_ref.py
+++ b/gitdb/test/db/test_ref.py
@@ -40,7 +40,7 @@ class TestReferenceDB(TestDBBase):
# setup alternate file
# add two, one is invalid
- own_repo_path = fixture_path('../../../.git/objects') # use own repo
+ own_repo_path = os.path.join(self.gitrepopath, 'objects') # use own repo
self.make_alt_file(alt_path, [own_repo_path, "invalid/path"])
rdb.update_cache()
assert len(rdb.databases()) == 1
diff --git a/gitdb/test/lib.py b/gitdb/test/lib.py
index c4acd92..a089eac 100644
--- a/gitdb/test/lib.py
+++ b/gitdb/test/lib.py
@@ -18,14 +18,41 @@ import tempfile
import shutil
import os
import gc
+import logging
from functools import wraps
#{ Bases
class TestBase(unittest.TestCase):
+ """Base class for all tests
- """Base class for all tests"""
+ TestCase providing access to readonly repositories using the following member variables.
+
+ * gitrepopath
+
+ * read-only base path of the git source repository, i.e. .../git/.git
+ """
+
+ #{ Invvariants
+ k_env_git_repo = "GITDB_TEST_GIT_REPO_BASE"
+ #} END invariants
+
+ @classmethod
+ def setUpClass(cls):
+ try:
+ super(TestBase, cls).setUpClass()
+ except AttributeError:
+ pass
+
+ cls.gitrepopath = os.environ.get(cls.k_env_git_repo)
+ if not cls.gitrepopath:
+ logging.info(
+ "You can set the %s environment variable to a .git repository of your choice - defaulting to the gitdb repository", cls.k_env_git_repo)
+ ospd = os.path.dirname
+ cls.gitrepopath = os.path.join(ospd(ospd(ospd(__file__))), '.git')
+ # end assure gitrepo is set
+ assert cls.gitrepopath.endswith('.git')
#} END bases
diff --git a/gitdb/test/performance/lib.py b/gitdb/test/performance/lib.py
index cbc52bc..fa4dd20 100644
--- a/gitdb/test/performance/lib.py
+++ b/gitdb/test/performance/lib.py
@@ -3,41 +3,15 @@
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
"""Contains library functions"""
-import os
-import logging
from gitdb.test.lib import TestBase
-#{ Invvariants
-k_env_git_repo = "GITDB_TEST_GIT_REPO_BASE"
-#} END invariants
-
#{ Base Classes
class TestBigRepoR(TestBase):
-
- """TestCase providing access to readonly 'big' repositories using the following
- member variables:
-
- * gitrepopath
-
- * read-only base path of the git source repository, i.e. .../git/.git"""
-
- def setUp(self):
- try:
- super(TestBigRepoR, self).setUp()
- except AttributeError:
- pass
-
- self.gitrepopath = os.environ.get(k_env_git_repo)
- if not self.gitrepopath:
- logging.info(
- "You can set the %s environment variable to a .git repository of your choice - defaulting to the gitdb repository", k_env_git_repo)
- ospd = os.path.dirname
- self.gitrepopath = os.path.join(ospd(ospd(ospd(ospd(__file__)))), '.git')
- # end assure gitrepo is set
- assert self.gitrepopath.endswith('.git')
+ """A placeholder in case we want to add additional functionality to all performance test-cases
+ """
#} END base classes
diff --git a/gitdb/test/test_example.py b/gitdb/test/test_example.py
index ed0a885..6e80bf5 100644
--- a/gitdb/test/test_example.py
+++ b/gitdb/test/test_example.py
@@ -3,10 +3,8 @@
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
"""Module with examples from the tutorial section of the docs"""
-from gitdb.test.lib import (
- TestBase,
- fixture_path
-)
+import os
+from gitdb.test.lib import TestBase
from gitdb import IStream
from gitdb.db import LooseObjectDB
@@ -16,7 +14,7 @@ from io import BytesIO
class TestExamples(TestBase):
def test_base(self):
- ldb = LooseObjectDB(fixture_path("../../../.git/objects"))
+ ldb = LooseObjectDB(os.path.join(self.gitrepopath, 'objects'))
for sha1 in ldb.sha_iter():
oinfo = ldb.info(sha1)