def test_remove_plugin_same_name(self): """ Exits because more than one plugin has the same name. If the bundle is not specified and more than one plugin has the same name, we can't assume which plugin they wish to remove. Error out and suggest they use the list command. """ plugin_dir1 = create_plugin( mkdtemp(), template='python', bundle='bundle1', name='name') plugin_dir2 = create_plugin( mkdtemp(), template='python', bundle='bundle2', name='name') self.run_command('add -r {0} {1}'.format(self.gitrepodir, plugin_dir1)) self.run_command('add -r {0} {1}'.format(self.gitrepodir, plugin_dir2)) with self.assertRaises(ForcedExit): # Leave the bundle out, this should make our command error out self.run_command('remove -r {0} name'.format(self.gitrepodir)) self.assertEqual( u'More than one plugin has the name of name. Use the list ' u'command to see installed plugins.\n', self.error)
def test_remove_plugin_same_name(self): """ Exits because more than one plugin has the same name. If the bundle is not specified and more than one plugin has the same name, we can't assume which plugin they wish to remove. Error out and suggest they use the list command. """ plugin_dir1 = create_plugin(mkdtemp(), template='python', bundle='bundle1', name='name') plugin_dir2 = create_plugin(mkdtemp(), template='python', bundle='bundle2', name='name') self.run_command('add -r {0} {1}'.format(self.gitrepodir, plugin_dir1)) self.run_command('add -r {0} {1}'.format(self.gitrepodir, plugin_dir2)) with self.assertRaises(ForcedExit): # Leave the bundle out, this should make our command error out self.run_command('remove -r {0} name'.format(self.gitrepodir)) self.assertEqual( u'More than one plugin has the name of name. Use the list ' u'command to see installed plugins.\n', self.error)
def test_list_plugins_same_bundle(self): """ Lists plugins correctly if they are in the same bundle. """ self._add_plugin( create_plugin(self.plugindir, template='python', bundle='test', name='plugin01')) self._add_plugin( create_plugin(self.plugindir, template='python', bundle='test', name='plugin02')) self._add_plugin( create_plugin(self.plugindir, template='python', bundle='test', name='plugin03')) self.run_command('list -r {0}'.format(self.gitrepodir)) self.assertResults( result_with_hint( u''' Installed plugins Plugin name Bundle name plugin01................. test plugin02................. test plugin03................. test ''', USE_RUNNOW), self.output)
def test_lists_alphabetically(self): """ Will list bundles and plugin names alphabetically. """ # Add these in reverse order of alphabetical self._add_plugin( create_plugin(self.plugindir, template='python', bundle='c', name='c')) self._add_plugin( create_plugin(self.plugindir, template='python', bundle='b', name='b')) self._add_plugin( create_plugin(self.plugindir, template='python', bundle='a', name='a')) self.run_command('list -r {0}'.format(self.gitrepodir)) self.assertResults( result_with_hint( u''' Installed plugins Plugin name Bundle name a........................ a b........................ b c........................ c ''', USE_RUNNOW), self.output)
def test_lists_alphabetically(self): """ Will list bundles and plugin names alphabetically. """ # Add these in reverse order of alphabetical self._add_plugin(create_plugin( self.plugindir, template='python', bundle='c', name='c')) self._add_plugin(create_plugin( self.plugindir, template='python', bundle='b', name='b')) self._add_plugin(create_plugin( self.plugindir, template='python', bundle='a', name='a')) self.run_command('list -r {0}'.format(self.gitrepodir)) self.assertResults(result_with_hint(u''' Installed plugins Plugin name Bundle name a........................ a b........................ b c........................ c ''', USE_RUNNOW), self.output)
def test_update_results(self): """ If we have two plugins that are updated. """ plugins_dir = join(self.gitrepodir, '.jig', 'plugins') fake_cloned_plugin = join(plugins_dir, 'abcdef1234567890') makedirs(fake_cloned_plugin) create_plugin(fake_cloned_plugin, bundle='a', name='a') create_plugin(fake_cloned_plugin, bundle='b', name='b') with patch.object(Git, 'execute'): # Fake the git pull command mock_execute = Git.execute Git.execute.return_value = (0, 'Already up to date.', '') results = update_plugins(self.gitrepodir) pm, value = results.items()[0] # We have our two plugins from the manager self.assertEquals(2, len(pm.plugins)) # And it called ``git pull`` on the repository mock_execute.assert_called_once_with( ['git', 'pull'], with_extended_output=True)
def test_missing_directory(self): """ Will not try to create a plugin in a missing directory. """ # Remove this so the create_plugin function has nowhere to go. rmdir(self.plugindir) with self.assertRaises(ValueError): create_plugin( self.plugindir, template='python', bundle='test', name='plugin')
def test_update_existing_plugins(self): """ Can update an existing plugin. """ # Make our remote repository so we have something to pull from origin_repo = mkdtemp() root_commit_dir = join(origin_repo, '01') makedirs(root_commit_dir) # Create a plugin in the repo create_plugin( root_commit_dir, template='python', bundle='a', name='a') create_plugin( root_commit_dir, template='python', bundle='b', name='b') # This is the directory we will clone ngd = NumberedDirectoriesToGit(origin_repo) dir_to_clone = ngd.repo.working_dir # This is a trick, we give it the dir_to_clone when asked to install it def clone_local(plugin, to_dir, branch): # Instead of jumping on the Internet to clone this, we will use the # local numbered directory repository we setup above. This will # allow our update to occur with a git pull and avoid network # traffic which is always faster for tests. clone(dir_to_clone, to_dir) # First thing is to install the the plugin with patch('jig.commands.base.clone') as c: c.side_effect = clone_local self.run_command( 'add --gitrepo {0} http://repo'.format( self.gitrepodir)) self.run_command( 'update --gitrepo {0}'.format( self.gitrepodir)) self.assertResults( """ Updating plugins Plugin a, b in bundle a, b Already up-to-date.""", self.output)
def test_plugin_defaults_to_cwd(self): """ Running the plugins tests defaults to the current working directory. """ plugin_dir = create_plugin(mkdtemp(), template='python', bundle='bundle', name='name') expectation = Expectation((1, 2), None, u'aaa') results = [ SuccessResult(actual=u'aaa', expectation=expectation, plugin=MockPlugin()) ] with patch('jig.commands.plugin.PluginTestRunner') as ptr: ptr.return_value = Mock() ptr.return_value.run = Mock(return_value=results) with cwd_bounce(plugin_dir): self.run_command('test') self.assertResults( u''' 01 – 02 Pass Pass 1, Fail 0''', self.output)
def test_list_missing_settings_on_plugin(self): """ If the installed plugin is missing settings. """ self._add_plugin( create_plugin(self.plugindir, template='python', bundle='test01', name='plugin01')) plugin_config_filename = join(self.plugindir, 'plugin01', 'config.cfg') with open(plugin_config_filename, 'r') as fh: config = SafeConfigParser() config.readfp(fh) # What if this plugin has no settings whatsoever, perhaps the plugin # author just didn't have any and did not include that section config.remove_section('settings') with open(plugin_config_filename, 'w') as fh: config.write(fh) self.run_command('list -r {0}'.format(self.gitrepodir)) self.assertResults( result_with_hint( u''' Installed plugins have no settings. ''', CHANGE_PLUGIN_SETTINGS), self.output)
def test_config_no_help_but_defaults(self): """ If the plugin has no help only the default is available. """ self._add_plugin( create_plugin( self.plugindir, template="python", bundle="test01", name="plugin01", settings={"a": "1", "b": "2", "c": "3"}, ) ) self.run_command("about -r {0}".format(self.gitrepodir)) self.assertResults( u""" test01.plugin01.a (default: 1) test01.plugin01.b (default: 2) test01.plugin01.c (default: 3) """, self.output, )
def test_formats_results_verbose(self): """ Will return test results with stdin and stdout. """ plugin_dir = create_plugin( mkdtemp(), template='python', bundle='bundle', name='name') expectation = Expectation((1, 2), None, u'aaa') results = [ SuccessResult( actual=u'aaa', expectation=expectation, plugin=MockPlugin(), stdin='a\n', stdout='b\n')] with patch('jig.commands.plugin.PluginTestRunner') as ptr: ptr.return_value = Mock() ptr.return_value.run = Mock(return_value=results) self.run_command('test -v {0}'.format(plugin_dir)) self.assertResults( u''' 01 – 02 Pass stdin (sent to the plugin) a stdout (received from the plugin) b {0} Pass 1, Fail 0'''.format(REPORTER_HORIZONTAL_DIVIDER), self.output)
def test_specific_range(self): """ Will run only a specific range of tests. """ plugin_dir = create_plugin(self.plugindir, 'bundle', 'plugin') self.add_timeline(plugin_dir, [('a.txt', 'a\n')]) self.add_timeline(plugin_dir, [('a.txt', 'aa\n')]) self.add_expectation(plugin_dir, u''' .. expectation:: :from: 01 :to: 02 ▾ plugin ✓ line 1: a.txt a is - ✓ line 1: a.txt aa is +''') ptr = PluginTestRunner(plugin_dir) # An expectation exists for the following range self.assertEqual( 1, len(ptr.run(test_range=[(1, 2)]))) # An expectation does not exist for this one self.assertEqual( 0, len(ptr.run(test_range=[(2, 3)])))
def test_add_plugin(self): """ Adds a valid plugin. """ plugin_dir = create_plugin(self.plugindir, template='python', bundle='a', name='a') # We are going to test whether it defaults --gitrepo to cwd self.run_command('add {0}'.format(plugin_dir)) config = get_jigconfig(self.gitrepodir) # The config now contains our section self.assertTrue(config.has_section('plugin:a:a')) self.assertResults( u''' Added plugin a in bundle a to the repository. Run the plugins in the current repository with this command: $ jig runnow Jig works off of your staged files in the Git repository index. You place things in the index with `git add`. You will need to stage some files before you can run Jig.''', self.output)
def create(self, argv): """ Create a new plugin. """ name = argv.name bundle = argv.bundle template = argv.template save_dir = argv.dir with self.out() as out: if template not in available_templates(): raise CommandError( 'Language {0} is not supported yet.'.format(template), hint=FORK_PROJECT_GITHUB) try: plugin_dir = create_plugin( save_dir, bundle, name, template=template) out.append('Created plugin as {0}'.format(plugin_dir)) except OSError as ose: if ose.errno == errno.EEXIST: # File exists raise CommandError( 'A plugin with this name already ' 'exists in this directory: {0}.'.format(save_dir)) # Something else, raise it again raise ose # pragma: no cover
def test_non_zero_exit_code(self): """ If the exit code is non-zero, gets stderr instead. """ plugin_dir = create_plugin(self.plugindir, 'bundle', 'plugin') self.add_timeline(plugin_dir, [('a.txt', 'a\n')]) self.add_timeline(plugin_dir, [('a.txt', 'aa\n')]) self.add_expectation(plugin_dir, u''' .. expectation:: :from: 01 :to: 02 Output''') ptr = PluginTestRunner(plugin_dir) with patch.object(Plugin, 'pre_commit'): Plugin.pre_commit.return_value = (1, '', 'Error') results = ptr.run() self.assertResults(u''' Exit code: 1 Std out: (none) Std err: Error''', results[0].actual)
def test_non_json_stdout(self): """ Still processes if the plugin returns something other than JSON data. """ plugin_dir = create_plugin(self.plugindir, 'bundle', 'plugin') self.add_timeline(plugin_dir, [('a.txt', 'a\n')]) self.add_timeline(plugin_dir, [('a.txt', 'aa\n')]) self.add_expectation(plugin_dir, u''' .. expectation:: :from: 01 :to: 02 Output''') ptr = PluginTestRunner(plugin_dir) with patch.object(Plugin, 'pre_commit'): Plugin.pre_commit.return_value = (0, 'Non-JSON', '') results = ptr.run() self.assertResults(u''' ▾ plugin ✓ Non-JSON''', results[0].actual)
def test_can_change_settings(self): """ Altering the settings will be used correctly. """ plugin_dir = create_plugin( self.plugindir, 'bundle', 'plugin', settings={'verbose': 'yes'}) self.add_timeline(plugin_dir, [('a.txt', 'a\n')]) self.add_timeline(plugin_dir, [('a.txt', 'aa\n')]) self.add_expectation(plugin_dir, u''' .. plugin-settings:: verbose = no .. expectation:: :from: 01 :to: 02 ▾ plugin ✓ a.txt File has been modified''') ptr = PluginTestRunner(plugin_dir) results = ptr.run() self.assertIsInstance(results[0], SuccessResult)
def test_specific_range(self): """ Will run only a specific range of tests. """ plugin_dir = create_plugin(self.plugindir, 'bundle', 'plugin') self.add_timeline(plugin_dir, [('a.txt', 'a\n')]) self.add_timeline(plugin_dir, [('a.txt', 'aa\n')]) self.add_expectation( plugin_dir, u''' .. expectation:: :from: 01 :to: 02 ▾ plugin ✓ line 1: a.txt a is - ✓ line 1: a.txt aa is +''') ptr = PluginTestRunner(plugin_dir) # An expectation exists for the following range self.assertEqual(1, len(ptr.run(test_range=[(1, 2)]))) # An expectation does not exist for this one self.assertEqual(0, len(ptr.run(test_range=[(2, 3)])))
def test_success_result(self): """ Will run the tests and detect a success result. """ plugin_dir = create_plugin(self.plugindir, 'bundle', 'plugin') self.add_timeline(plugin_dir, [('a.txt', 'a\n')]) self.add_timeline(plugin_dir, [('a.txt', 'aa\n')]) self.add_expectation( plugin_dir, u''' .. expectation:: :from: 01 :to: 02 ▾ plugin ✓ line 1: a.txt a is - ✓ line 1: a.txt aa is +''') ptr = PluginTestRunner(plugin_dir) results = ptr.run() self.assertEqual(1, len(results)) self.assertIsInstance(results[0], SuccessResult) self.assertEqual(results[0].actual.strip(), results[0].expectation.output.strip()) self.assertEqual((1, 2), results[0].expectation.range)
def test_non_zero_exit_code(self): """ If the exit code is non-zero, gets stderr instead. """ plugin_dir = create_plugin(self.plugindir, 'bundle', 'plugin') self.add_timeline(plugin_dir, [('a.txt', 'a\n')]) self.add_timeline(plugin_dir, [('a.txt', 'aa\n')]) self.add_expectation( plugin_dir, u''' .. expectation:: :from: 01 :to: 02 Output''') ptr = PluginTestRunner(plugin_dir) with patch.object(Plugin, 'pre_commit'): Plugin.pre_commit.return_value = (1, '', 'Error') results = ptr.run() self.assertResults( u''' Exit code: 1 Std out: (none) Std err: Error''', results[0].actual)
def test_success_result(self): """ Will run the tests and detect a success result. """ plugin_dir = create_plugin(self.plugindir, 'bundle', 'plugin') self.add_timeline(plugin_dir, [('a.txt', 'a\n')]) self.add_timeline(plugin_dir, [('a.txt', 'aa\n')]) self.add_expectation(plugin_dir, u''' .. expectation:: :from: 01 :to: 02 ▾ plugin ✓ line 1: a.txt a is - ✓ line 1: a.txt aa is +''') ptr = PluginTestRunner(plugin_dir) results = ptr.run() self.assertEqual(1, len(results)) self.assertIsInstance(results[0], SuccessResult) self.assertEqual( results[0].actual.strip(), results[0].expectation.output.strip()) self.assertEqual((1, 2), results[0].expectation.range)
def test_formats_results(self): """ Will return test results. """ plugin_dir = create_plugin( mkdtemp(), template='python', bundle='bundle', name='name') expectation = Expectation((1, 2), None, u'aaa') results = [ SuccessResult( actual=u'aaa', expectation=expectation, plugin=MockPlugin())] with patch('jig.commands.plugin.PluginTestRunner') as ptr: ptr.return_value = Mock() ptr.return_value.run = Mock(return_value=results) self.run_command('test {0}'.format(plugin_dir)) self.assertResults( u''' 01 – 02 Pass Pass 1, Fail 0''', self.output)
def test_non_json_stdout(self): """ Still processes if the plugin returns something other than JSON data. """ plugin_dir = create_plugin(self.plugindir, 'bundle', 'plugin') self.add_timeline(plugin_dir, [('a.txt', 'a\n')]) self.add_timeline(plugin_dir, [('a.txt', 'aa\n')]) self.add_expectation( plugin_dir, u''' .. expectation:: :from: 01 :to: 02 Output''') ptr = PluginTestRunner(plugin_dir) with patch.object(Plugin, 'pre_commit'): Plugin.pre_commit.return_value = (0, 'Non-JSON', '') results = ptr.run() self.assertResults( u''' ▾ plugin ✓ Non-JSON''', results[0].actual)
def test_plugin_defaults_to_cwd(self): """ Running the plugins tests defaults to the current working directory. """ plugin_dir = create_plugin( mkdtemp(), template='python', bundle='bundle', name='name') expectation = Expectation((1, 2), None, u'aaa') results = [ SuccessResult( actual=u'aaa', expectation=expectation, plugin=MockPlugin())] with patch('jig.commands.plugin.PluginTestRunner') as ptr: ptr.return_value = Mock() ptr.return_value.run = Mock(return_value=results) with cwd_bounce(plugin_dir): self.run_command('test') self.assertResults( u''' 01 – 02 Pass Pass 1, Fail 0''', self.output)
def test_can_change_settings(self): """ Altering the settings will be used correctly. """ plugin_dir = create_plugin(self.plugindir, 'bundle', 'plugin', settings={'verbose': 'yes'}) self.add_timeline(plugin_dir, [('a.txt', 'a\n')]) self.add_timeline(plugin_dir, [('a.txt', 'aa\n')]) self.add_expectation( plugin_dir, u''' .. plugin-settings:: verbose = no .. expectation:: :from: 01 :to: 02 ▾ plugin ✓ a.txt File has been modified''') ptr = PluginTestRunner(plugin_dir) results = ptr.run() self.assertIsInstance(results[0], SuccessResult)
def test_config_help(self): """ Help is available for each installed plugin setting that supports it. """ self._add_plugin( create_plugin( self.plugindir, template="python", bundle="test01", name="plugin01", settings={"a": "1", "b": "2", "c": "3"}, ) ) # Make a about message for the ``a`` setting self._plugin_about(join(self.plugindir, "plugin01"), {"a": "turn a on"}) self.run_command("about -r {0}".format(self.gitrepodir)) self.assertResults( u""" test01.plugin01.a (default: 1) turn a on test01.plugin01.b (default: 2) test01.plugin01.c (default: 3) """, self.output, )
def test_formats_results(self): """ Will return test results. """ plugin_dir = create_plugin(mkdtemp(), template='python', bundle='bundle', name='name') expectation = Expectation((1, 2), None, u'aaa') results = [ SuccessResult(actual=u'aaa', expectation=expectation, plugin=MockPlugin()) ] with patch('jig.commands.plugin.PluginTestRunner') as ptr: ptr.return_value = Mock() ptr.return_value.run = Mock(return_value=results) self.run_command('test {0}'.format(plugin_dir)) self.assertResults( u''' 01 – 02 Pass Pass 1, Fail 0''', self.output)
def test_list_plugins_one_overridden_config(self): """ Lists settings if there is one overridden setting. """ self._add_plugin( create_plugin(self.plugindir, template='python', bundle='test01', name='plugin01', settings={ 'a': '1', 'b': '2', 'c': '3' })) self._clear_settings(self.gitrepodir) # Override the setting for this plugin, it should take the place of the # default which is '1' self._set(self.gitrepodir, 'test01', 'plugin01', 'a', 'one') self.run_command('list -r {0}'.format(self.gitrepodir)) self.assertResults( result_with_hint( u''' test01.plugin01.a=one test01.plugin01.b=2 test01.plugin01.c=3 ''', CHANGE_PLUGIN_SETTINGS), self.output)
def test_add_plugin(self): """ Adds a valid plugin. """ plugin_dir = create_plugin( self.plugindir, template='python', bundle='a', name='a') # We are going to test whether it defaults --gitrepo to cwd self.run_command('add {0}'.format(plugin_dir)) config = get_jigconfig(self.gitrepodir) # The config now contains our section self.assertTrue(config.has_section('plugin:a:a')) self.assertResults( u''' Added plugin a in bundle a to the repository. Run the plugins in the current repository with this command: $ jig runnow Jig works off of your staged files in the Git repository index. You place things in the index with `git add`. You will need to stage some files before you can run Jig.''', self.output)
def test_list_plugins_no_overridden_config(self): """ Lists settings if there are no overridden configs. The default plugin settings will not be in plugins.cfg. """ self._add_plugin( create_plugin( self.plugindir, template="python", bundle="test01", name="plugin01", settings={"a": "1", "b": "2", "c": "3"}, ) ) self._clear_settings(self.gitrepodir) self.run_command("list -r {0}".format(self.gitrepodir)) self.assertResults( result_with_hint( u""" test01.plugin01.a=1 test01.plugin01.b=2 test01.plugin01.c=3 """, CHANGE_PLUGIN_SETTINGS, ), self.output, )
def test_list_plugins_no_overridden_config(self): """ Lists settings if there are no overridden configs. The default plugin settings will not be in plugins.cfg. """ self._add_plugin( create_plugin(self.plugindir, template='python', bundle='test01', name='plugin01', settings={ 'a': '1', 'b': '2', 'c': '3' })) self._clear_settings(self.gitrepodir) self.run_command('list -r {0}'.format(self.gitrepodir)) self.assertResults( result_with_hint( u''' test01.plugin01.a=1 test01.plugin01.b=2 test01.plugin01.c=3 ''', CHANGE_PLUGIN_SETTINGS), self.output)
def test_list_plugins_one_overridden_config(self): """ Lists settings if there is one overridden setting. """ self._add_plugin( create_plugin( self.plugindir, template="python", bundle="test01", name="plugin01", settings={"a": "1", "b": "2", "c": "3"}, ) ) self._clear_settings(self.gitrepodir) # Override the setting for this plugin, it should take the place of the # default which is '1' self._set(self.gitrepodir, "test01", "plugin01", "a", "one") self.run_command("list -r {0}".format(self.gitrepodir)) self.assertResults( result_with_hint( u""" test01.plugin01.a=one test01.plugin01.b=2 test01.plugin01.c=3 """, CHANGE_PLUGIN_SETTINGS, ), self.output, )
def test_config_help(self): """ Help is available for each installed plugin setting that supports it. """ self._add_plugin( create_plugin(self.plugindir, template='python', bundle='test01', name='plugin01', settings={ 'a': '1', 'b': '2', 'c': '3' })) # Make a about message for the ``a`` setting self._plugin_about(join(self.plugindir, 'plugin01'), {'a': 'turn a on'}) self.run_command('about -r {0}'.format(self.gitrepodir)) self.assertResults( u''' test01.plugin01.a (default: 1) turn a on test01.plugin01.b (default: 2) test01.plugin01.c (default: 3) ''', self.output)
def test_config_no_help_but_defaults(self): """ If the plugin has no help only the default is available. """ self._add_plugin( create_plugin(self.plugindir, template='python', bundle='test01', name='plugin01', settings={ 'a': '1', 'b': '2', 'c': '3' })) self.run_command('about -r {0}'.format(self.gitrepodir)) self.assertResults( u''' test01.plugin01.a (default: 1) test01.plugin01.b (default: 2) test01.plugin01.c (default: 3) ''', self.output)
def test_list_missing_settings_on_plugin(self): """ If the installed plugin is missing settings. """ self._add_plugin(create_plugin(self.plugindir, template="python", bundle="test01", name="plugin01")) plugin_config_filename = join(self.plugindir, "plugin01", "config.cfg") with open(plugin_config_filename, "r") as fh: config = SafeConfigParser() config.readfp(fh) # What if this plugin has no settings whatsoever, perhaps the plugin # author just didn't have any and did not include that section config.remove_section("settings") with open(plugin_config_filename, "w") as fh: config.write(fh) self.run_command("list -r {0}".format(self.gitrepodir)) self.assertResults( result_with_hint( u""" Installed plugins have no settings. """, CHANGE_PLUGIN_SETTINGS, ), self.output, )
def test_config_set(self): """ Setting can be changed. """ self._add_plugin( create_plugin(self.plugindir, template='python', bundle='test01', name='plugin01', settings={ 'a': '1', 'b': '2', 'c': '3' })) self.run_command('set -r {0} test01.plugin01.a 111'.format( self.gitrepodir)) # Setting was changed, no output to the console self.assertEqual('', self.output) # The setting was changed config = get_jigconfig(self.gitrepodir) self.assertEqual('111', config.get('plugin:test01:plugin01', 'a'))
def test_config_no_help(self): """ If the plugin has no settings, no about messages. """ self._add_plugin(create_plugin(self.plugindir, template="python", bundle="test01", name="plugin01")) self.run_command("about -r {0}".format(self.gitrepodir)) self.assertResults(u"Installed plugins have no settings.", self.output)
def test_multiple_expectations(self): """ Multiple tests can be ran. """ plugin_dir = create_plugin( self.plugindir, 'bundle', 'plugin', settings={'verbose': 'no'}) self.add_timeline( plugin_dir, [('src/a.txt', 'a\n')]) self.add_timeline( plugin_dir, [('src/a.txt', 'aa\n')]) self.add_timeline( plugin_dir, [('src/a.txt', 'aaa\n')]) self.add_timeline( plugin_dir, [ ('src/a.txt', 'aaa\n'), ('src/b.txt', 'bbb\n')]) self.add_expectation( plugin_dir, u''' .. expectation:: :from: 01 :to: 02 ▾ plugin ✓ src/a.txt File has been modified .. expectation:: :from: 02 :to: 03 ▾ plugin ✓ src/a.txt File has been modified .. expectation:: :from: 03 :to: 04 ▾ plugin ✓ src/b.txt File has been modified''') ptr = PluginTestRunner(plugin_dir) results = ptr.run() success = [isinstance(i, SuccessResult) for i in results] self.assertTrue(all(success))
def test_no_tests_to_run(self): """ Plugin has no tests to run. """ plugin_dir = create_plugin(self.plugindir, 'bundle', 'plugin') # Since our newly created plugin has no tests, this should be empty with self.assertRaises(ExpectationNoTests) as ec: PluginTestRunner(plugin_dir) self.assertIn('Could not find any tests', str(ec.exception))
def test_config_set_plugin_not_found(self): """ Setting cannot be changed because plugin is not installed. """ self._add_plugin(create_plugin(self.plugindir, template="python", bundle="test01", name="plugin01")) # plugin01 is installed but not the following with self.assertRaises(ForcedExit): self.run_command("set -r {0} notbundle.notplugin.a 111".format(self.gitrepodir)) self.assertResults(u"Could not locate plugin notplugin.", self.error)
def test_list_settings(self): """ List settings from freshly installed plugins. The default plugin config and the plugins.cfg will be in sync. """ self._add_plugin( create_plugin( self.plugindir, template="python", bundle="test01", name="plugin01", settings={"a": "1", "b": "2", "c": "3"}, ) ) self._add_plugin( create_plugin( self.plugindir, template="python", bundle="test02", name="plugin02", settings={"a": "11", "b": "22", "c": "33"}, ) ) self.run_command("list -r {0}".format(self.gitrepodir)) self.assertResults( result_with_hint( u""" test01.plugin01.a=1 test01.plugin01.b=2 test01.plugin01.c=3 test02.plugin02.a=11 test02.plugin02.b=22 test02.plugin02.c=33 """, CHANGE_PLUGIN_SETTINGS, ), self.output, )
def test_update_existing_plugins(self): """ Can update an existing plugin. """ # Make our remote repository so we have something to pull from origin_repo = mkdtemp() root_commit_dir = join(origin_repo, '01') makedirs(root_commit_dir) # Create a plugin in the repo create_plugin(root_commit_dir, template='python', bundle='a', name='a') create_plugin(root_commit_dir, template='python', bundle='b', name='b') # This is the directory we will clone ngd = NumberedDirectoriesToGit(origin_repo) dir_to_clone = ngd.repo.working_dir # This is a trick, we give it the dir_to_clone when asked to install it def clone_local(plugin, to_dir, branch): # Instead of jumping on the Internet to clone this, we will use the # local numbered directory repository we setup above. This will # allow our update to occur with a git pull and avoid network # traffic which is always faster for tests. clone(dir_to_clone, to_dir) # First thing is to install the the plugin with patch('jig.commands.base.clone') as c: c.side_effect = clone_local self.run_command('add --gitrepo {0} http://repo'.format( self.gitrepodir)) self.run_command('update --gitrepo {0}'.format(self.gitrepodir)) self.assertResults( """ Updating plugins Plugin a, b in bundle a, b Already up-to-date.""", self.output)
def test_plugin_tests_none_found(self): """ Run tests for a plugin where no tests are found. """ plugin_dir = create_plugin( mkdtemp(), template='python', bundle='bundle', name='name') with self.assertRaises(ForcedExit): self.run_command('test {0}'.format(plugin_dir)) self.assertIn('Could not find any tests:', self.error) self.assertIn('{0}/tests'.format(plugin_dir), self.error)
def test_config_no_help(self): """ If the plugin has no settings, no about messages. """ self._add_plugin( create_plugin(self.plugindir, template='python', bundle='test01', name='plugin01')) self.run_command('about -r {0}'.format(self.gitrepodir)) self.assertResults(u'Installed plugins have no settings.', self.output)
def test_list_settings(self): """ List settings from freshly installed plugins. The default plugin config and the plugins.cfg will be in sync. """ self._add_plugin( create_plugin(self.plugindir, template='python', bundle='test01', name='plugin01', settings={ 'a': '1', 'b': '2', 'c': '3' })) self._add_plugin( create_plugin(self.plugindir, template='python', bundle='test02', name='plugin02', settings={ 'a': '11', 'b': '22', 'c': '33' })) self.run_command('list -r {0}'.format(self.gitrepodir)) self.assertResults( result_with_hint( u''' test01.plugin01.a=1 test01.plugin01.b=2 test01.plugin01.c=3 test02.plugin02.a=11 test02.plugin02.b=22 test02.plugin02.c=33 ''', CHANGE_PLUGIN_SETTINGS), self.output)
def test_multiple_expectations(self): """ Multiple tests can be ran. """ plugin_dir = create_plugin(self.plugindir, 'bundle', 'plugin', settings={'verbose': 'no'}) self.add_timeline(plugin_dir, [('src/a.txt', 'a\n')]) self.add_timeline(plugin_dir, [('src/a.txt', 'aa\n')]) self.add_timeline(plugin_dir, [('src/a.txt', 'aaa\n')]) self.add_timeline(plugin_dir, [('src/a.txt', 'aaa\n'), ('src/b.txt', 'bbb\n')]) self.add_expectation( plugin_dir, u''' .. expectation:: :from: 01 :to: 02 ▾ plugin ✓ src/a.txt File has been modified .. expectation:: :from: 02 :to: 03 ▾ plugin ✓ src/a.txt File has been modified .. expectation:: :from: 03 :to: 04 ▾ plugin ✓ src/b.txt File has been modified''') ptr = PluginTestRunner(plugin_dir) results = ptr.run() success = [isinstance(i, SuccessResult) for i in results] self.assertTrue(all(success))
def test_plugin_tests_none_found(self): """ Run tests for a plugin where no tests are found. """ plugin_dir = create_plugin(mkdtemp(), template='python', bundle='bundle', name='name') with self.assertRaises(ForcedExit): self.run_command('test {0}'.format(plugin_dir)) self.assertIn('Could not find any tests:', self.error) self.assertIn('{0}/tests'.format(plugin_dir), self.error)
def test_no_expectations(self): """ We have a test timeline without any expectations. """ plugin_dir = create_plugin(self.plugindir, 'bundle', 'plugin') self.add_timeline(plugin_dir, [('a.txt', 'a\n')]) self.add_timeline(plugin_dir, [('a.txt', 'aa\n')]) # Since our newly created plugin has no tests, this should be empty with self.assertRaises(ExpectationFileNotFound) as ec: PluginTestRunner(plugin_dir) self.assertIn('Missing expectation file', str(ec.exception))
def test_new_plugin_compat_plugin_manager(self): """ New plugins are compatible with the :py:class:`PluginManager` """ plugin_dir = create_plugin( self.plugindir, template='python', bundle='test', name='plugin') pm = PluginManager(self.jigconfig) pm.add(plugin_dir) self.assertEqual(1, len(pm.plugins)) self.assertEqual('plugin', pm.plugins[0].name)
def test_remove_plugin_guesses_bundle(self): """ Removes an installed plugin. """ plugin_dir = create_plugin(self.plugindir, template='python', bundle='bundle', name='name') self.run_command('add -r {0} {1}'.format(self.gitrepodir, plugin_dir)) # Leave the bundle name off so it can be guessed. self.run_command('remove name') self.assertEqual(u'Removed plugin name\n', self.output)
def test_runs_specific_test(self): """ Will run a specific test. """ plugin_dir = create_plugin( mkdtemp(), template='python', bundle='bundle', name='name') with patch('jig.commands.plugin.PluginTestRunner') as ptr: ptr.return_value = Mock() ptr.return_value.run = Mock(return_value=[]) self.run_command('test -r 4..5 {0}'.format(plugin_dir)) ptr.return_value.run.assert_called_with(test_range=[(4, 5)])
def test_list_plugins_same_bundle(self): """ Lists plugins correctly if they are in the same bundle. """ self._add_plugin(create_plugin( self.plugindir, template='python', bundle='test', name='plugin01')) self._add_plugin(create_plugin( self.plugindir, template='python', bundle='test', name='plugin02')) self._add_plugin(create_plugin( self.plugindir, template='python', bundle='test', name='plugin03')) self.run_command('list -r {0}'.format(self.gitrepodir)) self.assertResults(result_with_hint(u''' Installed plugins Plugin name Bundle name plugin01................. test plugin02................. test plugin03................. test ''', USE_RUNNOW), self.output)
def test_config_set_plugin_not_found(self): """ Setting cannot be changed because plugin is not installed. """ self._add_plugin( create_plugin(self.plugindir, template='python', bundle='test01', name='plugin01')) # plugin01 is installed but not the following with self.assertRaises(ForcedExit): self.run_command('set -r {0} notbundle.notplugin.a 111'.format( self.gitrepodir)) self.assertResults(u'Could not locate plugin notplugin.', self.error)