Merge pull request #109 from jumanjiman/deprecate_gitpython

Deprecate GitPython
This commit is contained in:
Devan Goodwin 2014-03-10 09:38:16 -03:00
commit b3a14db2e8
8 changed files with 38 additions and 41 deletions

View file

@ -26,8 +26,8 @@ Tests
To run all tests, install these packages:
* python-nose and python3-nose
* python-pep8 and python3-pep8
* python-nose, python-pep8, and rpm-python
* python3-nose, python3-pep8, and rpm-python3
* createrepo
Then from the root of the project:

View file

@ -144,7 +144,7 @@ class BuilderBase(object):
"""
if not self.no_cleanup:
debug("Cleaning up [%s]" % self.rpmbuild_dir)
commands.getoutput("rm -rf %s" % self.rpmbuild_dir)
getoutput("rm -rf %s" % self.rpmbuild_dir)
else:
print("WARNING: Leaving rpmbuild files in: %s" % self.rpmbuild_dir)
@ -165,7 +165,7 @@ class BuilderBase(object):
"""
Create the build directories. Can safely be called multiple times.
"""
commands.getoutput("mkdir -p %s %s %s %s" % (
getoutput("mkdir -p %s %s %s %s" % (
self.rpmbuild_basedir, self.rpmbuild_dir,
self.rpmbuild_sourcedir, self.rpmbuild_builddir))
self._check_build_dirs_access()

View file

@ -43,7 +43,4 @@ def getoutput(cmd):
Returns output of executing cmd in a shell.
Supports Python 2.4 and 3.x.
"""
if PY2:
return commands.getoutput(cmd)
else:
return subprocess.getoutput(cmd)
return getstatusoutput(cmd)[1]

View file

@ -12,7 +12,6 @@
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
import git
import os
import shutil
import tempfile
@ -117,23 +116,15 @@ class TitoGitTestFixture(unittest.TestCase):
print("Testing in: %s" % self.repo_dir)
print
# GitPython calls os.login(), which throws OSError if there is no tty,
# but GitPython allows to avoid the call if env var USER exists.
try:
os.getlogin()
except OSError:
os.environ['USER'] = 'nobody'
# Initialize the repo:
self.repo = git.Repo.init(path=self.repo_dir, mkdir=True, bare=False)
os.chdir(self.repo_dir)
run_command('git init')
# Next we tito init:
os.chdir(self.repo_dir)
tito("init")
run_command('echo "offline = true" >> rel-eng/tito.props')
index = self.repo.index
index.add(['rel-eng/tito.props'])
index.commit('Setting offline.')
run_command('git add rel-eng/tito.props')
run_command("git commit -m 'set offline in tito.props'")
def tearDown(self):
shutil.rmtree(self.repo_dir)
@ -196,13 +187,12 @@ class TitoGitTestFixture(unittest.TestCase):
out_f.write(TEST_PYTHON_SRC)
out_f.close()
index = self.repo.index
files = [os.path.join(pkg_dir, 'a.txt'),
os.path.join(pkg_dir, 'setup.py'),
os.path.join(pkg_dir, '%s.spec' % pkg_name),
os.path.join(pkg_dir, 'src/module.py')
]
index.add(files)
index.commit('Initial commit.')
run_command('git add %s' % ' '.join(files))
run_command("git commit -m 'initial commit'")
tito('tag --keep-version --debug --accept-auto-changelog')

View file

@ -68,20 +68,19 @@ class MultiProjectTests(TitoGitTestFixture):
self.create_project(TEST_PKG_1, os.path.join(self.repo_dir, 'pkg1'))
self.create_project(TEST_PKG_2, os.path.join(self.repo_dir, 'pkg2'))
self.create_project(TEST_PKG_3, os.path.join(self.repo_dir, 'pkg3'))
os.chdir(self.repo_dir)
# For second test package, use a tito.props to override and use the
# ReleaseTagger:
os.chdir(os.path.join(self.repo_dir, 'pkg2'))
filename = os.path.join(self.repo_dir, 'pkg2', "tito.props")
out_f = open(filename, 'w')
out_f.write("[buildconfig]\n")
out_f.write("tagger = tito.tagger.ReleaseTagger\n")
out_f.write("builder = tito.builder.Builder\n")
out_f.close()
index = self.repo.index
index.add(['pkg2/tito.props'])
index.commit("Adding tito.props for pkg2.")
os.chdir(self.repo_dir)
run_command('git add pkg2/tito.props')
run_command("git commit -m 'add tito.props for pkg2'")
def test_template_version_tagger(self):
"""
@ -94,9 +93,10 @@ class MultiProjectTests(TitoGitTestFixture):
run_command('mkdir -p %s' % join(self.repo_dir, 'rel-eng/templates'))
self.write_file(join(self.repo_dir,
'rel-eng/templates/version.rb'), VERSION_TEMPLATE_FILE)
index = self.repo.index
index.add(['pkg3/tito.props'])
index.commit("Adding tito.props for pkg3.")
os.chdir(self.repo_dir)
run_command('git add pkg3/tito.props')
run_command("git commit -m 'add tito.props for pkg3'")
# Create another pkg3 tag and make sure we got a generated
# template file.

View file

@ -49,14 +49,21 @@ class SingleProjectTests(TitoGitTestFixture):
check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True)
def test_undo_tag(self):
commit = self.repo.heads.master.commit
os.chdir(self.repo_dir)
original_head = getoutput('git show-ref -s refs/heads/master')
# Create tito tag, which adds a new commit and moves head.
tito("tag --accept-auto-changelog --debug")
tag = "%s-0.0.2-1" % PKG_NAME
check_tag_exists(tag, offline=True)
self.assertNotEqual(commit, self.repo.heads.master.commit)
new_head = getoutput('git show-ref -s refs/heads/master')
self.assertNotEqual(original_head, new_head)
# Undo tito tag, which rewinds one commit to original head.
tito("tag -u")
self.assertFalse(tag_exists_locally(tag))
self.assertEqual(commit, self.repo.heads.master.commit)
new_head = getoutput('git show-ref -s refs/heads/master')
self.assertEqual(original_head, new_head)
def test_latest_tgz(self):
tito("build --tgz -o %s" % self.repo_dir)

View file

@ -25,9 +25,7 @@ class TitoUnitTestFixture(unittest.TestCase):
Fixture providing setup/teardown and utilities for unit tests.
"""
def setUp(self):
# GitPython calls os.login(), which throws OSError if there is no tty,
# but GitPython allows to avoid the call if env var USER exists.
try:
os.getlogin()
except OSError:
os.environ['USER'] = 'nobody'
print
print
print("Testing in: %s" % REPO_DIR)
print

View file

@ -90,6 +90,11 @@ class UglyHackishTest(TitoUnitTestFixture):
result = int(getoutput(cmd))
self.assertEqual(result, 0, "Found commands module (not supported in Python 3)")
def test_use_commands(self):
cmd = "find . -type f -regex '.*\.py$' -exec egrep 'commands\.' {} + | grep -v 'compat\.py' | wc -l"
result = int(getoutput(cmd))
self.assertEqual(result, 0, "Found commands module (not supported in Python 3)")
def test_print_function(self):
cmd = "find . -type f -regex '.*\.py$' -exec grep '^[[:space:]]*print .*' {} + | wc -l"
result = int(getoutput(cmd))