Esempio n. 1
0
 def test_print_results_missing_line(self):
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(""),
             [Result.from_values("t", "msg", file="file", line=5),
              Result.from_values("t", "msg", file="file", line=6)],
             {abspath("file"): ["line " + str(i + 1) for i in range(5)]},
             {},
             color=False)
         self.assertEqual("\n"
                          "file\n"
                          "|   5| {0}\n"
                          "|    | [NORMAL] t:\n"
                          "|    | {1}\n"
                          "\n"
                          "file\n"
                          "|   6| {2}\n"
                          "|    | [NORMAL] t:\n"
                          "|    | {1}\n".format(
                              highlight_text('line 5', self.lexer),
                              highlight_text("msg",
                                             style=BackgroundMessageStyle),
                              STR_LINE_DOESNT_EXIST),
                          stdout.getvalue())
Esempio n. 2
0
    def test_print_results_multiple_ranges(self):
        affected_code = (
            SourceRange.from_values('some_file', 5, end_line=7),
            SourceRange.from_values('another_file', 1, 3, 1, 5),
            SourceRange.from_values('another_file', 3, 3, 3, 5))
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(''),
                [Result('ClangCloneDetectionBear',
                        'Clone Found',
                        affected_code)],
                {abspath('some_file'): ['line ' + str(i + 1) + '\n'
                                        for i in range(10)],
                 abspath('another_file'): ['line ' + str(i + 1)
                                           for i in range(10)]},
                {},
                self.console_printer)
            self.assertEqual("""li{0}{1}
li{0}{2}

**** ClangCloneDetectionBear [Section: ] ****

!    ! [Severity: NORMAL]
!    ! {3}\n""".format(highlight_text(self.no_color, 'ne', self.lexer,
                                      BackgroundSourceRangeStyle),
                       highlight_text(self.no_color, ' 1', self.lexer),
                       highlight_text(self.no_color, ' 3', self.lexer),
                       highlight_text(self.no_color, 'Clone Found',
                                      style=BackgroundMessageStyle)),
                stdout.getvalue())
Esempio n. 3
0
    def test_print_results_sorting(self):
        with retrieve_stdout() as stdout:
            print_results(self.log_printer,
                          Section(""), [
                              Result.from_values("SpaceConsistencyBear",
                                                 "Trailing whitespace found",
                                                 file="file",
                                                 line=5),
                              Result.from_values("SpaceConsistencyBear",
                                                 "Trailing whitespace found",
                                                 file="file",
                                                 line=2)
                          ], {
                              abspath("file"): [
                                  "test line\n", "\t\n", "line 3\n",
                                  "line 4\n", "line 5\t\n"
                              ]
                          }, {},
                          color=False)

            self.assertEqual(
                """
file
|   2| {0}
|    | [NORMAL] SpaceConsistencyBear:
|    | {1}

file
|   5| {2}
|    | [NORMAL] SpaceConsistencyBear:
|    | {1}\n""".format(
                    highlight_text('\t', self.lexer),
                    highlight_text("Trailing whitespace found",
                                   style=BackgroundMessageStyle),
                    highlight_text('line 5\t', self.lexer)), stdout.getvalue())
Esempio n. 4
0
    def test_print_results_sorting(self):
        with retrieve_stdout() as stdout:
            print_results(self.log_printer,
                          Section(""),
                          [Result.from_values("SpaceConsistencyBear",
                                              "Trailing whitespace found",
                                              file="file",
                                              line=5),
                           Result.from_values("SpaceConsistencyBear",
                                              "Trailing whitespace found",
                                              file="file",
                                              line=2)],
                          {abspath("file"): ["test line\n",
                                             "\t\n",
                                             "line 3\n",
                                             "line 4\n",
                                             "line 5\t\n"]},
                          {},
                          color=False)

            self.assertEqual("""
file
|   2| {0}
|    | [NORMAL] SpaceConsistencyBear:
|    | {1}

file
|   5| {2}
|    | [NORMAL] SpaceConsistencyBear:
|    | {1}\n""".format(highlight_text('\t', self.lexer),
                       highlight_text("Trailing whitespace found",
                                      style=BackgroundMessageStyle),
                       highlight_text('line 5\t', self.lexer)),
                stdout.getvalue())
