コード例 #1
0
ファイル: abstract_principle.py プロジェクト: roch1990/peon
    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,
        )
コード例 #2
0
    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)
コード例 #3
0
def test_constructor():
    assert Report(text='test', channel=ReportChannels.stdout).text == 'test'
コード例 #4
0
def test_text_has_wrong_type():
    assert Report(text=[], channel=ReportChannels.stdout).to_stdout() is False
コード例 #5
0
def test_text_is_filled():
    assert Report(text='test message',
                  channel=ReportChannels.stdout).to_stdout() is True
コード例 #6
0
def test_text_is_empty():
    assert Report(text='', channel=ReportChannels.stdout).to_stdout() is False
コード例 #7
0
def test_text_is_none():
    assert Report(text=None,
                  channel=ReportChannels.stdout).to_stdout() is False
コード例 #8
0
def test_text_is_filled_string():
    Report(text='test', channel=ReportChannels.file).to_file()
    assert ReportToFileFixture().content() == 'test'
    ReportToFileFixture().clean()
コード例 #9
0
def test_text_is_empty_string():
    Report(text='', channel=ReportChannels.file).to_file()
    with pytest.raises(FileNotFoundError):
        assert ReportToFileFixture().content()