summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git/objects/commit.py2
-rw-r--r--git/test/db/cmd/test_base.py17
-rw-r--r--git/test/db/py/test_base.py11
-rw-r--r--git/test/lib/helper.py6
-rw-r--r--git/test/objects/lib.py6
-rw-r--r--git/test/test_config.py6
-rw-r--r--git/test/test_db.py25
-rw-r--r--git/test/test_diff.py11
-rw-r--r--git/test/test_example.py6
-rw-r--r--git/test/test_fun.py2
-rw-r--r--git/test/test_git.py141
-rw-r--r--git/test/test_import.py48
-rw-r--r--git/test/test_index.py8
-rw-r--r--git/test/test_reflog.py2
-rw-r--r--git/test/test_refs.py14
-rw-r--r--git/test/test_remote.py11
-rw-r--r--git/test/test_stats.py8
-rw-r--r--git/test/test_stream.py4
18 files changed, 191 insertions, 137 deletions
diff --git a/git/objects/commit.py b/git/objects/commit.py
index c201780c..c32bbf1a 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -29,7 +29,7 @@ from git.base import IStream
from cStringIO import StringIO
from util import parse_date
-from time import altzone
+from time import altzone, time
import os
import sys
diff --git a/git/test/db/cmd/test_base.py b/git/test/db/cmd/test_base.py
index 8d00f57f..59a6a55e 100644
--- a/git/test/db/cmd/test_base.py
+++ b/git/test/db/cmd/test_base.py
@@ -5,9 +5,8 @@
from git.test.lib import rorepo_dir
from git.test.db.base import RepoBase
-# immport test
-from git.db.cmd.base import *
-from git.db.cmd.complex import *
+from git.util import bin_to_hex
+from git.exc import BadObject
from git.db.complex import CmdCompatibilityGitDB
@@ -15,4 +14,14 @@ class TestBase(RepoBase):
RepoCls = CmdCompatibilityGitDB
def test_basics(self):
- pass
+ gdb = self.rorepo
+
+ # partial to complete - works with everything
+ hexsha = bin_to_hex(gdb.partial_to_complete_sha_hex("0.1.6"))
+ assert len(hexsha) == 40
+
+ assert bin_to_hex(gdb.partial_to_complete_sha_hex(hexsha[:20])) == hexsha
+
+ # fails with BadObject
+ for invalid_rev in ("0000", "bad/ref", "super bad"):
+ self.failUnlessRaises(BadObject, gdb.partial_to_complete_sha_hex, invalid_rev)
diff --git a/git/test/db/py/test_base.py b/git/test/db/py/test_base.py
index ade05c8d..6b06bbe9 100644
--- a/git/test/db/py/test_base.py
+++ b/git/test/db/py/test_base.py
@@ -5,17 +5,6 @@
from git.test.lib import rorepo_dir
from git.test.db.base import RepoBase
-# import test
-from git.db.py.base import *
-from git.db.py.loose import *
-from git.db.py.mem import *
-from git.db.py.pack import *
-from git.db.py.ref import *
-from git.db.py.resolve import *
-from git.db.py.submodule import *
-from git.db.py.transport import *
-from git.db.py.complex import *
-
from git.db.complex import PureCompatibilityGitDB
class TestPyDBBase(RepoBase):
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index f365e5b4..5776f526 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -219,6 +219,12 @@ class TestBase(TestCase):
self.failUnlessRaises(...)
"""
+ @classmethod
+ def setUpAll(cls):
+ """This method is only called to provide the most basic functionality
+ Subclasses may just override it or implement it differently"""
+ cls.rorepo = Repo(rorepo_dir())
+
def _make_file(self, rela_path, data, repo=None):
"""
Create a file at the given path relative to our repository, filled
diff --git a/git/test/objects/lib.py b/git/test/objects/lib.py
index c146833d..fe1d9f9d 100644
--- a/git/test/objects/lib.py
+++ b/git/test/objects/lib.py
@@ -8,11 +8,7 @@ from git.test.lib import (
with_rw_repo,
StringProcessAdapter,
)
-from git.repo import Repo
class TestObjectBase(TestBase):
"""Provides a default read-only repository in the rorepo member"""
-
- @classmethod
- def setUpAll(cls):
- cls.rorepo = Repo(rorepo_dir())
+ pass
diff --git a/git/test/test_config.py b/git/test/test_config.py
index b163b0af..d07fe6fd 100644
--- a/git/test/test_config.py
+++ b/git/test/test_config.py
@@ -4,13 +4,13 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-from git.test.lib import TestBase
-from git import *
+from git.test.lib import TestBase, fixture_path
import StringIO
+from git.config import *
from copy import copy
from ConfigParser import NoSectionError
-class TestBase(TestCase):
+class TestConfig(TestBase):
def _to_memcache(self, file_path):
fp = open(file_path, "r")
diff --git a/git/test/test_db.py b/git/test/test_db.py
deleted file mode 100644
index 825aadd9..00000000
--- a/git/test/test_db.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# test_repo.py
-# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors
-#
-# This module is part of GitPython and is released under
-# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-from git.test.lib import TestBase
-from git.db import *
-from git.util import bin_to_hex
-from git.exc import BadObject
-import os
-
-class TestDB(TestBase):
-
- def test_base(self):
- gdb = CmdGitDB(os.path.join(self.rorepo.git_dir, 'objects'), self.rorepo.git)
-
- # partial to complete - works with everything
- hexsha = bin_to_hex(gdb.partial_to_complete_sha_hex("0.1.6"))
- assert len(hexsha) == 40
-
- assert bin_to_hex(gdb.partial_to_complete_sha_hex(hexsha[:20])) == hexsha
-
- # fails with BadObject
- for invalid_rev in ("0000", "bad/ref", "super bad"):
- self.failUnlessRaises(BadObject, gdb.partial_to_complete_sha_hex, invalid_rev)
diff --git a/git/test/test_diff.py b/git/test/test_diff.py
index 0f006aa3..79f038e8 100644
--- a/git/test/test_diff.py
+++ b/git/test/test_diff.py
@@ -4,8 +4,15 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-from git.test.lib import TestBase
-from git import *
+from git.test.lib import (
+ TestBase,
+ StringProcessAdapter,
+ fixture,
+ assert_equal,
+ assert_true
+ )
+
+from git.diff import *
class TestDiff(TestBase):
diff --git a/git/test/test_example.py b/git/test/test_example.py
index 870424e5..dbab3118 100644
--- a/git/test/test_example.py
+++ b/git/test/test_example.py
@@ -3,9 +3,9 @@
# 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 lib import *
-from git import IStream
-from git.db.py import PureLooseObjectODB
+from lib import TestBase, fixture_path
+from git.base import IStream
+from git.db.py.loose import PureLooseObjectODB
from git.util import pool
from cStringIO import StringIO
diff --git a/git/test/test_fun.py b/git/test/test_fun.py
index 443f106c..ed069912 100644
--- a/git/test/test_fun.py
+++ b/git/test/test_fun.py
@@ -1,4 +1,4 @@
-from git.test.lib import TestBase
+from git.test.lib import TestBase, with_rw_repo
from git.objects.fun import (
traverse_tree_recursive,
traverse_trees_recursive,
diff --git a/git/test/test_git.py b/git/test/test_git.py
index 1f5ec6dd..aba09c1d 100644
--- a/git/test/test_git.py
+++ b/git/test/test_git.py
@@ -5,80 +5,89 @@
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
import os, sys
-from git.test.lib import TestBase
+from git.test.lib import (
+ TestBase,
+ patch_object,
+ raises,
+ assert_equal,
+ assert_true,
+ assert_match,
+ fixture_path
+ )
from git import Git, GitCommandError
-class TestGit(TestCase):
-
- @classmethod
- def setUpAll(cls):
- cls.git = Git(cls.rorepo.working_dir)
+class TestGit(TestBase):
+
+ @classmethod
+ def setUpAll(cls):
+ super(TestGit, cls).setUpAll()
+ cls.git = Git(cls.rorepo.working_dir)
- @patch_object(Git, 'execute')
- def test_call_process_calls_execute(self, git):
- git.return_value = ''
- self.git.version()
- assert_true(git.called)
- assert_equal(git.call_args, ((['git', 'version'],), {}))
+ @patch_object(Git, 'execute')
+ def test_call_process_calls_execute(self, git):
+ git.return_value = ''
+ self.git.version()
+ assert_true(git.called)
+ assert_equal(git.call_args, ((['git', 'version'],), {}))
- @raises(GitCommandError)
- def test_it_raises_errors(self):
- self.git.this_does_not_exist()
+ @raises(GitCommandError)
+ def test_it_raises_errors(self):
+ self.git.this_does_not_exist()
- def test_it_transforms_kwargs_into_git_command_arguments(self):
- assert_equal(["-s"], self.git.transform_kwargs(**{'s': True}))
- assert_equal(["-s5"], self.git.transform_kwargs(**{'s': 5}))
+ def test_it_transforms_kwargs_into_git_command_arguments(self):
+ assert_equal(["-s"], self.git.transform_kwargs(**{'s': True}))
+ assert_equal(["-s5"], self.git.transform_kwargs(**{'s': 5}))
- assert_equal(["--max-count"], self.git.transform_kwargs(**{'max_count': True}))
- assert_equal(["--max-count=5"], self.git.transform_kwargs(**{'max_count': 5}))
+ assert_equal(["--max-count"], self.git.transform_kwargs(**{'max_count': True}))
+ assert_equal(["--max-count=5"], self.git.transform_kwargs(**{'max_count': 5}))
- assert_equal(["-s", "-t"], self.git.transform_kwargs(**{'s': True, 't': True}))
+ assert_equal(["-s", "-t"], self.git.transform_kwargs(**{'s': True, 't': True}))
- def test_it_executes_git_to_shell_and_returns_result(self):
- assert_match('^git version [\d\.]{2}.*$', self.git.execute(["git","version"]))
+ def test_it_executes_git_to_shell_and_returns_result(self):
+ assert_match('^git version [\d\.]{2}.*$', self.git.execute(["git","version"]))
- def test_it_accepts_stdin(self):
- filename = fixture_path("cat_file_blob")
- fh = open(filename, 'r')
- assert_equal("70c379b63ffa0795fdbfbc128e5a2818397b7ef8",
- self.git.hash_object(istream=fh, stdin=True))
- fh.close()
+ def test_it_accepts_stdin(self):
+ filename = fixture_path("cat_file_blob")
+ fh = open(filename, 'r')
+ assert_equal("70c379b63ffa0795fdbfbc128e5a2818397b7ef8",
+ self.git.hash_object(istream=fh, stdin=True))
+ fh.close()
- @patch_object(Git, 'execute')
- def test_it_ignores_false_kwargs(self, git):
- # this_should_not_be_ignored=False implies it *should* be ignored
- output = self.git.version(pass_this_kwarg=False)
- assert_true("pass_this_kwarg" not in git.call_args[1])
-
- def test_persistent_cat_file_command(self):
- # read header only
- import subprocess as sp
- hexsha = "b2339455342180c7cc1e9bba3e9f181f7baa5167"
- g = self.git.cat_file(batch_check=True, istream=sp.PIPE,as_process=True)
- g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
- g.stdin.flush()
- obj_info = g.stdout.readline()
-
- # read header + data
- g = self.git.cat_file(batch=True, istream=sp.PIPE,as_process=True)
- g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
- g.stdin.flush()
- obj_info_two = g.stdout.readline()
- assert obj_info == obj_info_two
-
- # read data - have to read it in one large chunk
- size = int(obj_info.split()[2])
- data = g.stdout.read(size)
- terminating_newline = g.stdout.read(1)
-
- # now we should be able to read a new object
- g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
- g.stdin.flush()
- assert g.stdout.readline() == obj_info
-
-
- # same can be achived using the respective command functions
- hexsha, typename, size = self.git.get_object_header(hexsha)
- hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha)
- assert typename == typename_two and size == size_two
+ @patch_object(Git, 'execute')
+ def test_it_ignores_false_kwargs(self, git):
+ # this_should_not_be_ignored=False implies it *should* be ignored
+ output = self.git.version(pass_this_kwarg=False)
+ assert_true("pass_this_kwarg" not in git.call_args[1])
+
+ def test_persistent_cat_file_command(self):
+ # read header only
+ import subprocess as sp
+ hexsha = "b2339455342180c7cc1e9bba3e9f181f7baa5167"
+ g = self.git.cat_file(batch_check=True, istream=sp.PIPE,as_process=True)
+ g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
+ g.stdin.flush()
+ obj_info = g.stdout.readline()
+
+ # read header + data
+ g = self.git.cat_file(batch=True, istream=sp.PIPE,as_process=True)
+ g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
+ g.stdin.flush()
+ obj_info_two = g.stdout.readline()
+ assert obj_info == obj_info_two
+
+ # read data - have to read it in one large chunk
+ size = int(obj_info.split()[2])
+ data = g.stdout.read(size)
+ terminating_newline = g.stdout.read(1)
+
+ # now we should be able to read a new object
+ g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
+ g.stdin.flush()
+ assert g.stdout.readline() == obj_info
+
+
+ # same can be achived using the respective command functions
+ hexsha, typename, size = self.git.get_object_header(hexsha)
+ hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha)
+ assert typename == typename_two and size == size_two
diff --git a/git/test/test_import.py b/git/test/test_import.py
index d97cee55..a5a1d11b 100644
--- a/git/test/test_import.py
+++ b/git/test/test_import.py
@@ -6,9 +6,53 @@
module, by importing using from x import *"""
# perform the actual imports
+import os
-from nose import SkipTest
+from git import *
+
+def import_all(topdir, topmodule='git', skip = "test"):
+ base = os.path.basename
+ join = os.path.join
+ init_script = '__init__.py'
+ prev_cwd = os.getcwd()
+ try:
+ os.chdir(os.path.dirname(topdir))
+ for root, dirs, files in os.walk(base(topdir)):
+ if init_script not in files:
+ del(dirs[:])
+ continue
+ #END ignore non-packages
+
+ if skip in root:
+ continue
+ #END handle ignores
+
+ for relafile in files:
+ if not relafile.endswith('.py'):
+ continue
+ if relafile == init_script:
+ continue
+ module_path = join(root, os.path.splitext(relafile)[0]).replace("/", ".").replace("\\", ".")
+
+ m = __import__(module_path, globals(), locals(), [""])
+ try:
+ attrlist = m.__all__
+ for attr in attrlist:
+ assert hasattr(m, attr), "Invalid item in %s.__all__: %s" % (module_path, attr)
+ #END veriy
+ except AttributeError:
+ pass
+ # END try each listed attribute
+ #END for each file in dir
+ #END for each item
+ finally:
+ os.chdir(prev_cwd)
+ #END handle previous currentdir
+
+
class TestDummy(object):
def test_base(self):
- raise SkipTest("todo")
+ dn = os.path.dirname
+ # NOTE: i don't think this is working, as the __all__ variable is not used in this case
+ import_all(dn(dn(__file__)))
diff --git a/git/test/test_index.py b/git/test/test_index.py
index 3b94c4a6..7d65cb9b 100644
--- a/git/test/test_index.py
+++ b/git/test/test_index.py
@@ -4,7 +4,12 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-from git.test.lib import TestBase
+from git.test.lib import (
+ TestBase,
+ with_rw_repo,
+ fixture_path,
+ fixture
+ )
from git import *
import inspect
import os
@@ -12,6 +17,7 @@ import sys
import tempfile
import glob
import shutil
+import time
from stat import *
class TestIndex(TestBase):
diff --git a/git/test/test_reflog.py b/git/test/test_reflog.py
index 0207f4e4..271924aa 100644
--- a/git/test/test_reflog.py
+++ b/git/test/test_reflog.py
@@ -1,4 +1,4 @@
-from git.test.lib import TestBase
+from git.test.lib import TestBase, fixture_path
from git.objects import IndexObject
from git.refs import *
from git.util import Actor
diff --git a/git/test/test_refs.py b/git/test/test_refs.py
index 2e018e7f..3e6c0b3a 100644
--- a/git/test/test_refs.py
+++ b/git/test/test_refs.py
@@ -4,13 +4,15 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-from git.test.lib import TestBase
-from git.ref import *
-import git.ref as ref
+from git.test.lib import TestBase, with_rw_repo
+from git.refs import *
+import git.refs as ref
from git.util import Actor
from git.objects.tag import TagObject
+from git.exc import GitCommandError
+
from itertools import chain
import os
@@ -51,7 +53,7 @@ class TestRefs(TestBase):
# END if we have a tag object
# END for tag in repo-tags
assert tag_object_refs
- assert isinstance(TagReference.list_items(self.rorepo)['0.5.0'], TagReference)
+ assert isinstance(TagReference.list_items(self.rorepo)['0.1.6'], TagReference)
def test_tags(self):
# tag refs can point to tag objects or to commits
@@ -69,7 +71,7 @@ class TestRefs(TestBase):
assert len(s) == ref_count
assert len(s|s) == ref_count
- @with_rw_repo
+ @with_rw_repo("0.1.6")
def test_heads(self, rw_repo):
for head in Head.iter_items(rw_repo):
assert head.name
@@ -155,7 +157,7 @@ class TestRefs(TestBase):
def test_orig_head(self):
assert type(HEAD(self.rorepo).orig_head()) == SymbolicReference
- @with_rw_repo
+ @with_rw_repo("0.1.6")
def test_head_reset(self, rw_repo):
cur_head = HEAD(rw_repo)
old_head_commit = cur_head.commit
diff --git a/git/test/test_remote.py b/git/test/test_remote.py
index 301d1833..a7387816 100644
--- a/git/test/test_remote.py
+++ b/git/test/test_remote.py
@@ -4,9 +4,16 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-from git.test.lib import TestBase
-from git import *
+from git.test.lib import (
+ TestBase,
+ with_rw_and_rw_remote_repo,
+ with_rw_repo,
+ )
from git.util import IterableList
+from git.db.cmd.base import RemoteProgress
+from git.remote import *
+from git.exc import GitCommandError
+
import tempfile
import shutil
import os
diff --git a/git/test/test_stats.py b/git/test/test_stats.py
index b91ee1f6..27be6a77 100644
--- a/git/test/test_stats.py
+++ b/git/test/test_stats.py
@@ -4,8 +4,12 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-from git.test.lib import TestBase
-from git import *
+from git.test.lib import (
+ TestBase,
+ fixture,
+ assert_equal
+ )
+from git.util import Stats
class TestStats(TestBase):
diff --git a/git/test/test_stream.py b/git/test/test_stream.py
index 140dea95..8d7a5f9a 100644
--- a/git/test/test_stream.py
+++ b/git/test/test_stream.py
@@ -12,7 +12,7 @@ from lib import (
fixture_path
)
-from git import *
+from git.stream import *
from git.util import (
NULL_HEX_SHA,
hex_to_bin
@@ -23,7 +23,7 @@ from git.typ import (
str_blob_type
)
-from git.db.py import PureLooseObjectODB
+from git.db.py.loose import PureLooseObjectODB
import time
import tempfile
import os