Esempio n. 5
0
    def test_print_results_sorting(self):
        with retrieve_stdout() as stdout:
            print_results(self.log_printer,
                          Section(''),
                          [Result.from_values('SpaceConsistencyBear',
                                              'Trailing whitespace found',
                                              file='file',
                                              line=5),
                           Result.from_values('SpaceConsistencyBear',
                                              'Trailing whitespace found',
                                              file='file',
                                              line=2)],
                          {abspath('file'): ['test line\n',
                                             '\t\n',
                                             'line 3\n',
                                             'line 4\n',
                                             'line 5\t\n']},
                          {},
                          self.console_printer)

            self.assertEqual("""
file
|   2| {0}
|    | [NORMAL] SpaceConsistencyBear:
|    | {1}

file
|   5| {2}
|    | [NORMAL] SpaceConsistencyBear:
|    | {1}\n""".format(highlight_text(self.no_color, '\t', self.lexer),
                       highlight_text(self.no_color,
                                      'Trailing whitespace found',
                                      style=BackgroundMessageStyle),
                       highlight_text(self.no_color, 'line 5\t', self.lexer)),
                stdout.getvalue())
Esempio n. 6
0
 def test_print_results_missing_line(self):
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(''),
             [Result.from_values('t', 'msg', file='file', line=5),
              Result.from_values('t', 'msg', file='file', line=6)],
             {abspath('file'): ['line ' + str(i + 1) for i in range(5)]},
             {},
             self.console_printer)
         self.assertEqual('\n'
                          'file\n'
                          '|   5| {0}\n'
                          '|    | [NORMAL] t:\n'
                          '|    | {1}\n'
                          '\n'
                          'file\n'
                          '|   6| {2}\n'
                          '|    | [NORMAL] t:\n'
                          '|    | {1}\n'.format(
                              highlight_text(self.no_color,
                                             'line 5', self.lexer),
                              highlight_text(self.no_color, 'msg',
                                             style=BackgroundMessageStyle),
                              STR_LINE_DOESNT_EXIST),
                          stdout.getvalue())
Esempio n. 7
0
    def test_print_results_for_file(self):
        with retrieve_stdout() as stdout:
            print_results(self.log_printer, Section(''), [
                Result.from_values('SpaceConsistencyBear',
                                   'Trailing whitespace found',
                                   file='filename',
                                   line=2)
            ], {abspath('filename'): ['test line\n', 'line 2\n', 'line 3\n']},
                          {}, self.console_printer)
            self.assertEqual(
                """
filename
[    ]2 {0}

**** SpaceConsistencyBear [Section: ] ****

!    ! [Severity: NORMAL]
!    ! {1}\n""".format(
                    highlight_text(self.no_color, 'line 2', self.lexer),
                    highlight_text(self.no_color,
                                   'Trailing whitespace found',
                                   style=BackgroundMessageStyle), ''),
                stdout.getvalue())

        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer, Section(''), [
                    Result.from_values('SpaceConsistencyBear',
                                       'Trailing whitespace found',
                                       file='filename',
                                       line=5)
                ], {
                    abspath('filename'): [
                        'test line\n', 'line 2\n', 'line 3\n', 'line 4\n',
                        'line 5\n'
                    ]
                }, {}, self.console_printer)
            self.assertEqual(
                """
filename
[    ]5 {0}

**** SpaceConsistencyBear [Section: ] ****

!    ! [Severity: NORMAL]
!    ! {1}\n""".format(
                    highlight_text(self.no_color, 'line 5', self.lexer),
                    highlight_text(self.no_color,
                                   'Trailing whitespace found',
                                   style=BackgroundMessageStyle), ''),
                stdout.getvalue())
    def test_print_results_for_file(self):
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(''),
                [Result.from_values('SpaceConsistencyBear',
                                    'Trailing whitespace found',
                                    file='filename',
                                    line=2)],
                {abspath('filename'): ['test line\n', 'line 2\n', 'line 3\n']},
                {},
                self.console_printer)
            self.assertEqual("""
filename
[   2] {0}
**** SpaceConsistencyBear [Section:  | Severity: NORMAL] ****
!    ! {1}\n""".format(highlight_text(self.no_color, 'line 2', NoColorStyle,
                                      self.lexer),
                       highlight_text(self.no_color,
                                      'Trailing whitespace found',
                                      style=BackgroundMessageStyle), ''),
                stdout.getvalue())

        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(''),
                [Result.from_values('SpaceConsistencyBear',
                                    'Trailing whitespace found',
                                    file='filename',
                                    line=5)],
                {abspath('filename'): ['test line\n',
                                       'line 2\n',
                                       'line 3\n',
                                       'line 4\n',
                                       'line 5\n']},
                {},
                self.console_printer)
            self.assertEqual("""
filename
[   5] {0}
**** SpaceConsistencyBear [Section:  | Severity: NORMAL] ****
!    ! {1}\n""".format(highlight_text(self.no_color, 'line 5', NoColorStyle,
                                      self.lexer),
                       highlight_text(self.no_color,
                                      'Trailing whitespace found',
                                      style=BackgroundMessageStyle), ''),
                stdout.getvalue())
