def test_range_filter_when_start_line_is_not_positive( local_command: LocalCommandBuilder) -> None: local_command.start_line = 0 with pytest.raises(Exception): output = run_in_subprocess(local_command.build()) json.loads(output) local_command.start_line = -1 with pytest.raises(Exception): output = run_in_subprocess(local_command.build()) json.loads(output)
def inspect(self, path: Path, config: Dict[str, Any]) -> List[BaseIssue]: with new_temp_dir() as temp_dir: output_path = temp_dir / 'output.xml' command = self._create_command(path, output_path) run_in_subprocess(command) issues = parse_xml_file_result(output_path, self.inspector_type, self.choose_issue_type, IssueDifficulty.get_by_issue_type, self.origin_class_to_pattern, {}) output_path.unlink() return issues
def inspect(self, path: Path, config: Dict[str, Any]) -> List[BaseIssue]: if not (check_set_up_env_variable(DETEKT_DIRECTORY_ENV) and check_set_up_env_variable(DETEKT_VERSION_ENV)): return [] with new_temp_dir() as temp_dir: output_path = temp_dir / 'output.xml' command = self._create_command(path, output_path) run_in_subprocess(command) return parse_xml_file_result(output_path, self.inspector_type, self.choose_issue_type, IssueDifficulty.get_by_issue_type, self.origin_class_to_pattern, {})
def test_range_filter_when_start_line_is_not_first( local_command: LocalCommandBuilder) -> None: local_command.path = PATH_TO_FILE local_command.format = 'json' local_command.start_line = 3 output = run_in_subprocess(local_command.build()) output_json = json.loads(output) expected_json_with_one_issue = { 'quality': { 'code': 'MODERATE', 'text': 'Code quality (beta): MODERATE' }, 'issues': [ { 'code': 'E225', 'text': 'missing whitespace around operator', 'line': 'c=a + b', 'line_number': 4, 'column_number': 2, 'category': 'CODE_STYLE', 'influence_on_penalty': 0, 'difficulty': "EASY", }, ], } assert output_json == expected_json_with_one_issue
def test_range_filter_when_no_range_specified( local_command: LocalCommandBuilder) -> None: local_command.path = PATH_TO_FILE local_command.format = 'json' output = run_in_subprocess(local_command.build()) output_json = json.loads(output) assert output_json == EXPECTED_JSON
def test_range_filter_when_start_line_is_first( local_command: LocalCommandBuilder) -> None: local_command.path = PATH_TO_FILE local_command.format = 'json' local_command.start_line = 1 output = run_in_subprocess(local_command.build()) output_json = json.loads(output) assert output_json == EXPECTED_JSON
def test_range_filter_when_end_line_out_of_range( local_command: LocalCommandBuilder) -> None: local_command.path = PATH_TO_FILE local_command.format = 'json' local_command.end_line = 10 output = run_in_subprocess(local_command.build()) output_json = json.loads(output) assert output_json == output_json
def test_range_filter_when_end_line_is_last( local_command: LocalCommandBuilder) -> None: local_command.path = PATH_TO_FILE local_command.format = 'json' local_command.end_line = 4 # last line with an error output = run_in_subprocess(local_command.build()) output_json = json.loads(output) assert output_json == EXPECTED_JSON
def inspect(self, path: Path, config: Dict[str, Any]) -> List[BaseIssue]: if not (check_set_up_env_variable(PMD_DIRECTORY_ENV) and check_set_up_env_variable(PMD_VERSION_ENV)): return [] with new_temp_dir() as temp_dir: output_path = Path(temp_dir / 'out.csv') language_version = config.get('language_version') if language_version is None: logger.info( f"The version of Java is not passed. The version to be used is: {DEFAULT_JAVA_VERSION.value}.", ) language_version = DEFAULT_JAVA_VERSION command = self._create_command(path, output_path, language_version, config['n_cpu']) run_in_subprocess(command) return self.parse_output(output_path)
def test_range_filter_when_both_start_and_end_lines_out_of_range( local_command: LocalCommandBuilder) -> None: local_command.path = PATH_TO_FILE local_command.format = 'json' local_command.start_line = 10 local_command.end_line = 11 output = run_in_subprocess(local_command.build()) output_json = json.loads(output) assert output_json == NO_ISSUES_JSON
def test_range_filter_when_both_start_and_end_lines_specified( local_command: LocalCommandBuilder) -> None: local_command.path = PATH_TO_FILE local_command.format = 'json' local_command.start_line = 1 local_command.end_line = 5 output = run_in_subprocess(local_command.build()) output_json = json.loads(output) assert output_json == EXPECTED_JSON
def inspect(cls, path: Path, config: Dict[str, Any]) -> List[CodeIssue]: command = [ 'pylint', '--load-plugins', 'pylint_django', f'--rcfile={PATH_PYLINT_CONFIG}', f'--msg-template={MSG_TEMPLATE}', str(path), ] output = run_in_subprocess(command) return cls.parse(output)
def test_range_filter_when_start_out_of_range( local_command: LocalCommandBuilder) -> None: local_command.path = PATH_TO_FILE local_command.format = 'json' local_command.start_line = 5 output = run_in_subprocess(local_command.build()) output_json = json.loads(output) expected_json_without_issues = NO_ISSUES_JSON assert output_json == expected_json_without_issues
def inspect(cls, path: Path, config: Dict[str, Any]) -> List[BaseIssue]: mi_command = [ 'radon', 'mi', # compute the Maintainability Index score '--max', 'F', # set the maximum MI rank to display '--show', # actual MI value is shown in results, alongside the rank path, ] mi_output = run_in_subprocess(mi_command) return cls.mi_parse(mi_output)
def inspect(cls, path: Path, config: Dict[str, Any]) -> List[BaseIssue]: command = [ 'flake8', f'--format={FORMAT}', f'--config={PATH_FLAKE8_CONFIG}', f'--whitelist={PATH_FLAKE8_SPELLCHECK_WHITELIST}', '--max-complexity', '0', '--cohesion-below', '100', path, ] output = run_in_subprocess(command) return cls.parse(output)
def test_range_filter_when_both_start_and_end_lines_specified_not_equal_borders( local_command: LocalCommandBuilder, ) -> None: local_command.path = PATH_TO_FILE local_command.format = 'json' local_command.start_line = 2 local_command.end_line = 4 output = run_in_subprocess(local_command.build()) output_json = json.loads(output) expected_json = { 'quality': { 'code': 'BAD', 'text': 'Code quality (beta): BAD', }, 'issues': [ { 'code': 'E225', 'text': 'missing whitespace around operator', 'line': 'b=20', 'line_number': 2, 'column_number': 2, 'category': 'CODE_STYLE', 'influence_on_penalty': 0, 'difficulty': "EASY", }, { 'code': 'E225', 'text': 'missing whitespace around operator', 'line': 'c=a + b', 'line_number': 4, 'column_number': 2, 'category': 'CODE_STYLE', 'influence_on_penalty': 0, 'difficulty': "EASY", }, ], } assert output_json == expected_json