summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2017-02-06 08:21:50 +0100
committerGuido Günther <agx@sigxcpu.org>2017-02-06 08:21:50 +0100
commite52819dc98d93c066d742e3a0885bcb00cd9c519 (patch)
tree95207c1bc2b502480619ce44593e2186f1e593eb
parentf4d444d1ec709d3fa001b3409cecada70df0a11d (diff)
tests: add add_files helper
-rw-r--r--tests/component/__init__.py7
-rw-r--r--tests/component/rpm/test_buildpackage_rpm.py9
-rw-r--r--tests/component/rpm/test_rpm_ch.py5
3 files changed, 10 insertions, 11 deletions
diff --git a/tests/component/__init__.py b/tests/component/__init__.py
index 013550e4..f56ea55f 100644
--- a/tests/component/__init__.py
+++ b/tests/component/__init__.py
@@ -239,3 +239,10 @@ class ComponentTestBase(unittest.TestCase, GbpLogTester):
if v is not None:
ok_(v == parsed[k],
"Got %s not expected value %s for %s" % (parsed[k], v, k))
+
+ @staticmethod
+ def add_file(repo, name, content=None):
+ with open(name, 'w') as f:
+ f.write(' ' or content)
+ repo.add_files(name)
+ repo.commit_files(name, 'New file %s' % name)
diff --git a/tests/component/rpm/test_buildpackage_rpm.py b/tests/component/rpm/test_buildpackage_rpm.py
index 020c0a0e..1ab883fe 100644
--- a/tests/component/rpm/test_buildpackage_rpm.py
+++ b/tests/component/rpm/test_buildpackage_rpm.py
@@ -250,13 +250,8 @@ class TestGbpRpm(RpmRepoTestBase):
orig_files = ['gbp-test/' + path for
path in repo.ls_tree(upstr_branch)] + ['gbp-test']
repo.set_branch(upstr_branch)
- with open('new-file', 'w') as fobj:
- fobj.write('New file\n')
- with open('new-file2', 'w') as fobj:
- fobj.write('New file 2\n')
- repo.add_files(['new-file', 'new-file2'])
- repo.commit_files('new-file', 'New content')
- repo.commit_files('new-file2', 'New content 2')
+ for fname in ['new-file', 'new-file2']:
+ self.add_file(repo, fname, 'new content %s' % fname)
repo.set_branch(pkg_branch)
# TAG (default) does not contain the new files
diff --git a/tests/component/rpm/test_rpm_ch.py b/tests/component/rpm/test_rpm_ch.py
index 3fa54363..8da347b3 100644
--- a/tests/component/rpm/test_rpm_ch.py
+++ b/tests/component/rpm/test_rpm_ch.py
@@ -293,10 +293,7 @@ class TestRpmCh(RpmRepoTestBase):
orig_content = self.read_file('packaging/gbp-test-native.changes')
# Add new commit with known content
- with open('new-file.txt', 'w') as fobj:
- fobj.write('this is new content\n')
- repo.add_files('new-file.txt')
- repo.commit_staged('Add new file')
+ self.add_file(repo, 'new-file.txt', 'this is new content\n')
# Only track a non-existent file
eq_(mock_ch(['--since=HEAD^', 'non-existent-path']), 0)