Esempio n. 9
0
    def test_print_result_no_input(self):
        with make_temp() as testfile_path:
            file_dict = {testfile_path: ['1\n', '2\n', '3\n']}
            diff = Diff(file_dict[testfile_path])
            diff.delete_line(2)
            diff.change_line(3, '3\n', '3_changed\n')
            with simulate_console_inputs(1, 2, 3) as generator, \
                    retrieve_stdout() as stdout:
                ApplyPatchAction.is_applicable = staticmethod(
                    lambda *args: True)
                print_results_no_input(self.log_printer,
                                       Section('someSection'),
                                       [Result('origin', 'message', diffs={
                                           testfile_path: diff})],
                                       file_dict,
                                       self.file_diff_dict,
                                       self.console_printer)
                self.assertEqual(generator.last_input, -1)
                self.assertEqual(stdout.getvalue(),
                                 """
Project wide:

**** origin [Section: someSection] ****

!    ! [Severity: NORMAL]
!    ! {}\n""".format(highlight_text(self.no_color,
                                     'message', style=BackgroundMessageStyle)))
Esempio n. 10
0
    def test_print_results_for_file(self):
        with retrieve_stdout() as stdout:
            print_results(self.log_printer, Section(""), [
                Result.from_values("SpaceConsistencyBear",
                                   "Trailing whitespace found",
                                   file="filename",
                                   line=2)
            ], {abspath("filename"): ["test line\n", "line 2\n", "line 3\n"]},
                          {}, self.console_printer)
            self.assertEqual(
                """\nfilename
|   2| {}
|    | [NORMAL] SpaceConsistencyBear:
|    | {}\n""".format(
                    highlight_text(self.no_color, 'line 2', self.lexer),
                    highlight_text(self.no_color,
                                   "Trailing whitespace found",
                                   style=BackgroundMessageStyle)),
                stdout.getvalue())

        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer, Section(""), [
                    Result.from_values("SpaceConsistencyBear",
                                       "Trailing whitespace found",
                                       file="filename",
                                       line=5)
                ], {
                    abspath("filename"): [
                        "test line\n", "line 2\n", "line 3\n", "line 4\n",
                        "line 5\n"
                    ]
                }, {}, self.console_printer)
            self.assertEqual(
                """\nfilename
|   5| {}
|    | [NORMAL] SpaceConsistencyBear:
|    | {}\n""".format(
                    highlight_text(self.no_color, 'line 5', self.lexer),
                    highlight_text(self.no_color,
                                   "Trailing whitespace found",
                                   style=BackgroundMessageStyle)),
                stdout.getvalue())
