Example #1
0
 def test_error_missing_expected_value(self):
     with pytest.raises(ArgumentPreprocessingError):
         preprocess_options(['--foo', '--bar', '--qu=ux'],
                            {'bar': (None, True)})
     with pytest.raises(ArgumentPreprocessingError):
         preprocess_options(['--foo', '--bar'],
                            {'bar': (None, True)})
Example #2
0
 def test_value_equal(self):
     self.args = []
     preprocess_options(['--foo', '--bar=baz', '--qu=ux'],
                        {'foo' : (self._callback, False),
                         'qu' : (self._callback, True)})
     self.assertEqual(
         [('foo', None), ('qu', 'ux')], self.args)
Example #3
0
 def test_value_equal(self):
     self.args = []
     preprocess_options(
         ["--foo", "--bar=baz", "--qu=ux"],
         {"foo": (self._callback, False), "qu": (self._callback, True)},
     )
     assert [("foo", None), ("qu", "ux")] == self.args
Example #4
0
        def __init__(self, args, reporter=None):
            self._rcfile = None
            self._plugins = []
            preprocess_options(
                args,
                {
                    # option: (callback, takearg)
                    "rcfile": (self.cb_set_rcfile, True),
                    "load-plugins": (self.cb_add_plugins, True),
                },
            )
            self.linter = linter = self.LinterClass(
                (
                    (
                        "rcfile",
                        {
                            "action": "callback",
                            "callback": lambda *args: 1,
                            "type": "string",
                            "metavar": "<file>",
                            "help": "Specify a configuration file.",
                        },
                    ),
                    (
                        "init-hook",
                        {
                            "action": "callback",
                            "type": "string",
                            "metavar": "<code>",
                            "callback": cb_init_hook,
                            "help": "Python code to execute, usually for sys.path \
    manipulation such as pygtk.require().",
                        },
                    ),
                    (
                        "help-msg",
                        {
                            "action": "callback",
                            "type": "string",
                            "metavar": "<msg-id>",
                            "callback": self.cb_help_message,
                            "group": "Commands",
                            "help": """Display a help message for the given message id and \
    exit. The value may be a comma separated list of message ids.""",
                        },
                    ),
                    (
                        "list-msgs",
                        {
                            "action": "callback",
                            "metavar": "<msg-id>",
                            "callback": self.cb_list_messages,
                            "group": "Commands",
                            "help": "Generate pylint's full documentation.",
                        },
                    ),
                    (
                        "generate-rcfile",
                        {
                            "action": "callback",
                            "callback": self.cb_generate_config,
                            "group": "Commands",
                            "help": """Generate a sample configuration file according to \
    the current configuration. You can put other options before this one to get \
    them in the generated configuration.""",
                        },
                    ),
                    (
                        "generate-man",
                        {
                            "action": "callback",
                            "callback": self.cb_generate_manpage,
                            "group": "Commands",
                            "help": "Generate pylint's man page.",
                            "hide": "True",
                        },
                    ),
                    (
                        "errors-only",
                        {
                            "action": "callback",
                            "callback": self.cb_error_mode,
                            "short": "e",
                            "help": """In error mode, checkers without error messages are \
    disabled and for others, only the ERROR messages are displayed, and no reports \
    are done by default""",
                        },
                    ),
                    ("profile", {"type": "yn", "metavar": "<y_or_n>", "default": False, "help": "Profiled execution."}),
                ),
                option_groups=self.option_groups,
                reporter=reporter,
                pylintrc=self._rcfile,
            )
            # register standard checkers
            checkers.initialize(linter)
            # load command line plugins
            linter.load_plugin_modules(self._plugins)
            # read configuration
            linter.disable_message("W0704")
            linter.read_config_file()
            # is there some additional plugins in the file configuration, in
            config_parser = linter._config_parser
            if config_parser.has_option("MASTER", "load-plugins"):
                plugins = splitstrip(config_parser.get("MASTER", "load-plugins"))
                linter.load_plugin_modules(plugins)
            # now we can load file config and command line, plugins (which can
            # provide options) have been registered
            linter.load_config_file()
            if reporter:
                # if a custom reporter is provided as argument, it may be overriden
                # by file parameters, so re-set it here, but before command line
                # parsing so it's still overrideable by command line option
                linter.set_reporter(reporter)
            args = linter.load_command_line_configuration(args)
            # insert current working directory to the python path to have a correct
            # behaviour
            sys.path.insert(0, os.getcwd())
            if self.linter.config.profile:
                print >> sys.stderr, "** profiled run"
                from hotshot import Profile, stats

                prof = Profile("stones.prof")
                prof.runcall(linter.check, args)
                prof.close()
                data = stats.load("stones.prof")
                data.strip_dirs()
                data.sort_stats("time", "calls")
                data.print_stats(30)
            sys.path.pop(0)
