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_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_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_plugins_installed(self): """ If no plugins installed, about output mentions installing plugins. """ self.run_command("about -r {0}".format(self.gitrepodir)) self.assertResults(result_with_hint(u"No plugins installed.", NO_PLUGINS_INSTALLED), self.output)
def test_list_no_plugins(self): """ No plugins are installed and the list is empty. """ # Without the path argument, this should default to the current working # directory. self.run_command("list") self.assertResults(result_with_hint(u"No plugins installed.", NO_PLUGINS_INSTALLED), self.output)
def test_handles_error(self): """ An un-initialized jig Git repository provides an error message. """ with self.assertRaises(ForcedExit): self.run_command(mkdtemp()) self.assertResults( result_with_hint(u"This repository has not been initialized.", GIT_REPO_NOT_INITIALIZED), self.error )
def test_list_no_plugins(self): """ No plugins are installed and the list is empty. """ # Without the path argument, this should default to the current working # directory. self.run_command('list') self.assertResults( result_with_hint(u'No plugins installed.', NO_PLUGINS_INSTALLED), self.output)
def test_create_with_bad_language(self): """ Cannot create a plugin if the language is unavailable """ with self.assertRaises(ForcedExit): # We just created a plugin in this directory, so it should fail self.run_command('create -l php name bundle') self.assertResults( result_with_hint(u'Language php is not supported yet.', FORK_PROJECT_GITHUB), self.error)
def test_initialize_repo(self): """ We inititialize a repository with jig. """ self.run_command(self.gitrepodir) self.assertResults( result_with_hint( u'Git repository has been initialized for use with Jig.', AFTER_INIT), self.output)
def test_initialize_current_directory(self): """ Defaults to the current directory and initializes. """ # Leave the directory argument off, which should make the command # use the current working directory. self.run_command() self.assertResults( result_with_hint( u'Git repository has been initialized for use with Jig.', AFTER_INIT), self.output)
def test_create_with_bad_language(self): """ Cannot create a plugin if the language is unavailable """ with self.assertRaises(ForcedExit): # We just created a plugin in this directory, so it should fail self.run_command('create -l php name bundle') self.assertResults( result_with_hint( u'Language php is not supported yet.', FORK_PROJECT_GITHUB), self.error)
def test_uninitialized_repo(self): """ The .jig directory has not been initialized. """ # Remove the .jig directory, effectively un-initializing our repository rmtree(join(self.gitrepodir, '.jig')) with self.assertRaises(ForcedExit) as ec: self.runner.results(self.gitrepodir) self.assertEqual('1', str(ec.exception)) self.assertResults( result_with_hint(u'This repository has not been initialized.', GIT_REPO_NOT_INITIALIZED), self.error)
def test_hook_runs(self): """ New hook will run. """ pc_filename = hook(self.gitrepodir) retcode, output = self.runcmd(pc_filename) self.assertEqual(1, retcode) self.assertResults( result_with_hint( u'This repository has not been initialized.', GIT_REPO_NOT_INITIALIZED), output)
def test_home_templates_exist(self): """ A templates directory already exists in ~/.jig/git """ self.mocks['create_auto_init_templates'].side_effect = \ GitHomeTemplatesExists('~/.jig/git/templates') with self.assertRaises(ForcedExit): self.run_command() self.assertResults( result_with_hint( u'~/.jig/git/templates already exists', GIT_HOME_TEMPLATES_EXISTS), self.error)
def test_install_local_plugin(self): """ Can install a single local file system plugin. """ # Create a file to store the location of plugins to install self.commit(self.gitrepodir, 'jigplugins.txt', self.plugin01_dir) self.run_command('jigplugins.txt') self.assertResults( result_with_hint( dedent(u''' From {0}: - Added plugin plugin01 in bundle test01 '''.format(self.plugin01_dir)), USE_RUNNOW), self.output)
def test_templates_missing(self): """ No Git templates can be found. """ self.mocks['create_auto_init_templates'].side_effect = \ GitTemplatesMissing() with self.assertRaises(ForcedExit): self.run_command() self.assertResults( result_with_hint( u'Unable to find templates.', GIT_TEMPLATES_MISSING), self.error)
def test_init_templatesdir_already_set(self): """ Git is already configured with a init.templatedir """ self.mocks['set_templates_directory'].side_effect = \ InitTemplateDirAlreadySet('/tmp/templates') with self.assertRaises(ForcedExit): self.run_command() self.assertResults( result_with_hint( u'Git configuration for init.templatedir is /tmp/templates', INIT_TEMPLATE_DIR_ALREADY_SET), self.error)
def test_handles_range_error(self): """ If an improper range is given, provides a helpful error message. """ plugin_dir = create_plugin(mkdtemp(), template='python', bundle='bundle', name='name') with self.assertRaises(ForcedExit): # Bad range "a.b" self.run_command('test -r a.b {0}'.format(plugin_dir)) self.assertResults( result_with_hint(u'a.b is an invalid numbered test range', INVALID_RANGE), self.error)
def test_uninitialized_repo(self): """ The .jig directory has not been initialized. """ # Remove the .jig directory, effectively un-initializing our repository rmtree(join(self.gitrepodir, '.jig')) with self.assertRaises(ForcedExit) as ec: self.runner.results(self.gitrepodir) self.assertEqual('1', str(ec.exception)) self.assertResults( result_with_hint( u'This repository has not been initialized.', GIT_REPO_NOT_INITIALIZED), self.error)
def test_handles_range_error(self): """ If an improper range is given, provides a helpful error message. """ plugin_dir = create_plugin( mkdtemp(), template='python', bundle='bundle', name='name') with self.assertRaises(ForcedExit): # Bad range "a.b" self.run_command('test -r a.b {0}'.format(plugin_dir)) self.assertResults( result_with_hint( u'a.b is an invalid numbered test range', INVALID_RANGE), self.error)
def test_skips_duplicates(self): """ If a duplicate is being installed, skips it. """ self.commit(self.gitrepodir, 'jigplugins.txt', '{0}\n{0}\n'.format(self.plugin01_dir)) self.run_command('jigplugins.txt') self.assertResults( result_with_hint( dedent(u''' From {0}: - Added plugin plugin01 in bundle test01 From {0}: - The plugin is already installed. '''.format(self.plugin01_dir)), USE_RUNNOW), self.output)
def test_config_invalid_key(self): """ Invalid keys are handled. """ self._add_plugin(create_plugin(self.plugindir, template="python", bundle="test01", name="plugin01")) with self.assertRaises(ForcedExit): self.run_command("set -r {0} a:b:c 111".format(self.gitrepodir)) self.assertResults( result_with_hint( u""" a:b:c is an invalid config key. """, INVALID_CONFIG_KEY, ), self.error, )
def test_config_invalid_key(self): """ Invalid keys are handled. """ self._add_plugin( create_plugin(self.plugindir, template='python', bundle='test01', name='plugin01')) with self.assertRaises(ForcedExit): self.run_command('set -r {0} a:b:c 111'.format(self.gitrepodir)) self.assertResults( result_with_hint( u''' a:b:c is an invalid config key. ''', INVALID_CONFIG_KEY), self.error)
def test_install_local_plugin(self): """ Can install a single local file system plugin. """ # Create a file to store the location of plugins to install self.commit( self.gitrepodir, 'jigplugins.txt', self.plugin01_dir) self.run_command('jigplugins.txt') self.assertResults( result_with_hint(dedent( u''' From {0}: - Added plugin plugin01 in bundle test01 '''.format(self.plugin01_dir)), USE_RUNNOW), self.output)
def test_skips_duplicates(self): """ If a duplicate is being installed, skips it. """ self.commit( self.gitrepodir, 'jigplugins.txt', '{0}\n{0}\n'.format(self.plugin01_dir)) self.run_command('jigplugins.txt') self.assertResults( result_with_hint(dedent( u''' From {0}: - Added plugin plugin01 in bundle test01 From {0}: - The plugin is already installed. '''.format(self.plugin01_dir)), USE_RUNNOW), 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_plugins_has_one_error(self): """ The specified exists but the first location is a bad plugin. Confirms that the install continues even if an error is found. """ self.commit(self.gitrepodir, 'jigplugins.txt', '{0}\n{1}\n'.format(self.plugin02_dir, self.plugin01_dir)) self.run_command('jigplugins.txt') self.assertResults( result_with_hint( dedent(u''' From {0}: - File contains parsing errors: {0}/config.cfg \t[line 2]: 'This is a bad config file that will fail to parse\\n' From {1}: - Added plugin plugin01 in bundle test01 '''.format(self.plugin02_dir, self.plugin01_dir)), USE_RUNNOW), 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_plugins_has_one_error(self): """ The specified exists but the first location is a bad plugin. Confirms that the install continues even if an error is found. """ self.commit( self.gitrepodir, 'jigplugins.txt', '{0}\n{1}\n'.format( self.plugin02_dir, self.plugin01_dir)) self.run_command('jigplugins.txt') self.assertResults(result_with_hint(dedent( u''' From {0}: - File contains parsing errors: {0}/config.cfg \t[line 2]: 'This is a bad config file that will fail to parse\\n' From {1}: - Added plugin plugin01 in bundle test01 '''.format(self.plugin02_dir, self.plugin01_dir)), USE_RUNNOW), self.output)
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)