Add some multi-project builder tests.

This commit is contained in:
Devan Goodwin 2010-05-24 23:16:49 -03:00
parent 7e8017571f
commit dc27216b51
4 changed files with 32 additions and 9 deletions

View file

@ -141,6 +141,9 @@ class Builder(object):
print("Building package [%s]" % (self.build_tag))
self.no_cleanup = options.no_cleanup
# Track full path to artifacts build during this run:
self.artifacts = []
if options.tgz:
self.tgz()
if options.srpm:
@ -156,6 +159,7 @@ class Builder(object):
self._koji_release()
self.cleanup()
return self.artifacts
def tgz(self):
"""
@ -173,6 +177,7 @@ class Builder(object):
full_path = os.path.join(self.rpmbuild_basedir, self.tgz_filename)
print("Wrote: %s" % full_path)
self.sources.append(full_path)
self.artifacts.append(full_path)
return full_path
# TODO: reuse_cvs_checkout isn't needed here, should be cleaned up:
@ -200,6 +205,7 @@ class Builder(object):
output = run_command(cmd)
print(output)
self.srpm_location = self._find_wrote_in_rpmbuild_output(output)[0]
self.artifacts.append(self.srpm_location)
def _rpm(self):
""" Build an RPM. """
@ -223,6 +229,7 @@ class Builder(object):
if len(files_written) < 2:
error_out("Error parsing rpmbuild output")
self.srpm_location = files_written[0]
self.artifacts.extend(files_written)
print
print("Successfully built: %s" % ' '.join(files_written))

View file

@ -89,14 +89,13 @@ class CLI(object):
"""
def main(self, argv):
print("argv = %s" % argv)
if len(argv) < 1 or not argv[0] in CLI_MODULES.keys():
self._usage()
sys.exit(1)
module_class = CLI_MODULES[argv[0]]
module = module_class()
module.main(argv)
return module.main(argv)
def _usage(self):
print("Usage: tito MODULENAME --help")
@ -380,7 +379,7 @@ class BuildModule(BaseCliModule):
builder = self._create_builder(package_name, build_tag,
build_version, self.options, self.pkg_config,
build_dir)
builder.run(self.options)
return builder.run(self.options)
def _create_builder(self, package_name, build_tag, build_version, options,
pkg_config, build_dir):
@ -489,7 +488,7 @@ class TagModule(BaseCliModule):
offline=self.options.offline)
try:
tagger.run(self.options)
return tagger.run(self.options)
except TitoException, e:
error_out(e.message)
@ -554,6 +553,7 @@ class InitModule(BaseCliModule):
print(" - committed to git")
print("Done!")
return []
class ReportModule(BaseCliModule):
@ -587,6 +587,7 @@ class ReportModule(BaseCliModule):
if self.options.untagged_commits:
self._run_untagged_commits(self.global_config)
sys.exit(1)
return []
def _run_untagged_commits(self, global_config):
"""

View file

@ -100,7 +100,7 @@ class Empty(object):
def tito(argstring):
""" Run Tito from source with given arguments. """
CLI().main(argstring.split(' '))
return CLI().main(argstring.split(' '))
class TitoGitTestFixture(unittest.TestCase):
"""

View file

@ -29,13 +29,13 @@ from fixture import *
# A location where we can safely create a test git repository.
# WARNING: This location will be destroyed if present.
TEST_PKG_1 = 'tito-test-pkg'
TEST_PKG_1 = 'titotestpkg'
TEST_PKG_1_DIR = "%s/" % TEST_PKG_1
TEST_PKG_2 = 'tito-test-pkg2'
TEST_PKG_2 = 'titotestpkg2'
TEST_PKG_2_DIR = "%s/" % TEST_PKG_2
TEST_PKG_3 = 'tito-test-pkg3'
TEST_PKG_3 = 'titotestpkg3'
TEST_PKG_3_DIR = "blah/whatever/%s/" % TEST_PKG_3
TEST_PKGS = [TEST_PKG_1, TEST_PKG_2, TEST_PKG_3]
@ -45,7 +45,7 @@ def release_bumped(initial_version, new_version):
new_release = new_version.split('-')[-1]
return new_release == str(int(first_release) + 1)
class MultiProjectTaggerTests(TitoGitTestFixture):
class MultiProjectTests(TitoGitTestFixture):
def setUp(self):
TitoGitTestFixture.setUp(self)
@ -95,4 +95,19 @@ class MultiProjectTaggerTests(TitoGitTestFixture):
new_ver = get_latest_tagged_version(TEST_PKG_2)
self.assertTrue(release_bumped(start_ver, new_ver))
def test_build_tgz(self):
os.chdir(os.path.join(self.repo_dir, 'pkg1'))
artifacts = tito('build --tgz')
self.assertEquals(1, len(artifacts))
self.assertEquals('%s-0.0.1.tar.gz' % TEST_PKG_1,
os.path.basename(artifacts[0]))
def test_build_rpm(self):
os.chdir(os.path.join(self.repo_dir, 'pkg1'))
artifacts = tito('build --rpm')
self.assertEquals(3, len(artifacts))
print artifacts