Example #5
0
 def test_error_unexpected_value(self):
     with pytest.raises(ArgumentPreprocessingError):
         preprocess_options(['--foo', '--bar=spam', '--qu=ux'],
                            {'bar': (None, False)})
Example #6
0
 def test_value_space(self):
     self.args = []
     preprocess_options(["--qu", "ux"], {"qu": (self._callback, True)})
     assert [("qu", "ux")] == self.args
Example #7
0
 def test_value_space(self):
     self.args = []
     preprocess_options(['--qu', 'ux'], {'qu': (self._callback, True)})
     self.assertEqual([('qu', 'ux')], self.args)
Example #8
0
 def test_error_unexpected_value(self):
     with pytest.raises(ArgumentPreprocessingError):
         preprocess_options(['--foo', '--bar=spam', '--qu=ux'],
                            {'bar': (None, False)})
Example #9
0
 def test_value_space(self):
     self.args = []
     preprocess_options(["--qu", "ux"], {"qu": (self._callback, True)})
     assert [("qu", "ux")] == self.args
Example #10
0
 def test_error_unexpected_value(self):
     with pytest.raises(ArgumentPreprocessingError):
         preprocess_options(
             ["--foo", "--bar=spam", "--qu=ux"], {"bar": (None, False)}
         )
Example #11
0
 def test_error_missing_expected_value(self):
     with pytest.raises(ArgumentPreprocessingError):
         preprocess_options(["--foo", "--bar", "--qu=ux"], {"bar": (None, True)})
     with pytest.raises(ArgumentPreprocessingError):
         preprocess_options(["--foo", "--bar"], {"bar": (None, True)})
Example #12
0
 def test_error_missing_expected_value(self):
     with pytest.raises(ArgumentPreprocessingError):
         preprocess_options(['--foo', '--bar', '--qu=ux'],
                            {'bar': (None, True)})
     with pytest.raises(ArgumentPreprocessingError):
         preprocess_options(['--foo', '--bar'], {'bar': (None, True)})
