Skip to content
This repository was archived by the owner on Apr 14, 2024. It is now read-only.

Commit 7bde7b0

Browse files
committed
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
1 parent be29427 commit 7bde7b0

File tree

6 files changed

+43
-41
lines changed

6 files changed

+43
-41
lines changed

‎gitdb/exc.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,34 @@ class ODBError(Exception):
1212

1313

1414
class InvalidDBRoot(ODBError):
15-
1615
"""Thrown if an object database cannot be initialized at the given path"""
1716

1817

1918
class BadObject(ODBError):
20-
2119
"""The object with the given SHA does not exist. Instantiate with the
2220
failed sha"""
2321

2422
def __str__(self):
2523
return "BadObject: %s" % to_hex_sha(self.args[0])
2624

2725

28-
class ParseError(ODBError):
26+
class BadName(ODBError):
27+
"""A name provided to rev_parse wasn't understood"""
28+
29+
def __str__(self):
30+
return "Ref '%s' did not resolve to an object" % self.args[0]
2931

32+
33+
class ParseError(ODBError):
3034
"""Thrown if the parsing of a file failed due to an invalid format"""
3135

3236

3337
class AmbiguousObjectName(ODBError):
34-
3538
"""Thrown if a possibly shortened name does not uniquely represent a single object
3639
in the database"""
3740

3841

3942
class BadObjectType(ODBError):
40-
4143
"""The object had an unsupported type"""
4244

4345

‎gitdb/test/db/test_git.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
5+
import os
56
from gitdb.test.db.lib import (
67
TestDBBase,
78
fixture_path,
@@ -16,7 +17,7 @@
1617
class TestGitDB(TestDBBase):
1718

1819
def test_reading(self):
19-
gdb = GitDB(fixture_path('../../../.git/objects'))
20+
gdb = GitDB(os.path.join(self.gitrepopath, 'objects'))
2021

2122
# we have packs and loose objects, alternates doesn't necessarily exist
2223
assert 1 < len(gdb.databases()) < 4

‎gitdb/test/db/test_ref.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_writing(self, path):
4040

4141
# setup alternate file
4242
# add two, one is invalid
43-
own_repo_path = fixture_path('../../../.git/objects') # use own repo
43+
own_repo_path = os.path.join(self.gitrepopath, 'objects') # use own repo
4444
self.make_alt_file(alt_path, [own_repo_path, "invalid/path"])
4545
rdb.update_cache()
4646
assert len(rdb.databases()) == 1

‎gitdb/test/lib.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,41 @@
1818
import shutil
1919
import os
2020
import gc
21+
import logging
2122
from functools import wraps
2223

2324

2425
#{ Bases
2526

2627
class TestBase(unittest.TestCase):
28+
"""Base class for all tests
2729
28-
"""Base class for all tests"""
30+
TestCase providing access to readonly repositories using the following member variables.
31+
32+
* gitrepopath
33+
34+
* read-only base path of the git source repository, i.e. .../git/.git
35+
"""
36+
37+
#{ Invvariants
38+
k_env_git_repo = "GITDB_TEST_GIT_REPO_BASE"
39+
#} END invariants
40+
41+
@classmethod
42+
def setUpClass(cls):
43+
try:
44+
super(TestBase, cls).setUpClass()
45+
except AttributeError:
46+
pass
47+
48+
cls.gitrepopath = os.environ.get(cls.k_env_git_repo)
49+
if not cls.gitrepopath:
50+
logging.info(
51+
"You can set the %s environment variable to a .git repository of your choice - defaulting to the gitdb repository", cls.k_env_git_repo)
52+
ospd = os.path.dirname
53+
cls.gitrepopath = os.path.join(ospd(ospd(ospd(__file__))), '.git')
54+
# end assure gitrepo is set
55+
assert cls.gitrepopath.endswith('.git')
2956

3057

3158
#} END bases

‎gitdb/test/performance/lib.py

+2-28
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,15 @@
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
"""Contains library functions"""
6-
import os
7-
import logging
86
from gitdb.test.lib import TestBase
97

108

11-
#{ Invvariants
12-
k_env_git_repo = "GITDB_TEST_GIT_REPO_BASE"
13-
#} END invariants
14-
159

1610
#{ Base Classes
1711

1812
class TestBigRepoR(TestBase):
19-
20-
"""TestCase providing access to readonly 'big' repositories using the following
21-
member variables:
22-
23-
* gitrepopath
24-
25-
* read-only base path of the git source repository, i.e. .../git/.git"""
26-
27-
def setUp(self):
28-
try:
29-
super(TestBigRepoR, self).setUp()
30-
except AttributeError:
31-
pass
32-
33-
self.gitrepopath = os.environ.get(k_env_git_repo)
34-
if not self.gitrepopath:
35-
logging.info(
36-
"You can set the %s environment variable to a .git repository of your choice - defaulting to the gitdb repository", k_env_git_repo)
37-
ospd = os.path.dirname
38-
self.gitrepopath = os.path.join(ospd(ospd(ospd(ospd(__file__)))), '.git')
39-
# end assure gitrepo is set
40-
assert self.gitrepopath.endswith('.git')
13+
"""A placeholder in case we want to add additional functionality to all performance test-cases
14+
"""
4115

4216

4317
#} END base classes

‎gitdb/test/test_example.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
"""Module with examples from the tutorial section of the docs"""
6-
from gitdb.test.lib import (
7-
TestBase,
8-
fixture_path
9-
)
6+
import os
7+
from gitdb.test.lib import TestBase
108
from gitdb import IStream
119
from gitdb.db import LooseObjectDB
1210

@@ -16,7 +14,7 @@
1614
class TestExamples(TestBase):
1715

1816
def test_base(self):
19-
ldb = LooseObjectDB(fixture_path("../../../.git/objects"))
17+
ldb = LooseObjectDB(os.path.join(self.gitrepopath, 'objects'))
2018

2119
for sha1 in ldb.sha_iter():
2220
oinfo = ldb.info(sha1)

0 commit comments

Comments
 (0)