summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Collins <rbtcollins@hp.com>2014-03-13 18:04:45 +1300
committerRobert Collins <rbtcollins@hp.com>2014-03-17 09:16:24 +1300
commit542cd8057e81476857919cda9714d31cf9cdff01 (patch)
treef288ec1d393d093d2354e87ade0c1775d8b58839
parent6ffff7c95706e3a39e82fa0362e825aab21cbb26 (diff)
downloadpbr-542cd8057e81476857919cda9714d31cf9cdff01.tar.gz
Remove duplicate git setup in tests.
Less duplication for more reuse. If the intent was clarity before, I'm happy to skip this and just have duplicate code... Change-Id: I09fd14ecd9751e79a3a475dedf320c36ba0ba71c
-rw-r--r--pbr/tests/base.py4
-rw-r--r--pbr/tests/test_packaging.py35
2 files changed, 31 insertions, 8 deletions
diff --git a/pbr/tests/base.py b/pbr/tests/base.py
index f18dadc..6c31bc9 100644
--- a/pbr/tests/base.py
+++ b/pbr/tests/base.py
@@ -92,6 +92,10 @@ class BaseTestCase(testtools.TestCase, testresources.ResourcedTestCase):
self.log_fixture = self.useFixture(
fixtures.FakeLogger('pbr'))
+ # Older git does not have config --local, so create a temporary home
+ # directory to permit using git config --global without stepping on
+ # developer configuration.
+ self.useFixture(fixtures.TempHomeDir())
self.useFixture(fixtures.NestedTempfile())
self.useFixture(fixtures.FakeLogger())
self.useFixture(fixtures.EnvironmentVariable('PBR_VERSION', '0.0'))
diff --git a/pbr/tests/test_packaging.py b/pbr/tests/test_packaging.py
index 029f378..d01c4fb 100644
--- a/pbr/tests/test_packaging.py
+++ b/pbr/tests/test_packaging.py
@@ -47,16 +47,36 @@ from pbr import packaging
from pbr.tests import base
+class TestRepo(fixtures.Fixture):
+ """A git repo for testing with.
+
+ Use of TempHomeDir with this fixture is strongly recommended as due to the
+ lack of config --local in older gits, it will write to the users global
+ configuration without TempHomeDir.
+ """
+
+ def __init__(self, basedir):
+ super(TestRepo, self).__init__()
+ self._basedir = basedir
+
+ def setUp(self):
+ super(TestRepo, self).setUp()
+ base._run_cmd(['git', 'init', '.'], self._basedir)
+ base._run_cmd(
+ ['git', 'config', '--global', 'user.email', 'example@example.com'],
+ self._basedir)
+ base._run_cmd(['git', 'add', '.'], self._basedir)
+
+ def commit(self):
+ base._run_cmd(['git', 'commit', '-m', 'test commit'], self._basedir)
+
+
class TestPackagingInGitRepoWithCommit(base.BaseTestCase):
def setUp(self):
super(TestPackagingInGitRepoWithCommit, self).setUp()
- self.useFixture(fixtures.TempHomeDir())
- self._run_cmd(
- 'git', ['config', '--global', 'user.email', 'nobody@example.com'])
- self._run_cmd('git', ['init', '.'])
- self._run_cmd('git', ['add', '.'])
- self._run_cmd('git', ['commit', '-m', 'test commit'])
+ repo = self.useFixture(TestRepo(self.package_dir))
+ repo.commit()
self.run_setup('sdist')
return
@@ -77,8 +97,7 @@ class TestPackagingInGitRepoWithoutCommit(base.BaseTestCase):
def setUp(self):
super(TestPackagingInGitRepoWithoutCommit, self).setUp()
- self._run_cmd('git', ['init', '.'])
- self._run_cmd('git', ['add', '.'])
+ self.useFixture(TestRepo(self.package_dir))
self.run_setup('sdist')
return