diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2013-10-02 12:35:22 +0300 |
---|---|---|
committer | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2014-11-14 14:47:19 +0200 |
commit | af7a3c9d14e5a6cd53ececac6d2bc9007724220c (patch) | |
tree | f5b642d005104a17c5769bcf6824021593466cd2 /tests | |
parent | bffd714af55b59a16cad011ef7b05548251b8963 (diff) | |
download | git-buildpackage-af7a3c9d14e5a6cd53ececac6d2bc9007724220c.tar.gz git-buildpackage-af7a3c9d14e5a6cd53ececac6d2bc9007724220c.tar.bz2 git-buildpackage-af7a3c9d14e5a6cd53ececac6d2bc9007724220c.zip |
rpm-tests: add RepoManifest class
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/component/rpm/__init__.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/component/rpm/__init__.py b/tests/component/rpm/__init__.py index b9d22ade..0fcdf9dd 100644 --- a/tests/component/rpm/__init__.py +++ b/tests/component/rpm/__init__.py @@ -17,6 +17,7 @@ """Test module for RPM command line tools of the git-buildpackage suite""" import os +from xml.dom import minidom from tests.component import ComponentTestGitRepository @@ -27,6 +28,43 @@ from tests.component import ComponentTestGitRepository RPM_TEST_DATA_SUBMODULE = os.path.join('tests', 'component', 'rpm', 'data') RPM_TEST_DATA_DIR = os.path.abspath(RPM_TEST_DATA_SUBMODULE) +class RepoManifest(object): + """Class representing a test repo manifest file""" + def __init__(self, filename=None): + self._doc = minidom.Document() + if filename: + self._doc = minidom.parse(filename) + if self._doc.firstChild.nodeName != 'gbp-test-manifest': + raise Exception('%s is not a test repo manifest' % filename) + else: + self._doc.appendChild(self._doc.createElement("gbp-test-manifest")) + + def add_project(self, name, branches): + """Add new project to the manifest""" + prj_e = self._doc.createElement('project') + prj_e.setAttribute('name', name) + for branch, revision in branches.iteritems(): + br_e = self._doc.createElement('branch') + br_e.setAttribute('name', branch) + br_e.setAttribute('revision', revision) + prj_e.appendChild(br_e) + self._doc.firstChild.appendChild(prj_e) + + def projects_iter(self): + """Return an iterator over projects""" + for prj_e in self._doc.getElementsByTagName('project'): + branches = {} + for br_e in prj_e.getElementsByTagName('branch'): + rev = br_e.getAttribute('revision') + branches[br_e.getAttribute('name')] = rev + yield prj_e.getAttribute('name'), branches + + + def write(self, filename): + """Write to file""" + with open(filename, 'w') as fileobj: + fileobj.write(self._doc.toprettyxml()) + def setup(): """Test Module setup""" ComponentTestGitRepository.check_testdata(RPM_TEST_DATA_SUBMODULE) |