Esempio n. 11
0
 def test_print_results_project_wide(self):
     with retrieve_stdout() as stdout:
         print_results(self.log_printer,
                       Section(""), [Result("origin", "message")], {}, {},
                       color=False)
         self.assertEqual(
             "\n{}\n|    | [NORMAL] origin:\n|    | {}\n".format(
                 STR_PROJECT_WIDE,
                 highlight_text("message", style=BackgroundMessageStyle)),
             stdout.getvalue())
Esempio n. 12
0
    def test_print_results_for_file(self):
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(""),
                [Result.from_values("SpaceConsistencyBear",
                                    "Trailing whitespace found",
                                    file="filename",
                                    line=2)],
                {abspath("filename"): ["test line\n", "line 2\n", "line 3\n"]},
                {},
                self.console_printer)
            self.assertEqual("""\nfilename
|   2| {}
|    | [NORMAL] SpaceConsistencyBear:
|    | {}\n""".format(highlight_text(self.no_color, 'line 2', self.lexer),
                      highlight_text(self.no_color, "Trailing whitespace found",
                                     style=BackgroundMessageStyle)),
                stdout.getvalue())

        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(""),
                [Result.from_values("SpaceConsistencyBear",
                                    "Trailing whitespace found",
                                    file="filename",
                                    line=5)],
                {abspath("filename"): ["test line\n",
                                       "line 2\n",
                                       "line 3\n",
                                       "line 4\n",
                                       "line 5\n"]},
                {},
                self.console_printer)
            self.assertEqual("""\nfilename
|   5| {}
|    | [NORMAL] SpaceConsistencyBear:
|    | {}\n""".format(highlight_text(self.no_color, 'line 5', self.lexer),
                      highlight_text(self.no_color, "Trailing whitespace found",
                                     style=BackgroundMessageStyle)),
                stdout.getvalue())
Esempio n. 13
0
 def test_print_results_project_wide(self):
     with retrieve_stdout() as stdout:
         print_results(self.log_printer, Section(''),
                       [Result('origin', 'message')], {}, {},
                       self.console_printer)
         self.assertEqual(
             '\n{}\n|    | [NORMAL] origin:\n|    | {}\n'.format(
                 STR_PROJECT_WIDE,
                 highlight_text(self.no_color,
                                'message',
                                style=BackgroundMessageStyle)),
             stdout.getvalue())
Esempio n. 14
0
 def test_print_results_project_wide(self):
     with retrieve_stdout() as stdout:
         print_results(self.log_printer,
                       Section(""),
                       [Result("origin", "message")],
                       {},
                       {},
                       color=False)
         self.assertEqual(
             "\n{}\n|    | [NORMAL] origin:\n|    | {}\n".format(
                 STR_PROJECT_WIDE,
                 highlight_text("message", style=BackgroundMessageStyle)),
             stdout.getvalue())
Esempio n. 15
0
 def test_print_results_without_line(self):
     with retrieve_stdout() as stdout:
         print_results(self.log_printer,
                       Section(""),
                       [Result.from_values("t", "msg", file="file")],
                       {abspath("file"): []}, {},
                       color=False)
         self.assertEqual(
             "\nfile\n"
             "|    | [NORMAL] t:\n"
             "|    | {}\n".format(
                 highlight_text("msg", style=BackgroundMessageStyle)),
             stdout.getvalue())
Esempio n. 16
0
 def test_print_results_without_line(self):
     with retrieve_stdout() as stdout:
         print_results(self.log_printer, Section(''),
                       [Result.from_values('t', 'msg', file='file')],
                       {abspath('file'): []}, {}, self.console_printer)
         self.assertEqual(
             '\nfile\n'
             '|    | [NORMAL] t:\n'
             '|    | {}\n'.format(
                 highlight_text(self.no_color,
                                'msg',
                                style=BackgroundMessageStyle)),
             stdout.getvalue())
