2012-06-19 12:57:25 -03:00
|
|
|
|
|
|
|
import unittest
|
Add a Travis configuration
Travis[1] runs continuous integration for Open Source projects. With
github, it will run the configured tests and tag pull requests as passing
or failing. This commit adds a Travis configuration.
Since Travis hosts run debian/ubuntu, and execute tests in virtualenv,
getting access to `rpm` and `python-rpm` is impossible, or nontrivial,
at least. For now, ignore the functional tests. To support running the
BuildTargetParser tests, pull that class out into its own module, and
away from release.py, which imports `rpm`.
To configure travis, go to the website, log in with your github account,
then sync your repos under the account tab below your name. Then just
switch the repo to 'on' and it should be all set up.
[1]: http://travis-ci.org
2012-11-10 10:19:02 -04:00
|
|
|
from tito.buildparser import BuildTargetParser
|
2014-02-15 23:19:29 +00:00
|
|
|
from tito.compat import *
|
2012-06-19 12:57:25 -03:00
|
|
|
from tito.exception import TitoException
|
|
|
|
|
|
|
|
|
|
|
|
class BuildTargetParserTests(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
unittest.TestCase.setUp(self)
|
|
|
|
self.valid_branches = ["branch1", "branch2"]
|
|
|
|
|
|
|
|
self.release_target = "project-x.y.z"
|
avoid TB on python3 due to git format string
Use RawConfigParser instead of ConfigParser to avoid...
Traceback (most recent call last):
File "/home/sandbox/test/functional/multiproject_tests.py", line 68, in setUp
self.create_project(TEST_PKG_1, os.path.join(self.repo_dir, 'pkg1'))
File "/home/sandbox/test/functional/fixture.py", line 198, in create_project
tito('tag --keep-version --debug --accept-auto-changelog')
File "/home/sandbox/test/functional/fixture.py", line 103, in tito
return CLI().main(argstring.split(' '))
File "/home/sandbox/src/tito/cli.py", line 222, in main
return module.main(argv)
File "/home/sandbox/src/tito/cli.py", line 671, in main
offline=self.options.offline)
File "/home/sandbox/src/tito/tagger/main.py", line 51, in __init__
ConfigObject.__init__(self, config=config)
File "/home/sandbox/src/tito/config_object.py", line 38, in __init__
config.get(section, options))
File "/usr/lib64/python3.3/configparser.py", line 1184, in set
super().set(section, option, value)
File "/usr/lib64/python3.3/configparser.py", line 889, in set
value)
File "/usr/lib64/python3.3/configparser.py", line 399, in before_set
"position %d" % (value, tmp_value.find('%')))
nose.proxy.ValueError: ValueError: invalid interpolation syntax in '%s (%ae)' at position 0
2014-03-09 00:45:52 +00:00
|
|
|
self.releasers_config = RawConfigParser()
|
2012-06-19 12:57:25 -03:00
|
|
|
self.releasers_config.add_section(self.release_target)
|
|
|
|
self.releasers_config.set(self.release_target, "build_targets",
|
|
|
|
"branch1:project-x.y.z-candidate")
|
|
|
|
|
|
|
|
def test_parser_gets_correct_targets(self):
|
|
|
|
parser = BuildTargetParser(self.releasers_config, self.release_target,
|
|
|
|
self.valid_branches)
|
|
|
|
release_targets = parser.get_build_targets()
|
|
|
|
self.assertTrue("branch1" in release_targets)
|
|
|
|
self.assertEqual("project-x.y.z-candidate", release_targets["branch1"])
|
|
|
|
self.assertFalse("branch2" in release_targets)
|
|
|
|
|
|
|
|
def test_invalid_branch_raises_exception(self):
|
|
|
|
self.releasers_config.set(self.release_target, "build_targets",
|
|
|
|
"invalid-branch:project-x.y.z-candidate")
|
|
|
|
parser = BuildTargetParser(self.releasers_config, self.release_target,
|
|
|
|
self.valid_branches)
|
|
|
|
self.assertRaises(TitoException, parser.get_build_targets)
|
|
|
|
|
|
|
|
def test_missing_semicolon_raises_exception(self):
|
|
|
|
self.releasers_config.set(self.release_target, "build_targets",
|
|
|
|
"invalid-branchproject-x.y.z-candidate")
|
|
|
|
parser = BuildTargetParser(self.releasers_config, self.release_target,
|
|
|
|
self.valid_branches)
|
|
|
|
self.assertRaises(TitoException, parser.get_build_targets)
|
|
|
|
|
|
|
|
def test_empty_branch_raises_exception(self):
|
|
|
|
self.releasers_config.set(self.release_target, "build_targets",
|
|
|
|
":project-x.y.z-candidate")
|
|
|
|
parser = BuildTargetParser(self.releasers_config, self.release_target,
|
|
|
|
self.valid_branches)
|
|
|
|
self.assertRaises(TitoException, parser.get_build_targets)
|
|
|
|
|
|
|
|
def test_empty_target_raises_exception(self):
|
|
|
|
self.releasers_config.set(self.release_target, "build_targets",
|
|
|
|
"branch1:")
|
|
|
|
parser = BuildTargetParser(self.releasers_config, self.release_target,
|
|
|
|
self.valid_branches)
|
|
|
|
self.assertRaises(TitoException, parser.get_build_targets)
|
|
|
|
|
|
|
|
def test_multiple_spaces_ok(self):
|
|
|
|
self.releasers_config.set(self.release_target, "build_targets",
|
|
|
|
" branch1:project-x.y.z-candidate ")
|
|
|
|
parser = BuildTargetParser(self.releasers_config, self.release_target,
|
|
|
|
self.valid_branches)
|
|
|
|
release_targets = parser.get_build_targets()
|
|
|
|
self.assertEqual(1, len(release_targets))
|
|
|
|
self.assertTrue("branch1" in release_targets)
|
|
|
|
self.assertEqual("project-x.y.z-candidate", release_targets["branch1"])
|
|
|
|
|
|
|
|
def test_multiple_branches_supported(self):
|
|
|
|
self.releasers_config.set(self.release_target, "build_targets",
|
|
|
|
"branch1:project-x.y.z-candidate branch2:second-target")
|
|
|
|
parser = BuildTargetParser(self.releasers_config, self.release_target,
|
|
|
|
self.valid_branches)
|
|
|
|
release_targets = parser.get_build_targets()
|
|
|
|
self.assertEquals(2, len(release_targets))
|
|
|
|
self.assertTrue("branch1" in release_targets)
|
|
|
|
self.assertEqual("project-x.y.z-candidate", release_targets["branch1"])
|
|
|
|
self.assertTrue("branch2" in release_targets)
|
|
|
|
self.assertEqual("second-target", release_targets['branch2'])
|