Example #1
0
    def test_invalid_arguments(self):
        # arguments must be SourceRanges
        with self.assertRaises(TypeError):
            SourceRange(1, self.result_fileA_noline)

        with self.assertRaises(TypeError):
            SourceRange(self.result_fileA_line2, 1)
    def test_contained_in_3(self):
        start = SourcePosition('a.py', line=1, column=5)
        end = SourcePosition('a.py', line=5, column=1)
        smaller = SourceRange(start, end)

        start = SourcePosition('a.py', line=2, column=5)
        end = SourcePosition('a.py', line=5, column=1)
        bigger = SourceRange(start, end)
        self.assertFalse(contained_in(smaller, bigger))
Example #3
0
    def test_check_bear_results_3(self):
        start = SourcePosition('a.py', line=368, column=4)
        end = SourcePosition('a.py', line=442, column=2)
        range_object = SourceRange(start, end)
        results = [
            Result(affected_code=[range_object],
                   message='green_mode',
                   origin=QuickstartBear)
        ]

        start = SourcePosition('a.py', line=468, column=4)
        end = SourcePosition('a.py', line=478, column=2)
        ignore_object = SourceRange(start, end)
        ignore_ranges = [('+=', ignore_object)]
        self.assertFalse(check_bear_results(results, ignore_ranges))
 def test_run_quickstartbear(self):
     dir_path = str(Path(__file__).parent) + os.sep
     ignore_globs = ['*pycache*', '**.pyc', '**.orig']
     contents = initialize_project_data(dir_path, ignore_globs)
     contents = {'dir_structure': contents, settings_key: []}
     settings_key_values = [
         {
             'max_lines_per_file': 1000
         },  # default value
         {
             'max_line_length': 80
         },
         {
             'min_lines_per_file': 5
         }
     ]
     test_contents = deepcopy(contents)
     test_contents[settings_key] = settings_key_values
     (final_contents, ignore_ranges, complete_file_dict,
      complete_filename_list) = run_quickstartbear(contents, dir_path)
     ignore_file_name = dir_path + 'test_dir' + os.sep + 'test_file.py'
     start = SourcePosition(ignore_file_name, line=3, column=1)
     stop = SourcePosition(ignore_file_name, line=4, column=20)
     test_ignore_ranges = SourceRange(start, stop)
     self.assertEqual(test_contents, final_contents)
     self.assertEqual(ignore_ranges, [([], test_ignore_ranges)])
Example #5
0
    def test_construction(self):
        uut1 = SourceRange(self.result_fileA_noline)
        self.assertEqual(uut1.end, self.result_fileA_noline)

        uut2 = SourceRange.from_values('A')
        self.assertEqual(uut1, uut2)

        uut = SourceRange.from_values('B', start_line=2, end_line=4)
        self.assertEqual(uut.start, self.result_fileB_line2)
        self.assertEqual(uut.end, self.result_fileB_line4)
Example #6
0
    def test_from_absolute_position(self):
        text = ('a\n', 'b\n')
        start = AbsolutePosition(text, 0)
        end = AbsolutePosition(text, 2)

        uut = SourceRange.from_absolute_position('F', start, end)
        compare = SourceRange.from_values('F', 1, 1, 2, 1)
        self.assertEqual(uut, compare)

        uut = SourceRange.from_absolute_position('F', start, None)
        compare = SourceRange(SourcePosition('F', 1, 1), None)
        self.assertEqual(uut, compare)
Example #7
0
    def test_renamed_file(self):
        src_range = SourceRange(SourcePosition('test_file'))
        self.assertEqual(src_range.renamed_file({}), abspath('test_file'))

        self.assertEqual(
            src_range.renamed_file({abspath('test_file'): Diff([])}),
            abspath('test_file'))

        self.assertEqual(
            src_range.renamed_file(
                {abspath('test_file'): Diff([], rename='another_file')}),
            'another_file')
Example #8
0
 def test_invalid_comparison(self):
     with self.assertRaises(TypeError):
         SourceRange(self.result_fileB_noline, self.result_fileB_line2) < 1
Example #9
0
 def test_argument_order(self):
     # end should come after the start
     with self.assertRaises(ValueError):
         SourceRange(self.result_fileA_line2, self.result_fileA_noline)
Example #10
0
 def test_argument_file(self):
     # both Source_Positions should describe the same file
     with self.assertRaises(ValueError):
         SourceRange(self.result_fileA_noline, self.result_fileB_noline)
Example #11
0
 def test_file_property(self):
     uut = SourceRange(self.result_fileA_line2)
     self.assertRegex(uut.file, '.*A')
Example #12
0
 def test_expand(self):
     empty_position = SourcePosition('filename')
     file = ['abc\n', 'def\n', 'ghi\n']
     empty_range = SourceRange(empty_position, empty_position)
     full_range = SourceRange.from_values('filename', 1, 1, 3, 4)
     self.assertEqual(empty_range.expand(file), full_range)
Example #13
0
 def test_expand(self):
     empty_position = SourcePosition("filename")
     file = ["abc\n", "def\n", "ghi\n"]
     empty_range = SourceRange(empty_position, empty_position)
     full_range = SourceRange.from_values("filename", 1, 1, 3, 4)
     self.assertEqual(empty_range.expand(file), full_range)
Example #14
0
 def test_file_property(self):
     uut = SourceRange(self.result_fileA_line2)
     self.assertEqual(uut.file, "A")