diff options
author | Guido Günther <agx@sigxcpu.org> | 2015-01-25 15:10:12 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2015-01-25 15:14:59 +0100 |
commit | be16d2ebc6c6f13df05d79f4eb97e8e470529c93 (patch) | |
tree | 7ac002fa8a5dba8158431de49faaf53352af0ee9 /tests/testutils/debiangittestrepo.py | |
parent | 59402f62fe9e46ed7b0e29d9cf6a56177a57a73d (diff) |
testutils: split out DebianGitTestRepo
Gbp-Dch: Ignore
Diffstat (limited to 'tests/testutils/debiangittestrepo.py')
-rw-r--r-- | tests/testutils/debiangittestrepo.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/testutils/debiangittestrepo.py b/tests/testutils/debiangittestrepo.py new file mode 100644 index 0000000..61456f1 --- /dev/null +++ b/tests/testutils/debiangittestrepo.py @@ -0,0 +1,41 @@ +# vim: set fileencoding=utf-8 : + +from .. import context + +import os +import unittest + +import gbp.deb.git + +class DebianGitTestRepo(unittest.TestCase): + """Scratch repo for a single unit test""" + + def setUp(self): + self.tmpdir = context.new_tmpdir(__name__) + + repodir = self.tmpdir.join('test_repo') + self.repo = gbp.deb.git.DebianGitRepository.create(repodir) + + def tearDown(self): + context.teardown() + + def add_file(self, name, content=None, msg=None): + """ + Add a single file with name I{name} and content I{content}. If + I{content} is C{none} the content of the file is undefined. + + @param name: the file's path relativ to the git repo + @type name: C{str} + @param content: the file's content + @type content: C{str} + """ + path = os.path.join(self.repo.path, name) + + d = os.path.dirname(path) + if not os.path.exists(d): + os.makedirs(d) + + with open(path, 'w+') as f: + content == None or f.write(content) + self.repo.add_files(name, force=True) + self.repo.commit_files(path, msg or "added %s" % name) |