Example #13
0
        def __init__(self, args, reporter=None):
            self._rcfile = None
            self._plugins = []
            preprocess_options(args, {
                # option: (callback, takearg)
                'rcfile':       (self.cb_set_rcfile, True),
                'load-plugins': (self.cb_add_plugins, True),
                })
            self.linter = linter = self.LinterClass((
                ('rcfile',
                 {'action' : 'callback', 'callback' : lambda *args: 1,
                  'type': 'string', 'metavar': '<file>',
                  'help' : 'Specify a configuration file.'}),

                ('init-hook',
                 {'action' : 'callback', 'type' : 'string', 'metavar': '<code>',
                  'callback' : cb_init_hook,
                  'help' : 'Python code to execute, usually for sys.path \
    manipulation such as pygtk.require().'}),

                ('help-msg',
                 {'action' : 'callback', 'type' : 'string', 'metavar': '<msg-id>',
                  'callback' : self.cb_help_message,
                  'group': 'Commands',
                  'help' : '''Display a help message for the given message id and \
    exit. The value may be a comma separated list of message ids.'''}),

                ('list-msgs',
                 {'action' : 'callback', 'metavar': '<msg-id>',
                  'callback' : self.cb_list_messages,
                  'group': 'Commands',
                  'help' : "Generate pylint's full documentation."}),

                ('generate-rcfile',
                 {'action' : 'callback', 'callback' : self.cb_generate_config,
                  'group': 'Commands',
                  'help' : '''Generate a sample configuration file according to \
    the current configuration. You can put other options before this one to get \
    them in the generated configuration.'''}),

                ('generate-man',
                 {'action' : 'callback', 'callback' : self.cb_generate_manpage,
                  'group': 'Commands',
                  'help' : "Generate pylint's man page.",'hide': 'True'}),

                ('errors-only',
                 {'action' : 'callback', 'callback' : self.cb_error_mode,
                  'short': 'e',
                  'help' : '''In error mode, checkers without error messages are \
    disabled and for others, only the ERROR messages are displayed, and no reports \
    are done by default'''}),

                ('profile',
                 {'type' : 'yn', 'metavar' : '<y_or_n>',
                  'default': False,
                  'help' : 'Profiled execution.'}),

                ), option_groups=self.option_groups,
                   reporter=reporter, pylintrc=self._rcfile)
            # register standard checkers
            checkers.initialize(linter)
            # load command line plugins
            linter.load_plugin_modules(self._plugins)
            # read configuration
            linter.disable_message('W0704')
            linter.read_config_file()
            # is there some additional plugins in the file configuration, in
            config_parser = linter._config_parser
            if config_parser.has_option('MASTER', 'load-plugins'):
                plugins = splitstrip(config_parser.get('MASTER', 'load-plugins'))
                linter.load_plugin_modules(plugins)
            # now we can load file config and command line, plugins (which can
            # provide options) have been registered
            linter.load_config_file()
            if reporter:
                # if a custom reporter is provided as argument, it may be overriden
                # by file parameters, so re-set it here, but before command line
                # parsing so it's still overrideable by command line option
                linter.set_reporter(reporter)
            args = linter.load_command_line_configuration(args)
            # insert current working directory to the python path to have a correct
            # behaviour
            sys.path.insert(0, os.getcwd())
            if self.linter.config.profile:
                print >> sys.stderr, '** profiled run'
                from hotshot import Profile, stats
                prof = Profile('stones.prof')
                prof.runcall(linter.check, args)
                prof.close()
                data = stats.load('stones.prof')
                data.strip_dirs()
                data.sort_stats('time', 'calls')
                data.print_stats(30)
            sys.path.pop(0)
