Пример #1
0
    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,
        )
Пример #2
0
    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,
        )
Пример #3
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)
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
    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)
Пример #7
0
    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))
Пример #8
0
    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)
Пример #9
0
    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')))
Пример #10
0
    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)
Пример #11
0
    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)
Пример #12
0
    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)
Пример #13
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)
Пример #14
0
    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)
Пример #15
0
    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)
Пример #16
0
 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)
Пример #17
0
    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)
Пример #18
0
    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)
Пример #19
0
 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)
Пример #20
0
 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)
Пример #21
0
    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')
Пример #22
0
    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)
Пример #23
0
    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')
Пример #24
0
    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)
Пример #25
0
    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)
Пример #26
0
    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)
Пример #27
0
    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)
Пример #28
0
    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)
Пример #29
0
    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)
Пример #30
0
    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)
Пример #31
0
    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)
Пример #32
0
    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)
Пример #33
0
    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)
Пример #34
0
    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)
Пример #35
0
    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)
Пример #36
0
    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)
Пример #37
0
    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)
Пример #38
0
    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)
Пример #39
0
    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)
Пример #40
0
    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)
Пример #41
0
    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)
Пример #42
0
    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)
Пример #43
0
    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')))
Пример #44
0
    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)
Пример #45
0
    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)
Пример #46
0
    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)
Пример #47
0
    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)
Пример #48
0
    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)
Пример #49
0
    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)
Пример #50
0
    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)
Пример #51
0
    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)
Пример #52
0
    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)
Пример #53
0
    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)