Skip to content

make gitdb tests not require being ran from within gitdb git repository #16

@yarikoptic

Description

@yarikoptic

Although I also got confused with #7 suggesting that gitdb is "dead" and absorbed into GitPython but it seems to be live and kicking out new releases ;) So I will assume that.

It would be nice if gitdb tests could be ran on a source distribution of gitdb, i.e. without relying on having .git. Now even if I initialize some dummy repository

mkdir TESTGITDB
cd TESTGITDB
git init; for c in 1 2 3; do echo $c >| 1; git add 1; git commit -m "commit $c"; done

manually and point to it as directed by messages I get:

> GITDB_TEST_GIT_REPO_BASE=$PWD/TESTGITDB/.git nosetests -s -v gitdb/test
...
======================================================================
ERROR: test_reading (gitdb.test.db.test_git.TestGitDB)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yoh/deb/gits/python-gitdb/gitdb/test/db/test_git.py", line 22, in test_reading
    assert 1 < len(gdb.databases()) < 4
  File "/home/yoh/deb/gits/python-gitdb/gitdb/db/base.py", line 223, in databases
    return tuple(self._dbs)
  File "/home/yoh/deb/gits/python-gitdb/gitdb/util.py", line 237, in __getattr__
    self._set_cache_(attr)
  File "/home/yoh/deb/gits/python-gitdb/gitdb/db/git.py", line 58, in _set_cache_
    raise InvalidDBRoot(self.root_path())
InvalidDBRoot: /home/yoh/deb/gits/python-gitdb/gitdb/test/fixtures/../../../.git/objects

======================================================================
ERROR: test_pack_random_access (gitdb.test.performance.test_pack.TestPackedDBPerformance)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yoh/deb/gits/python-gitdb/gitdb/test/lib.py", line 45, in wrapper
    return func(self, *args, **kwargs)
  File "/home/yoh/deb/gits/python-gitdb/gitdb/test/performance/test_pack.py", line 54, in test_pack_random_access
    (ns, len(pdb.entities()), elapsed, ns / elapsed), file=sys.stderr)
ZeroDivisionError: float division by zero

======================================================================
ERROR: test_pack_writing (gitdb.test.performance.test_pack_streaming.TestPackStreamingPerformance)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yoh/deb/gits/python-gitdb/gitdb/test/lib.py", line 45, in wrapper
    return func(self, *args, **kwargs)
  File "/home/yoh/deb/gits/python-gitdb/gitdb/test/performance/test_pack_streaming.py", line 58, in test_pack_writing
    PackEntity.write_pack((pdb.stream(sha) for sha in pdb.sha_iter()), ostream.write, object_count=ni)
  File "/home/yoh/deb/gits/python-gitdb/gitdb/pack.py", line 979, in write_pack
    "Expected to write %i objects into pack, but received only %i from iterators" % (object_count, actual_count))
ValueError: Expected to write 1000 objects into pack, but received only 0 from iterators

======================================================================
ERROR: test_base (gitdb.test.test_example.TestExamples)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yoh/deb/gits/python-gitdb/gitdb/test/test_example.py", line 42, in test_base
    ldb.store(istream)
  File "/home/yoh/deb/gits/python-gitdb/gitdb/db/loose.py", line 184, in store
    fd, tmp_path = tempfile.mkstemp(prefix='obj', dir=self._root_path)
  File "/usr/lib/python2.7/tempfile.py", line 308, in mkstemp
    return _mkstemp_inner(dir, prefix, suffix, flags)
  File "/usr/lib/python2.7/tempfile.py", line 239, in _mkstemp_inner
    fd = _os.open(file, flags, 0600)
OSError: [Errno 2] No such file or directory: '/home/yoh/deb/gits/python-gitdb/gitdb/test/fixtures/../../../.git/objects/objZdoPUA'

======================================================================
FAIL: test_writing (gitdb.test.db.test_ref.TestReferenceDB)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yoh/deb/gits/python-gitdb/gitdb/test/lib.py", line 60, in wrapper
    return func(self, path)
  File "/home/yoh/deb/gits/python-gitdb/gitdb/test/db/test_ref.py", line 46, in test_writing
    assert len(rdb.databases()) == 1
AssertionError

----------------------------------------------------------------------
Ran 24 tests in 13.322s

FAILED (SKIP=1, errors=4, failures=1)

I think it would have been best if there was a fixture for the tests battery which would initiate such a repository using git present on the system (thus testing against whatever git available) and do not even rely on me doing above dance manually. If some tests are really dependent on gitdb/.git -- I guess they could Skip if no upstairs .git available.

Thanks in advance!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions