def test_specific_plugin_installed(self): """ A specific plugin can be ran if it's installed. """ self._add_plugin(self.jigconfig, "plugin01") set_jigconfig(self.gitrepodir, config=self.jigconfig) # Create staged self.commit(self.gitrepodir, "a.txt", "a") self.stage(self.gitrepodir, "b.txt", "b") with nested(patch("jig.runner.sys"), self.assertRaises(SystemExit)) as (r_sys, ec): # Raise the error to halt execution like the real sys.exit would r_sys.exit.side_effect = SystemExit self.run_command("--plugin plugin01 {0}".format(self.gitrepodir)) self.assertResults( u""" ▾ plugin01 ⚠ line 1: b.txt b is + {0} Jig ran 1 plugin Info 0 Warn 1 Stop 0 """.format( ATTENTION ), self.output, )
def test_changes(self): """ Changes are made and the plugin runs and gives us output. """ self._add_plugin(self.jigconfig, "plugin01") set_jigconfig(self.gitrepodir, config=self.jigconfig) # Create staged changes self.commit(self.gitrepodir, "a.txt", "a") self.stage(self.gitrepodir, "b.txt", "b") with nested(patch("jig.runner.sys"), self.assertRaises(SystemExit)) as (r_sys, ec): # Raise the error to halt execution like the real sys.exit would r_sys.exit.side_effect = SystemExit self.run_command(self.gitrepodir) r_sys.exit.assert_called_once_with(0) self.assertResults( u""" ▾ plugin01 ⚠ line 1: b.txt b is + {0} Jig ran 1 plugin Info 0 Warn 1 Stop 0 """.format( ATTENTION ), self.output, )
def test_staged_one_file(self): """ Ran on a repository with a staged file. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Add the first commit because we have to have it self.commit( self.gitrepodir, name='a.txt', content='a') # Create a new file an stage it to the index self.stage( self.gitrepodir, name='b.txt', content='b') results = self.runner.results(self.gitrepodir) # One plugin ran, we should have results from it self.assertEqual(1, len(results)) # It's plugin01 self.assertEqual('plugin01', results.keys()[0].name) retcode, stdout, stderr = results.items()[0][1] # The return code is 0 self.assertEqual(0, retcode) # We auto-convert to an object self.assertEqual({u'b.txt': [[1, u'warn', u'b is +']]}, stdout) # And no errors occurred here self.assertEqual('', stderr)
def test_specific_plugin_installed(self): """ A specific plugin can be ran if it's installed. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Create staged self.commit(self.gitrepodir, 'a.txt', 'a') self.stage(self.gitrepodir, 'b.txt', 'b') with nested(patch('jig.runner.sys'), self.assertRaises(SystemExit)) as (r_sys, ec): # Raise the error to halt execution like the real sys.exit would r_sys.exit.side_effect = SystemExit self.run_command('--plugin plugin01 {0}'.format(self.gitrepodir)) self.assertResults( u""" ▾ plugin01 ⚠ line 1: b.txt b is + {0} Jig ran 1 plugin Info 0 Warn 1 Stop 0 """.format(ATTENTION), self.output)
def process(self, argv): path = argv.path plugins_file = argv.pluginsfile with self.out() as out: try: plugin_list = read_plugin_list(plugins_file) except IOError as e: # Grab the human-readable part of the IOError and raise that raise PluginError(e[1]) for plugin in plugin_list: config = get_jigconfig(path) pm = PluginManager(config) try: added = add_plugin(pm, plugin, path) except Exception as e: out.append('From {0}:\n - {1}'.format(plugin, e)) continue set_jigconfig(path, pm.config) out.append('From {0}:'.format(plugin)) for p in added: out.append(' - Added plugin {0} in bundle {1}'.format( p.name, p.bundle)) out.extend(USE_RUNNOW)
def test_modified_one_file(self): """ One modified and staged file. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Add the first commit because we have to have it self.commit( self.gitrepodir, name='a.txt', content='a') # We've created this but not added it to the index self.stage( self.gitrepodir, name='a.txt', content='aaa') results = self.runner.results(self.gitrepodir) _, stdout, _ = results.items()[0][1] self.assertEqual( {u'a.txt': [[1, u'warn', u'a is -'], [1, u'warn', u'aaa is +']]}, stdout)
def remove(self, argv): """ Remove a plugin. This method is smart enough to work with only the plugin name if it happens to be unique. If there is more than one plugin with the same name but in a different bundle it will exit with an error. """ path = argv.path name = argv.name bundle = argv.bundle with self.out() as out: config = get_jigconfig(path) pm = PluginManager(config) plugins = plugins_by_name(pm) # Find the bundle if it's not specified if name in plugins and not bundle: if len(plugins[name]) > 1: # There are more than one plugin by this name raise CommandError( 'More than one plugin has the name of ' '{0}. Use the list command to see installed ' 'plugins.'.format(name)) bundle = plugins[name][0].bundle pm.remove(bundle, name) set_jigconfig(path, pm.config) out.append('Removed plugin {0}'.format(name))
def test_handles_non_json_stdout(self): """ Supports non-JSON output from the plugin. """ with patch.object(Plugin, 'pre_commit'): Plugin.pre_commit.return_value = ( 0, 'Test non-JSON output', '') self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) self.commit( self.gitrepodir, name='a.txt', content='a') self.stage( self.gitrepodir, name='b.txt', content='b') results = self.runner.results(self.gitrepodir) _, stdout, _ = results.items()[0][1] # And we can still get the output even though it's not JSON self.assertEqual('Test non-JSON output', stdout)
def test_specific_plugin(self): """ Filter to results to a specific file. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) self.commit( self.gitrepodir, name='a.txt', content='a') self.stage( self.gitrepodir, name='b.txt', content='b') # We can filter to the one that is already installed self.assertEqual( 1, len(self.runner.results(self.gitrepodir, plugin='plugin01'))) # If we try to filter on a non-existent plugin we get no results self.assertEqual( 0, len(self.runner.results(self.gitrepodir, plugin='notinstalled')))
def test_will_prompt_user(self): """ User sees a prompt if there are messages. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Create staged changes self.commit(self.gitrepodir, 'a.txt', 'a') self.stage(self.gitrepodir, 'b.txt', 'b') with nested( patch('jig.runner.raw_input', create=True), patch('jig.runner.sys'), self.assertRaises(SystemExit) ) as (ri, r_sys, ec): # Fake the raw_input call to return 's' r_sys.exit.side_effect = SystemExit ri.return_value = 's' self.runner.main(self.gitrepodir) # The user was prompted about committing or canceling ri.assert_called_once_with( '\nCommit anyway (hit "c"), or stop (hit "s"): ') # When they said cancel we exited with non-zero r_sys.exit.assert_called_once_with(1)
def test_handles_retcode_1_with_stderr(self): """ Handles non-zero return codes and data written to stderr. """ with patch.object(Plugin, 'pre_commit'): Plugin.pre_commit.return_value = ( 1, '', 'Something went horribly wrong') self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) self.commit( self.gitrepodir, name='a.txt', content='a') self.stage( self.gitrepodir, name='b.txt', content='b') results = self.runner.results(self.gitrepodir) retcode, _, stderr = results.items()[0][1] self.assertEqual(1, retcode) self.assertEqual( 'Something went horribly wrong', stderr)
def test_will_prompt_but_continue_anyway(self): """ The user can choose to continue with the commit anyway. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Create staged changes self.commit(self.gitrepodir, 'a.txt', 'a') self.stage(self.gitrepodir, 'b.txt', 'b') with nested( patch('jig.runner.raw_input', create=True), patch('jig.runner.sys') ) as (ri, r_sys): # Fake the raw_input call to return 'c' ri.return_value = 'c' self.runner.main(self.gitrepodir) # The user was prompted about committing or canceling ri.assert_called_once_with( '\nCommit anyway (hit "c"), or stop (hit "s"): ') # When they said cancel we exited with non-zero r_sys.exit.assert_called_once_with(0)
def test_staged_one_file(self): """ Ran on a repository with a staged file. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Add the first commit because we have to have it self.commit(self.gitrepodir, name='a.txt', content='a') # Create a new file an stage it to the index self.stage(self.gitrepodir, name='b.txt', content='b') results = self.runner.results(self.gitrepodir) # One plugin ran, we should have results from it self.assertEqual(1, len(results)) # It's plugin01 self.assertEqual('plugin01', results.keys()[0].name) retcode, stdout, stderr = results.items()[0][1] # The return code is 0 self.assertEqual(0, retcode) # We auto-convert to an object self.assertEqual({u'b.txt': [[1, u'warn', u'b is +']]}, stdout) # And no errors occurred here self.assertEqual('', stderr)
def test_changes(self): """ Changes are made and the plugin runs and gives us output. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Create staged changes self.commit(self.gitrepodir, 'a.txt', 'a') self.stage(self.gitrepodir, 'b.txt', 'b') with nested(patch('jig.runner.sys'), self.assertRaises(SystemExit)) as (r_sys, ec): # Raise the error to halt execution like the real sys.exit would r_sys.exit.side_effect = SystemExit self.run_command(self.gitrepodir) r_sys.exit.assert_called_once_with(0) self.assertResults( u""" ▾ plugin01 ⚠ line 1: b.txt b is + {0} Jig ran 1 plugin Info 0 Warn 1 Stop 0 """.format(ATTENTION), self.output)
def test_will_prompt_user(self): """ User sees a prompt if there are messages. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Create staged changes self.commit(self.gitrepodir, 'a.txt', 'a') self.stage(self.gitrepodir, 'b.txt', 'b') with nested(patch('jig.runner.raw_input', create=True), patch('jig.runner.sys'), self.assertRaises(SystemExit)) as (ri, r_sys, ec): # Fake the raw_input call to return 's' r_sys.exit.side_effect = SystemExit ri.return_value = 's' self.runner.main(self.gitrepodir) # The user was prompted about committing or canceling ri.assert_called_once_with( '\nCommit anyway (hit "c"), or stop (hit "s"): ') # When they said cancel we exited with non-zero r_sys.exit.assert_called_once_with(1)
def test_save_config_not_initialized(self): """ Raises an error if saving a config where there is not Git repo. """ with self.assertRaises(GitRepoNotInitialized): # It hasn't been initialized at this point, this should fail set_jigconfig(self.gitrepodir, config=None)
def set(self, argv): """ Change a single setting for an installed plugin. """ path = argv.path key = argv.key key_parts = key.split('.', 3) config_value = argv.value with self.out(): if len(key_parts) != 3: # The key is not correct raise ConfigKeyInvalid( '{0} is an invalid config key.'.format(key)) bundle, plugin, config_key = key_parts config = get_jigconfig(path) pm = PluginManager(config) if not self._has_plugin(pm, bundle, plugin): raise CommandError('Could not locate plugin {0}.'.format( plugin)) section_name = 'plugin:{0}:{1}'.format( bundle, plugin) # Finally change the setting pm.config.set(section_name, config_key, config_value) set_jigconfig(path, pm.config)
def set(self, argv): """ Change a single setting for an installed plugin. """ path = argv.path key = argv.key key_parts = key.split('.', 3) config_value = argv.value with self.out(): if len(key_parts) != 3: # The key is not correct raise ConfigKeyInvalid( '{0} is an invalid config key.'.format(key)) bundle, plugin, config_key = key_parts config = get_jigconfig(path) pm = PluginManager(config) if not self._has_plugin(pm, bundle, plugin): raise CommandError( 'Could not locate plugin {0}.'.format(plugin)) section_name = 'plugin:{0}:{1}'.format(bundle, plugin) # Finally change the setting pm.config.set(section_name, config_key, config_value) set_jigconfig(path, pm.config)
def _add_plugin(self, plugin_dir): """ Adds a plugin to the jig initialized Git repository. """ config = get_jigconfig(self.gitrepodir) pm = PluginManager(config) pm.add(plugin_dir) set_jigconfig(self.gitrepodir, pm.config)
def setUp(self): super(TestReportCommand, self).setUp() self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Create a few commits self.commit(self.gitrepodir, 'a.txt', 'a') self.commit(self.gitrepodir, 'b.txt', 'b') self.commit(self.gitrepodir, 'c.txt', 'c')
def _set(self, gitrepodir, bundle_name, plugin_name, key, value): """ Change a setting for a plugin and save the Jig config. """ config = get_jigconfig(self.gitrepodir) pm = PluginManager(config) pm.config.set("plugin:{0}:{1}".format(bundle_name, plugin_name), key, value) set_jigconfig(self.gitrepodir, pm.config)
def test_save_config(self): """ Can save a config. """ config = initializer(self.gitrepodir) config.add_section('test') config.set('test', 'foo', 'bar') set_jigconfig(self.gitrepodir, config=config)
def test_bad_last_checked(self): """ If the repo has a bad last checked value. """ config = get_jigconfig(self.gitrepodir) config.set('jig', 'last_checked_for_updates', 'bad') set_jigconfig(self.gitrepodir, config) last_check = last_checked_for_updates(self.gitrepodir) self.assertEqual(0, last_check)
def test_no_last_checked(self): """ If the repo has never been checked for an update. """ config = get_jigconfig(self.gitrepodir) config.remove_section('jig') set_jigconfig(self.gitrepodir, config) last_check = last_checked_for_updates(self.gitrepodir) self.assertEqual(0, last_check)
def _set(self, gitrepodir, bundle_name, plugin_name, key, value): """ Change a setting for a plugin and save the Jig config. """ config = get_jigconfig(self.gitrepodir) pm = PluginManager(config) pm.config.set('plugin:{0}:{1}'.format(bundle_name, plugin_name), key, value) set_jigconfig(self.gitrepodir, pm.config)
def test_empty_repository(self): """ If .jig is ran on a repository that hasn't had any commits """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) self.runner.results(self.gitrepodir) self.assertEqual( 'This repository is empty, jig needs at ' 'least 1 commit to continue.\n', self.output)
def test_last_checked(self): """ Can determine the last time checked. """ now = datetime.utcnow().replace(microsecond=0) set_jigconfig(self.gitrepodir, config=set_checked_for_updates(self.gitrepodir)) date = last_checked_for_updates(self.gitrepodir) self.assertEqual(now, date)
def setUp(self): super(TestRunnerRevRange, self).setUp() repo, working_dir, diffs = self.repo_from_fixture('repo01') self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) for letter in ['a', 'b', 'c']: self.commit(self.gitrepodir, name='{0}.txt'.format(letter), content=letter)
def setUp(self): super(TestRunnerRevRange, self).setUp() repo, working_dir, diffs = self.repo_from_fixture('repo01') self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) for letter in ['a', 'b', 'c']: self.commit( self.gitrepodir, name='{0}.txt'.format(letter), content=letter)
def test_no_diff(self): """ If .jig is ran on a repository without any changes. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) self.commit(self.gitrepodir, name='a.txt', content='a') self.runner.results(self.gitrepodir) self.assertEqual( 'No staged changes in the repository, skipping jig.\n', self.output)
def test_already_checked_before(self): """ If this is not the first time a check has been set. """ set_jigconfig(self.gitrepodir, config=set_checked_for_updates(self.gitrepodir)) date1 = last_checked_for_updates(self.gitrepodir) set_jigconfig(self.gitrepodir, config=set_checked_for_updates(self.gitrepodir)) date2 = last_checked_for_updates(self.gitrepodir) self.assertEqual(date1, date2)
def _clear_settings(self, gitrepodir): """ Remove all plugin specific settings. """ config = get_jigconfig(self.gitrepodir) pm = PluginManager(config) for section in pm.config.sections(): if not section.startswith('plugin'): continue for option, value in pm.config.items(section): if option == 'path': continue pm.config.remove_option(section, option) set_jigconfig(self.gitrepodir, pm.config)
def test_no_changes(self): """ No changes have been made to the Git repository. """ self._add_plugin(self.jigconfig, "plugin01") set_jigconfig(self.gitrepodir, config=self.jigconfig) # Create the first commit self.commit(self.gitrepodir, "a.txt", "a") with self.assertRaises(SystemExit) as ec: self.run_command(self.gitrepodir) self.assertSystemExitCode(ec.exception, 0) self.assertEqual(u"No staged changes in the repository, " u"skipping jig.\n", self.output)
def _clear_settings(self, gitrepodir): """ Remove all plugin specific settings. """ config = get_jigconfig(self.gitrepodir) pm = PluginManager(config) for section in pm.config.sections(): if not section.startswith("plugin"): continue for option, value in pm.config.items(section): if option == "path": continue pm.config.remove_option(section, option) set_jigconfig(self.gitrepodir, pm.config)
def test_no_diff(self): """ If .jig is ran on a repository without any changes. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) self.commit( self.gitrepodir, name='a.txt', content='a') self.runner.results(self.gitrepodir) self.assertEqual( 'No staged changes in the repository, skipping jig.\n', self.output)
def test_deleted_one_file(self): """ Delete one file. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) self.commit(self.gitrepodir, name='a.txt', content='a') # Now stage a file for removal self.stage_remove(self.gitrepodir, name='a.txt') results = self.runner.results(self.gitrepodir) _, stdout, _ = results.items()[0][1] # We should see it being removed self.assertEqual({u'a.txt': [[1, u'warn', u'a is -']]}, stdout)
def test_unstaged_one_file(self): """ Ran on a repository with an unstaged file. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Add the first commit because we have to have it self.commit(self.gitrepodir, name='a.txt', content='a') # We've created this but not added it to the index self.create_file(self.gitrepodir, name='b.txt', content='b') self.runner.results(self.gitrepodir) self.assertEqual( 'No staged changes in the repository, skipping jig.\n', self.output)
def test_no_changes(self): """ No changes have been made to the Git repository. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Create the first commit self.commit(self.gitrepodir, 'a.txt', 'a') with self.assertRaises(SystemExit) as ec: self.run_command(self.gitrepodir) self.assertSystemExitCode(ec.exception, 0) self.assertEqual( u'No staged changes in the repository, ' u'skipping jig.\n', self.output)
def test_specific_plugin_not_installed(self): """ A specific plugin can be ran but it's not installed. """ self._add_plugin(self.jigconfig, "plugin01") set_jigconfig(self.gitrepodir, config=self.jigconfig) # Create staged self.commit(self.gitrepodir, "a.txt", "a") self.stage(self.gitrepodir, "b.txt", "b") with nested(patch("jig.runner.sys"), self.assertRaises(SystemExit)) as (r_sys, ec): # Raise the error to halt execution like the real sys.exit would r_sys.exit.side_effect = SystemExit self.run_command("--plugin notinstalled {0}".format(self.gitrepodir)) # A plugin which is not installed was requested so not output self.assertEqual("", self.output)
def test_specific_plugin(self): """ Filter to results to a specific file. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) self.commit(self.gitrepodir, name='a.txt', content='a') self.stage(self.gitrepodir, name='b.txt', content='b') # We can filter to the one that is already installed self.assertEqual( 1, len(self.runner.results(self.gitrepodir, plugin='plugin01'))) # If we try to filter on a non-existent plugin we get no results self.assertEqual( 0, len(self.runner.results(self.gitrepodir, plugin='notinstalled')))
def test_handles_non_json_stdout(self): """ Supports non-JSON output from the plugin. """ with patch.object(Plugin, 'pre_commit'): Plugin.pre_commit.return_value = (0, 'Test non-JSON output', '') self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) self.commit(self.gitrepodir, name='a.txt', content='a') self.stage(self.gitrepodir, name='b.txt', content='b') results = self.runner.results(self.gitrepodir) _, stdout, _ = results.items()[0][1] # And we can still get the output even though it's not JSON self.assertEqual('Test non-JSON output', stdout)
def test_modified_one_file(self): """ One modified and staged file. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Add the first commit because we have to have it self.commit(self.gitrepodir, name='a.txt', content='a') # We've created this but not added it to the index self.stage(self.gitrepodir, name='a.txt', content='aaa') results = self.runner.results(self.gitrepodir) _, stdout, _ = results.items()[0][1] self.assertEqual( {u'a.txt': [[1, u'warn', u'a is -'], [1, u'warn', u'aaa is +']]}, stdout)
def test_handles_retcode_1_with_stderr(self): """ Handles non-zero return codes and data written to stderr. """ with patch.object(Plugin, 'pre_commit'): Plugin.pre_commit.return_value = (1, '', 'Something went horribly wrong') self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) self.commit(self.gitrepodir, name='a.txt', content='a') self.stage(self.gitrepodir, name='b.txt', content='b') results = self.runner.results(self.gitrepodir) retcode, _, stderr = results.items()[0][1] self.assertEqual(1, retcode) self.assertEqual('Something went horribly wrong', stderr)
def test_will_continue_to_prompt_until_correctly_answered(self): """ The user must answer 'c' or 's' and nothing else. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Create staged changes self.commit(self.gitrepodir, 'a.txt', 'a') self.stage(self.gitrepodir, 'b.txt', 'b') with nested(patch('jig.runner.raw_input', create=True), patch('jig.runner.sys')) as (ri, r_sys): # Fake the raw_input call to return 'c' only after giving # two incorrect options. ri.side_effect = ['1', '2', 'c'] self.runner.main(self.gitrepodir) # raw_input was called 3 times until it received a proper response self.assertEqual(3, ri.call_count)
def test_deleted_one_file(self): """ Delete one file. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) self.commit( self.gitrepodir, name='a.txt', content='a') # Now stage a file for removal self.stage_remove(self.gitrepodir, name='a.txt') results = self.runner.results(self.gitrepodir) _, stdout, _ = results.items()[0][1] # We should see it being removed self.assertEqual({u'a.txt': [[1, u'warn', u'a is -']]}, stdout)
def test_specific_plugin_not_installed(self): """ A specific plugin can be ran but it's not installed. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Create staged self.commit(self.gitrepodir, 'a.txt', 'a') self.stage(self.gitrepodir, 'b.txt', 'b') with nested(patch('jig.runner.sys'), self.assertRaises(SystemExit)) as (r_sys, ec): # Raise the error to halt execution like the real sys.exit would r_sys.exit.side_effect = SystemExit self.run_command('--plugin notinstalled {0}'.format( self.gitrepodir)) # A plugin which is not installed was requested so not output self.assertEqual('', self.output)
def add(self, argv): """ Add a plugin. """ path = argv.path plugin = argv.plugin with self.out() as out: config = get_jigconfig(path) pm = PluginManager(config) added = add_plugin(pm, plugin, path) set_jigconfig(path, pm.config) for p in added: out.append( 'Added plugin {0} in bundle {1} to the ' 'repository.'.format(p.name, p.bundle)) out.extend(USE_RUNNOW)
def test_will_abort_on_keyboard_interrupt(self): """ The user can CTRL-C out of it and the commit is canceled. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Create staged changes self.commit(self.gitrepodir, 'a.txt', 'a') self.stage(self.gitrepodir, 'b.txt', 'b') with nested(patch('jig.runner.raw_input', create=True), patch('jig.runner.sys'), self.assertRaises(SystemExit)) as (ri, r_sys, ec): # Fake the raw_input call to return 'c' ri.side_effect = KeyboardInterrupt r_sys.exit.side_effect = SystemExit self.runner.main(self.gitrepodir) # We exited with 1 to indicate the commit should abort r_sys.exit.assert_called_once_with(1)
def test_will_continue_to_prompt_until_correctly_answered(self): """ The user must answer 'c' or 's' and nothing else. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Create staged changes self.commit(self.gitrepodir, 'a.txt', 'a') self.stage(self.gitrepodir, 'b.txt', 'b') with nested( patch('jig.runner.raw_input', create=True), patch('jig.runner.sys') ) as (ri, r_sys): # Fake the raw_input call to return 'c' only after giving # two incorrect options. ri.side_effect = ['1', '2', 'c'] self.runner.main(self.gitrepodir) # raw_input was called 3 times until it received a proper response self.assertEqual(3, ri.call_count)
def test_unstaged_one_file(self): """ Ran on a repository with an unstaged file. """ self._add_plugin(self.jigconfig, 'plugin01') set_jigconfig(self.gitrepodir, config=self.jigconfig) # Add the first commit because we have to have it self.commit( self.gitrepodir, name='a.txt', content='a') # We've created this but not added it to the index self.create_file( self.gitrepodir, name='b.txt', content='b') self.runner.results(self.gitrepodir) self.assertEqual( 'No staged changes in the repository, skipping jig.\n', self.output)