def report(self, problem_map: dict): output = f'\nPrinciple: {self.principle_name}\n' for file, line_numbers in problem_map.items(): for line_number in line_numbers: output += f'{file}:{line_number}\n' output += f'More information: {self.link}' if not problem_map: return Report(text='', channel=self.output_channel) return Report( text=output, channel=self.output_channel, )
def project(self): reports = [] principles = Principle( files=self.files, output_channel=self.output_channel, ) # cleanup report file Report(text='', channel=self.output_channel).clean() reports.append(principles.no_null()) reports.append(principles.no_code_in_constructors()) reports.append(principles.no_getters_and_setters()) reports.append(principles.no_mutable_objects()) reports.append( principles.no_readers_parsers_or_controllers_or_sorters_and_so_on( )) reports.append( principles.no_static_methods_and_not_even_private_ones()) reports.append( principles.no_instanceof_or_type_casting_or_reflection()) reports.append( principles.no_statements_in_test_methods_except_assert()) reports.append(principles.no_inheritance()) code_with_vulnerabilities = False if reports: for report in reports: report_done = report.send() code_with_vulnerabilities = code_with_vulnerabilities or report_done # skip result exit_code if flag provided exit_code = 0 if self.result_independence else 1 if code_with_vulnerabilities: sys.exit(exit_code)
def test_constructor(): assert Report(text='test', channel=ReportChannels.stdout).text == 'test'
def test_text_has_wrong_type(): assert Report(text=[], channel=ReportChannels.stdout).to_stdout() is False
def test_text_is_filled(): assert Report(text='test message', channel=ReportChannels.stdout).to_stdout() is True
def test_text_is_empty(): assert Report(text='', channel=ReportChannels.stdout).to_stdout() is False
def test_text_is_none(): assert Report(text=None, channel=ReportChannels.stdout).to_stdout() is False
def test_text_is_filled_string(): Report(text='test', channel=ReportChannels.file).to_file() assert ReportToFileFixture().content() == 'test' ReportToFileFixture().clean()
def test_text_is_empty_string(): Report(text='', channel=ReportChannels.file).to_file() with pytest.raises(FileNotFoundError): assert ReportToFileFixture().content()