def test_config_options_should_be_properly_quoted(self): command_pattern = 'jshint ${options} /path/to/file.js' config = { 'config': '.jshint rc' } task = CheckerTask('dummy-taskname', command_pattern, config) task.command_options = { 'config': '--config ${value}' } task() expected_command = "jshint --config '.jshint rc' /path/to/file.js" self.assert_shell_command_executed(expected_command)
def test_option_is_not_passed_to_command_if_its_config_option_is_none2(self): command_pattern = 'command ${options}' config = { 'opt': None } task = CheckerTask('dummy', command_pattern, config) task.command_options = { 'opt': '--opt1 ${value}' } task() expected_command = 'command' self.assert_shell_command_executed(expected_command)
def test_replace_options_placeholder_with_checker_options2(self): command_pattern = 'jshint ${options} /path/to/file.js' config = { 'config': '.jshintrc' } task = CheckerTask('dummy-taskname', command_pattern, config) task.command_options = { 'config': '--config ${value}' } task() expected_command = 'jshint --config .jshintrc /path/to/file.js' self.assert_shell_command_executed(expected_command)
def test_empty_string_is_valid_command_option(self): command_pattern = 'command ${options}' config = { 'config': '' } task = CheckerTask('dummy', command_pattern, config) task.command_options = { 'config': '--config ${value}' } task() expected_command = "command --config ''" self.assert_shell_command_executed(expected_command)
def test_replace_options_placeholder_with_checker_options(self): """Pylint accepts pylintrc option.""" command_pattern = 'pylint -f parseable /path/to/module.py ${options}' config = { 'rcfile': 'pylintrc' } task = CheckerTask('dummy-taskname', command_pattern, config) task.command_options = { 'rcfile': '--rcfile=${value}' } task() expected_command = 'pylint -f parseable /path/to/module.py ' \ '--rcfile=pylintrc' self.assert_shell_command_executed(expected_command)
def test_command_options_can_be_passed_directly_to_command_pattern(self): command_pattern = 'command ${opt1} ${opt2}' config = { 'opt1': 'val1', 'opt2': 'val2' } task = CheckerTask('dummy', command_pattern, config) task.command_options = { 'opt1': '--opt1 ${value}', 'opt2': '${value}' } task() expected_command = 'command --opt1 val1 val2' self.assert_shell_command_executed(expected_command)
def create(self, relpath=None, config=None): """Create Task for specified file.""" config = self._mix_config(config) if relpath: abspath = git.abspath(relpath) command = self._command.safe_substitute(file_abspath=abspath) taskname = self._taskname.substitute(file_relpath=relpath) else: taskname = self._taskname.template command = self._command.template task = Task(taskname, command, config) if self._command_options: task.command_options = self._command_options if self._result_creator: task.result_creator = self._result_creator return task