Esempio n. 17
0
 def test_print_results_missing_line(self):
     with retrieve_stdout() as stdout:
         print_results(self.log_printer, Section(""), [
             Result.from_values("t", "msg", file="file", line=5),
             Result.from_values("t", "msg", file="file", line=6)
         ], {abspath("file"): ["line " + str(i + 1) for i in range(5)]}, {},
                       self.console_printer)
         self.assertEqual(
             "\n"
             "file\n"
             "|   5| {0}\n"
             "|    | [NORMAL] t:\n"
             "|    | {1}\n"
             "\n"
             "file\n"
             "|   6| {2}\n"
             "|    | [NORMAL] t:\n"
             "|    | {1}\n".format(
                 highlight_text(self.no_color, 'line 5', self.lexer),
                 highlight_text(self.no_color,
                                "msg",
                                style=BackgroundMessageStyle),
                 STR_LINE_DOESNT_EXIST), stdout.getvalue())
Esempio n. 18
0
 def test_print_results_project_wide(self):
     with retrieve_stdout() as stdout:
         print_results(self.log_printer,
                       Section(''),
                       [Result('origin', 'message')],
                       {},
                       {},
                       self.console_printer)
         self.assertEqual(
             '\n{}\n|    | [NORMAL] origin:\n|    | {}\n'.format(
                 STR_PROJECT_WIDE,
                 highlight_text(self.no_color,
                                'message', style=BackgroundMessageStyle)),
             stdout.getvalue())
Esempio n. 19
0
 def test_print_results_without_line(self):
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(""),
             [Result.from_values("t", "msg", file="file")],
             {abspath("file"): []},
             {},
             color=False)
         self.assertEqual(
             "\nfile\n"
             "|    | [NORMAL] t:\n"
             "|    | {}\n".format(highlight_text(
                 "msg", style=BackgroundMessageStyle)),
             stdout.getvalue())
Esempio n. 20
0
 def test_print_results_without_line(self):
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(''),
             [Result.from_values('t', 'msg', file='file')],
             {abspath('file'): []},
             {},
             self.console_printer)
         self.assertEqual(
             '\nfile\n'
             '|    | [NORMAL] t:\n'
             '|    | {}\n'.format(highlight_text(
                self.no_color, 'msg', style=BackgroundMessageStyle)),
             stdout.getvalue())
Esempio n. 21
0
 def test_print_results_missing_file(self):
     self.log_printer.log_level = logging.CRITICAL
     with retrieve_stdout() as stdout:
         print_results(self.log_printer, Section(''), [
             Result('t', 'msg'),
             Result.from_values('t', 'msg', file='file', line=5)
         ], {}, {}, self.console_printer)
         self.assertEqual(
             '\n' + STR_PROJECT_WIDE + '\n'
             '|    | [NORMAL] t:\n'
             '|    | {0}\n'
             # Second results file isn't there, no context is
             # printed, only a warning log message which we
             # don't catch
             '|    | [NORMAL] t:\n'
             '|    | {0}\n'.format(
                 highlight_text(
                     self.no_color, 'msg', style=BackgroundMessageStyle)),
             stdout.getvalue())
Esempio n. 22
0
    def test_print_results_multiple_ranges(self):
        affected_code = (SourceRange.from_values('some_file', 5, end_line=7),
                         SourceRange.from_values('another_file', 1, 3, 1, 5),
                         SourceRange.from_values('another_file', 3, 3, 3, 5))
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer, Section(''), [
                    Result('Bear_for_detecting_clone', 'Clone Found',
                           affected_code)
                ], {
                    abspath('some_file'):
                    ['line ' + str(i + 1) + '\n' for i in range(10)],
                    abspath('another_file'):
                    ['line ' + str(i + 1) for i in range(10)]
                }, {}, self.console_printer)
            self.assertEqual(
                """
another_file
[   1] li{0}{1}

another_file
[   3] li{0}{2}

some_file
[   5] li{0}{3}
[   6] li{0}{4}
[   7] li{0}{5}
**** Bear_for_detecting_clone [Section:  | Severity: NORMAL] ****
!    ! {6}\n""".format(
                    highlight_text(self.no_color, 'ne',
                                   BackgroundSourceRangeStyle, self.lexer),
                    highlight_text(self.no_color, ' 1', NoColorStyle,
                                   self.lexer),
                    highlight_text(self.no_color, ' 3', NoColorStyle,
                                   self.lexer),
                    highlight_text(self.no_color, ' 5', NoColorStyle,
                                   self.lexer),
                    highlight_text(self.no_color, ' 6', NoColorStyle,
                                   self.lexer),
                    highlight_text(self.no_color, ' 7', NoColorStyle,
                                   self.lexer),
                    highlight_text(self.no_color,
                                   'Clone Found',
                                   style=BackgroundMessageStyle), ' '),
                stdout.getvalue())
