
This commit intentionally introduces a number of important API breakages. Specifically, the jenkins_jobs.cmd module has been pared down to some of its most difficult-to-refactor elements. * Create jenkins_jobs.cli.entry.JenkinsJobs class to organize command line parsing and execution. * Remove references to ConfigParser object in test code, hidden as an implementation detail of JenkinsJobs command line parsing. This will be necessary in the next stage of JJB 2.0 code which will be to create a JJBConfig object that handles logic and presentation of configuration from various sources--defaults, command line arguments, configuration file, and maybe environment variables in the future. * Remove references to Namespace object produced by argparse module. Required rewrite of multipath & recursive path tests with a new MatchesDir testtools Matcher class that validates the expected output for a run of JJB against a given set of yamldirs with the specified command line arguments. * Use stevedore to dynamically load subcommand parsers. * Move configuration loading/testing to its own test file. Also fix the global vs home directory JJB config file test. Change-Id: If62280418ba7319c313033ab387af4284237747e
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
import os
|
|
|
|
import testtools
|
|
from jenkins_jobs.cli import entry
|
|
from tests.base import LoggingFixture
|
|
from tests.base import mock
|
|
|
|
|
|
class CmdTestsBase(LoggingFixture, testtools.TestCase):
|
|
|
|
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
|
|
|
def setUp(self):
|
|
super(CmdTestsBase, self).setUp()
|
|
|
|
# Testing the cmd module can sometimes result in the CacheStorage class
|
|
# attempting to create the cache directory multiple times as the tests
|
|
# are run in parallel. Stub out the CacheStorage to ensure that each
|
|
# test can safely create the cache directory without risk of
|
|
# interference.
|
|
cache_patch = mock.patch('jenkins_jobs.builder.CacheStorage',
|
|
autospec=True)
|
|
self.cache_mock = cache_patch.start()
|
|
self.addCleanup(cache_patch.stop)
|
|
|
|
self.default_config_file = os.path.join(self.fixtures_path,
|
|
'empty_builder.ini')
|
|
|
|
def execute_jenkins_jobs_with_args(self, args):
|
|
jenkins_jobs = entry.JenkinsJobs(args)
|
|
jenkins_jobs.execute()
|
|
|
|
|
|
class CmdTests(CmdTestsBase):
|
|
|
|
def test_with_empty_args(self):
|
|
"""
|
|
User passes no args, should fail with SystemExit
|
|
"""
|
|
with mock.patch('sys.stderr'):
|
|
self.assertRaises(SystemExit, entry.JenkinsJobs, [])
|