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-02-04 13:01:05 +0200 |
commit | 249c5ed4d72afe610495f25ccc0589e7f5e46b92 (patch) | |
tree | ba62d4995d00918d8ab3d2771fe688625ddd696f /tests | |
parent | e686b25a24d151bb3cec524575063c441f47617e (diff) | |
download | git-buildpackage-249c5ed4d72afe610495f25ccc0589e7f5e46b92.tar.gz git-buildpackage-249c5ed4d72afe610495f25ccc0589e7f5e46b92.tar.bz2 git-buildpackage-249c5ed4d72afe610495f25ccc0589e7f5e46b92.zip |
rpm-tests: add RepoManifest class
Change-Id: I4819657fba25bad6a7b17bbf01ceb10445563516
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/component/rpm/__init__.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/component/rpm/__init__.py b/tests/component/rpm/__init__.py index e84fca94..831de81d 100644 --- a/tests/component/rpm/__init__.py +++ b/tests/component/rpm/__init__.py @@ -17,12 +17,49 @@ """Test module for RPM command line tools of the git-buildpackage suite""" import os +from xml.dom import minidom 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'): + branches[br_e.getAttribute('name')] = br_e.getAttribute('revision') + 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) |