Esempio n. 23
0
    def test_print_results_multiple_ranges(self):
        affected_code = (
            SourceRange.from_values('some_file', 5, end_line=7),
            SourceRange.from_values('another_file', 1, 3, 1, 5),
            SourceRange.from_values('another_file', 3, 3, 3, 5))
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(''),
                [Result('Bear_for_detecting_clone',
                        'Clone Found',
                        affected_code)],
                {abspath('some_file'): ['line ' + str(i + 1) + '\n'
                                        for i in range(10)],
                 abspath('another_file'): ['line ' + str(i + 1)
                                           for i in range(10)]},
                {},
                self.console_printer)
            self.assertEqual("""
another_file
[   1] li{0}{1}

another_file
[   3] li{0}{2}

some_file
[   5] li{0}{3}
[   6] li{0}{4}
[   7] li{0}{5}
**** Bear_for_detecting_clone [Section:  | Severity: NORMAL] ****
!    ! {6}\n""".format(highlight_text(self.no_color, 'ne',
                                      BackgroundSourceRangeStyle, self.lexer),
                       highlight_text(self.no_color, ' 1', NoColorStyle,
                                      self.lexer),
                       highlight_text(self.no_color, ' 3', NoColorStyle,
                                      self.lexer),
                       highlight_text(self.no_color, ' 5', NoColorStyle,
                                      self.lexer),
                       highlight_text(self.no_color, ' 6', NoColorStyle,
                                      self.lexer),
                       highlight_text(self.no_color, ' 7', NoColorStyle,
                                      self.lexer),
                       highlight_text(self.no_color, 'Clone Found',
                                      style=BackgroundMessageStyle), ' '),
                stdout.getvalue())
Esempio n. 24
0
 def test_print_results_missing_file(self):
     self.log_printer = LogPrinter(NullPrinter())
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(""), [
                 Result("t", "msg"),
                 Result.from_values("t", "msg", file="file", line=5)
             ], {}, {},
             color=False)
         self.assertEqual(
             "\n" + STR_PROJECT_WIDE + "\n"
             "|    | [NORMAL] t:\n"
             "|    | {0}\n"
             # Second results file isn't there, no context is
             # printed, only a warning log message which we
             # don't catch
             "|    | [NORMAL] t:\n"
             "|    | {0}\n".format(
                 highlight_text("msg", style=BackgroundMessageStyle)),
             stdout.getvalue())
Esempio n. 25
0
 def test_print_results_missing_file(self):
     self.log_printer.log_level = logging.CRITICAL
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(''),
             [Result('t', 'msg'),
              Result.from_values('t', 'msg', file='file', line=5)],
             {},
             {},
             self.console_printer)
         self.assertEqual('\n' + STR_PROJECT_WIDE + '\n'
                          '|    | [NORMAL] t:\n'
                          '|    | {0}\n'
                          # Second results file isn't there, no context is
                          # printed, only a warning log message which we
                          # don't catch
                          '|    | [NORMAL] t:\n'
                          '|    | {0}\n'.format(
                              highlight_text(self.no_color, 'msg',
                                             style=BackgroundMessageStyle)),
                          stdout.getvalue())
