From 0e218077b34195fc08a46898ab81412cd5d5a318 Mon Sep 17 00:00:00 2001 From: Paul Morgan Date: Sat, 8 Mar 2014 22:26:01 +0000 Subject: [PATCH 1/3] HACKING: tests on python3 require rpm-python3 --- HACKING | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HACKING b/HACKING index 0eeb174..21fcf7a 100644 --- a/HACKING +++ b/HACKING @@ -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: From a0d0f859c7d1613f62a5179b2886cd40701231ff Mon Sep 17 00:00:00 2001 From: Paul Morgan Date: Sun, 9 Mar 2014 01:18:29 +0000 Subject: [PATCH 2/3] resolve another use of commands module for python3 compat 03255001d6 moved commands module to src/tito/compat.py to handle differences between python2 and python3, but missed a bit that did not show up in unit or functional tests. Fix those occurences and add unit test to detect the regression. --- src/tito/builder/main.py | 4 ++-- src/tito/compat.py | 5 +---- test/unit/pep8-tests.py | 5 +++++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/tito/builder/main.py b/src/tito/builder/main.py index 315999b..5172876 100644 --- a/src/tito/builder/main.py +++ b/src/tito/builder/main.py @@ -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() diff --git a/src/tito/compat.py b/src/tito/compat.py index ca8a15c..90fc1ba 100644 --- a/src/tito/compat.py +++ b/src/tito/compat.py @@ -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] diff --git a/test/unit/pep8-tests.py b/test/unit/pep8-tests.py index f3671a0..a62808e 100644 --- a/test/unit/pep8-tests.py +++ b/test/unit/pep8-tests.py @@ -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)) From 3ae15969237b8cd292fdd7601e8ed74b92971193 Mon Sep 17 00:00:00 2001 From: Paul Morgan Date: Sat, 8 Mar 2014 22:25:35 +0000 Subject: [PATCH 3/3] deprecate GitPython GitPython is not compatible with python3 and may never be: https://fedoraproject.org/wiki/User:Churchyard/python3 --- test/functional/fixture.py | 22 ++++++---------------- test/functional/multiproject_tests.py | 16 ++++++++-------- test/functional/singleproject_tests.py | 13 ++++++++++--- test/unit/fixture.py | 10 ++++------ 4 files changed, 28 insertions(+), 33 deletions(-) diff --git a/test/functional/fixture.py b/test/functional/fixture.py index 81207de..e779172 100644 --- a/test/functional/fixture.py +++ b/test/functional/fixture.py @@ -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') diff --git a/test/functional/multiproject_tests.py b/test/functional/multiproject_tests.py index cf26b67..b7e2046 100644 --- a/test/functional/multiproject_tests.py +++ b/test/functional/multiproject_tests.py @@ -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. diff --git a/test/functional/singleproject_tests.py b/test/functional/singleproject_tests.py index ef2f0d0..1d66fce 100644 --- a/test/functional/singleproject_tests.py +++ b/test/functional/singleproject_tests.py @@ -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) diff --git a/test/unit/fixture.py b/test/unit/fixture.py index 58908ac..ab00ff8 100644 --- a/test/unit/fixture.py +++ b/test/unit/fixture.py @@ -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