コード例 #1
0
ファイル: test_runnow.py プロジェクト: robmadole/jig
    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
ファイル: test_runnow.py プロジェクト: robmadole/jig
    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
ファイル: test_runner.py プロジェクト: dmore/jig
    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
ファイル: test_runnow.py プロジェクト: robmadole/jig
    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
ファイル: install.py プロジェクト: robmadole/jig
    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
ファイル: test_runner.py プロジェクト: dmore/jig
    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
ファイル: plugin.py プロジェクト: robmadole/jig
    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
ファイル: test_runner.py プロジェクト: dmore/jig
    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
ファイル: test_runner.py プロジェクト: dmore/jig
    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
ファイル: test_runner.py プロジェクト: dmore/jig
    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
ファイル: test_runner.py プロジェクト: dmore/jig
    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
ファイル: test_runner.py プロジェクト: dmore/jig
    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
ファイル: test_runner.py プロジェクト: robmadole/jig
    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
ファイル: test_runnow.py プロジェクト: robmadole/jig
    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
ファイル: test_runner.py プロジェクト: robmadole/jig
    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
ファイル: test_tools.py プロジェクト: robmadole/jig
 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
ファイル: config.py プロジェクト: dmore/jig
    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
ファイル: config.py プロジェクト: robmadole/jig
    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
ファイル: test_config.py プロジェクト: robmadole/jig
 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
ファイル: test_config.py プロジェクト: robmadole/jig
 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
ファイル: test_report.py プロジェクト: dmore/jig
    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
ファイル: test_config.py プロジェクト: robmadole/jig
    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
ファイル: test_report.py プロジェクト: robmadole/jig
    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
ファイル: test_tools.py プロジェクト: robmadole/jig
    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
ファイル: test_tools.py プロジェクト: robmadole/jig
    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
ファイル: test_tools.py プロジェクト: robmadole/jig
    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
ファイル: test_config.py プロジェクト: robmadole/jig
    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
ファイル: test_runner.py プロジェクト: robmadole/jig
    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
ファイル: test_tools.py プロジェクト: robmadole/jig
    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
ファイル: test_runner.py プロジェクト: robmadole/jig
    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
ファイル: test_runner.py プロジェクト: dmore/jig
    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
ファイル: test_runner.py プロジェクト: dmore/jig
    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
ファイル: test_runner.py プロジェクト: robmadole/jig
    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
ファイル: test_tools.py プロジェクト: robmadole/jig
    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
ファイル: test_config.py プロジェクト: robmadole/jig
    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
ファイル: test_runnow.py プロジェクト: robmadole/jig
    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
ファイル: test_config.py プロジェクト: robmadole/jig
    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
ファイル: test_runner.py プロジェクト: dmore/jig
    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
ファイル: test_runner.py プロジェクト: robmadole/jig
    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
ファイル: test_runner.py プロジェクト: robmadole/jig
    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
ファイル: test_runnow.py プロジェクト: robmadole/jig
    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
ファイル: test_runnow.py プロジェクト: robmadole/jig
    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
ファイル: test_runner.py プロジェクト: robmadole/jig
    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
ファイル: test_runner.py プロジェクト: robmadole/jig
    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
ファイル: test_runner.py プロジェクト: robmadole/jig
    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
ファイル: test_runner.py プロジェクト: robmadole/jig
    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
ファイル: test_runner.py プロジェクト: robmadole/jig
    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
ファイル: test_runner.py プロジェクト: dmore/jig
    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
ファイル: test_runnow.py プロジェクト: robmadole/jig
    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
ファイル: plugin.py プロジェクト: dmore/jig
    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
ファイル: test_runner.py プロジェクト: robmadole/jig
    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
ファイル: test_runner.py プロジェクト: dmore/jig
    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
ファイル: test_runner.py プロジェクト: dmore/jig
    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)