Esempio n. 26
0
 def test_print_results_missing_file(self):
     self.log_printer = LogPrinter(NullPrinter())
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(""),
             [Result("t", "msg"),
              Result.from_values("t", "msg", file="file", line=5)],
             {},
             {},
             color=False)
         self.assertEqual("\n" + STR_PROJECT_WIDE + "\n"
                          "|    | [NORMAL] t:\n"
                          "|    | {0}\n"
                          # Second results file isn't there, no context is
                          # printed, only a warning log message which we
                          # don't catch
                          "|    | [NORMAL] t:\n"
                          "|    | {0}\n".format(
                              highlight_text("msg",
                                             style=BackgroundMessageStyle)),
                          stdout.getvalue())
Esempio n. 27
0
    def test_print_results_multiple_ranges(self):
        affected_code = (
            SourceRange.from_values('some_file', 5, end_line=7),
            SourceRange.from_values('another_file', 1, 3, 1, 5),
            SourceRange.from_values('another_file', 3, 3, 3, 5))
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(''),
                [Result('ClangCloneDetectionBear',
                        'Clone Found',
                        affected_code)],
                {abspath('some_file'): ['line ' + str(i + 1) + '\n'
                                        for i in range(10)],
                 abspath('another_file'): ['line ' + str(i + 1)
                                           for i in range(10)]},
                {},
                self.console_printer)
            self.assertEqual("""
another_file
|   1| li{0}{1}

another_file
|   3| li{0}{2}

some_file
|   5| {3}
|   6| {4}
|   7| {5}
|    | [NORMAL] ClangCloneDetectionBear:
|    | {6}\n""".format(highlight_text(self.no_color, 'ne', self.lexer,
                                      BackgroundSourceRangeStyle),
                       highlight_text(self.no_color, ' 1', self.lexer),
                       highlight_text(self.no_color, ' 3', self.lexer),
                       highlight_text(self.no_color, 'line 5', self.lexer),
                       highlight_text(self.no_color, 'line 6', self.lexer),
                       highlight_text(self.no_color, 'line 7', self.lexer),
                       highlight_text(self.no_color, 'Clone Found',
                                      style=BackgroundMessageStyle)),
                stdout.getvalue())
Esempio n. 28
0
    def test_print_result_no_input(self):
        with make_temp() as testfile_path:
            file_dict = {testfile_path: ["1\n", "2\n", "3\n"]}
            diff = Diff(file_dict[testfile_path])
            diff.delete_line(2)
            diff.change_line(3, "3\n", "3_changed\n")
            with simulate_console_inputs(1, 2, 3) as generator, \
                    retrieve_stdout() as stdout:
                ApplyPatchAction.is_applicable = staticmethod(
                    lambda *args: True)
                print_results_no_input(self.log_printer,
                                       Section("someSection"),
                                       [Result("origin", "message", diffs={
                                           testfile_path: diff})],
                                       file_dict,
                                       self.file_diff_dict,
                                       color=False)
                self.assertEqual(generator.last_input, -1)
                self.assertEqual(stdout.getvalue(),
                                 """
Project wide:
|    | [NORMAL] origin:
|    | {}\n""".format(highlight_text("message", style=BackgroundMessageStyle)))
Esempio n. 29
0
    def test_print_result_no_input(self):
        with make_temp() as testfile_path:
            file_dict = {testfile_path: ["1\n", "2\n", "3\n"]}
            diff = Diff(file_dict[testfile_path])
            diff.delete_line(2)
            diff.change_line(3, "3\n", "3_changed\n")
            with simulate_console_inputs(1, 2, 3) as generator, \
                    retrieve_stdout() as stdout:
                ApplyPatchAction.is_applicable = staticmethod(
                    lambda *args: True)
                print_results_no_input(
                    self.log_printer,
                    Section("someSection"),
                    [Result("origin", "message", diffs={testfile_path: diff})],
                    file_dict,
                    self.file_diff_dict,
                    color=False)
                self.assertEqual(generator.last_input, -1)
                self.assertEqual(
                    stdout.getvalue(), """
Project wide:
|    | [NORMAL] origin:
|    | {}\n""".format(highlight_text("message", style=BackgroundMessageStyle)))
Esempio n. 30
0
    def test_print_results_multiple_ranges(self):
        affected_code = (SourceRange.from_values("some_file", 5, end_line=7),
                         SourceRange.from_values("another_file", 1, 3, 1, 5),
                         SourceRange.from_values("another_file", 3, 3, 3, 5))
        with retrieve_stdout() as stdout:
            print_results(self.log_printer,
                          Section(""), [
                              Result("ClangCloneDetectionBear", "Clone Found",
                                     affected_code)
                          ], {
                              abspath("some_file"):
                              ["line " + str(i + 1) + "\n" for i in range(10)],
                              abspath("another_file"):
                              ["line " + str(i + 1) for i in range(10)]
                          }, {},
                          color=False)
            self.assertEqual(
                """
another_file
|   1| li{0}{1}

another_file
|   3| li{0}{2}

some_file
|   5| {3}
|   6| {4}
|   7| {5}
|    | [NORMAL] ClangCloneDetectionBear:
|    | {6}\n""".format(
                    highlight_text('ne', self.lexer,
                                   BackgroundSourceRangeStyle),
                    highlight_text(' 1', self.lexer),
                    highlight_text(' 3', self.lexer),
                    highlight_text('line 5', self.lexer),
                    highlight_text('line 6', self.lexer),
                    highlight_text('line 7', self.lexer),
                    highlight_text("Clone Found",
                                   style=BackgroundMessageStyle)),
                stdout.getvalue())