Example #14
0
     def __init__(self, args, reporter=None):
         self._rcfile = None
         self._plugins = []
         preprocess_options(
             args,
             {
                 # option: (callback, takearg)
                 'rcfile': (self.cb_set_rcfile, True),
                 'load-plugins': (self.cb_add_plugins, True),
             })
         self.linter = linter = self.LinterClass((
             ('rcfile', {
                 'action': 'callback',
                 'callback': lambda *args: 1,
                 'type': 'string',
                 'metavar': '<file>',
                 'help': 'Specify a configuration file.'
             }),
             ('init-hook', {
                 'action':
                 'callback',
                 'type':
                 'string',
                 'metavar':
                 '<code>',
                 'callback':
                 cb_init_hook,
                 'help':
                 'Python code to execute, usually for sys.path \
 manipulation such as pygtk.require().'
             }),
             ('help-msg', {
                 'action':
                 'callback',
                 'type':
                 'string',
                 'metavar':
                 '<msg-id>',
                 'callback':
                 self.cb_help_message,
                 'group':
                 'Commands',
                 'help':
                 '''Display a help message for the given message id and \
 exit. The value may be a comma separated list of message ids.'''
             }),
             ('list-msgs', {
                 'action': 'callback',
                 'metavar': '<msg-id>',
                 'callback': self.cb_list_messages,
                 'group': 'Commands',
                 'help': "Generate pylint's full documentation."
             }),
             ('generate-rcfile', {
                 'action':
                 'callback',
                 'callback':
                 self.cb_generate_config,
                 'group':
                 'Commands',
                 'help':
                 '''Generate a sample configuration file according to \
 the current configuration. You can put other options before this one to get \
 them in the generated configuration.'''
             }),
             ('generate-man', {
                 'action': 'callback',
                 'callback': self.cb_generate_manpage,
                 'group': 'Commands',
                 'help': "Generate pylint's man page.",
                 'hide': 'True'
             }),
             ('errors-only', {
                 'action':
                 'callback',
                 'callback':
                 self.cb_error_mode,
                 'short':
                 'e',
                 'help':
                 '''In error mode, checkers without error messages are \
 disabled and for others, only the ERROR messages are displayed, and no reports \
 are done by default'''
             }),
             ('profile', {
                 'type': 'yn',
                 'metavar': '<y_or_n>',
                 'default': False,
                 'help': 'Profiled execution.'
             }),
         ),
                                                 option_groups=self.
                                                 option_groups,
                                                 reporter=reporter,
                                                 pylintrc=self._rcfile)
         # register standard checkers
         checkers.initialize(linter)
         # load command line plugins
         linter.load_plugin_modules(self._plugins)
         # read configuration
         linter.disable_message('W0704')
         linter.read_config_file()
         # is there some additional plugins in the file configuration, in
         config_parser = linter._config_parser
         if config_parser.has_option('MASTER', 'load-plugins'):
             plugins = splitstrip(
                 config_parser.get('MASTER', 'load-plugins'))
             linter.load_plugin_modules(plugins)
         # now we can load file config and command line, plugins (which can
         # provide options) have been registered
         linter.load_config_file()
         if reporter:
             # if a custom reporter is provided as argument, it may be overriden
             # by file parameters, so re-set it here, but before command line
             # parsing so it's still overrideable by command line option
             linter.set_reporter(reporter)
         args = linter.load_command_line_configuration(args)
         # insert current working directory to the python path to have a correct
         # behaviour
         sys.path.insert(0, os.getcwd())
         if self.linter.config.profile:
             print('** profiled run', file=sys.stderr)
             from hotshot import Profile, stats
             prof = Profile('stones.prof')
             prof.runcall(linter.check, args)
             prof.close()
             data = stats.load('stones.prof')
             data.strip_dirs()
             data.sort_stats('time', 'calls')
             data.print_stats(30)
         sys.path.pop(0)
Example #15
0
 def test_error_unexpected_value(self):
     with pytest.raises(ArgumentPreprocessingError):
         preprocess_options(
             ["--foo", "--bar=spam", "--qu=ux"], {"bar": (None, False)}
         )
Example #16
0
 def test_error_missing_expected_value(self):
     with pytest.raises(ArgumentPreprocessingError):
         preprocess_options(["--foo", "--bar", "--qu=ux"], {"bar": (None, True)})
     with pytest.raises(ArgumentPreprocessingError):
         preprocess_options(["--foo", "--bar"], {"bar": (None, True)})
Example #17
0
 def test_value_space(self):
     self.args = []
     preprocess_options(['--qu', 'ux'],
                        {'qu' : (self._callback, True)})
     self.assertEqual(
         [('qu', 'ux')], self.args)
Example #18
0
 def test_value_equal(self):
     self.args = []
     preprocess_options(['--foo', '--bar=baz', '--qu=ux'],
                        {'foo': (self._callback, False),
                         'qu': (self._callback, True)})
     assert [('foo', None), ('qu', 'ux')] == self.args