Esempio n. 31
0
    def test_print_results_multiple_ranges(self):
        affected_code = (
            SourceRange.from_values("some_file", 5, end_line=7),
            SourceRange.from_values("another_file", 1, 3, 1, 5),
            SourceRange.from_values("another_file", 3, 3, 3, 5))
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(""),
                [Result("ClangCloneDetectionBear",
                        "Clone Found",
                        affected_code)],
                {abspath("some_file"): ["line " + str(i + 1) + "\n"
                                        for i in range(10)],
                 abspath("another_file"): ["line " + str(i + 1)
                                           for i in range(10)]},
                {},
                color=False)
            self.assertEqual("""
another_file
|   1| li{0}{1}

another_file
|   3| li{0}{2}

some_file
|   5| {3}
|   6| {4}
|   7| {5}
|    | [NORMAL] ClangCloneDetectionBear:
|    | {6}\n""".format(highlight_text('ne', self.lexer,
                                      BackgroundSourceRangeStyle),
                       highlight_text(' 1', self.lexer),
                       highlight_text(' 3', self.lexer),
                       highlight_text('line 5', self.lexer),
                       highlight_text('line 6', self.lexer),
                       highlight_text('line 7', self.lexer),
                       highlight_text("Clone Found",
                                      style=BackgroundMessageStyle)),
                stdout.getvalue())
Esempio n. 32
0
    def test_print_result_no_input(self):
        with make_temp() as testfile_path:
            file_dict = {testfile_path: ['1\n', '2\n', '3\n']}
            diff = Diff(file_dict[testfile_path])
            diff.delete_line(2)
            diff.change_line(3, '3\n', '3_changed\n')
            with simulate_console_inputs(1, 2, 3) as generator:
                with retrieve_stdout() as stdout:
                    ApplyPatchAction.is_applicable = staticmethod(
                        lambda *args: True)
                    print_results_no_input(self.log_printer,
                                           Section('someSection'),
                                           [Result('origin', 'message', diffs={
                                               testfile_path: diff})],
                                           file_dict,
                                           self.file_diff_dict,
                                           self.console_printer)
                    self.assertEqual(generator.last_input, -1)
                    self.assertEqual(stdout.getvalue(),
                                     """
Project wide:
**** origin [Section: someSection | Severity: NORMAL] ****
!    ! {}\n""".format(highlight_text(self.no_color, 'message',
                                         style=BackgroundMessageStyle)))