Пример #1
0
    def test_escaping_of_globs_that_start_with_reserved_chars(
            self, mock_open, _):
        file_data = ['', '# comment', '\#file1', '\!file2']
        mock_open.return_value.__iter__.return_value = file_data

        result = IgnoreManager.get_config()
        self.assertEqual(result, (['#file1', '!file2'], []))
Пример #2
0
 def test_whitelisted_lines(self, mock_open, _):
     configs = [
         ('foo.c', '*.c'),
         ('.c', '*.c'),
         ('foo/foo.c', '*.c'),
         ('foo/foo.c', 'foo.c'),
         ('foo.c', '/*.c'),
         ('foo.c', '/foo.c'),
         ('foo.c', 'foo.c'),
         ('foo.c', 'foo.[ch]'),
         ('foo/bar/bla.c', 'foo/**'),
         ('foo/bar/bla/blie.c', 'foo/**/blie.c'),
         ('foo/bar/bla.c', '**/bla.c'),
         ('bla.c', '**/bla.c'),
         ('foo/bar', 'foo/**/bar'),
         ('foo/bla/bar', 'foo/**/bar'),
         ('foo/bar/', 'bar/'),
         ('foo/bar/', 'bar'),
         ('foo/bar/something', 'foo/bar/*'),
     ]
     for (path, pattern) in configs:
         mock_open.return_value.__iter__.return_value = [pattern]
         patterns = IgnoreManager.get_config()
         self.assertEqual(
             (self.get_ignored(patterns), self.get_whitelisted(patterns)),
             ([pattern], []))
         assert len(list(IgnoreManager.find_matching(path, patterns))) == 1
Пример #3
0
    def test_properly_interprets_whitelisted_globs(self, mock_open, _):
        file_data = ['', '# comment', '*.py', '!file1.py']
        mock_open.return_value.__iter__.return_value = file_data

        patterns = IgnoreManager.get_config()
        self.assertEqual(
            (self.get_ignored(patterns), self.get_whitelisted(patterns)),
            (['*.py'], ['file1.py']))
Пример #4
0
    def test_trims_slash_prefix_from_abs_paths(self, mock_open, _):
        file_data = ['/test', '!/ignore']
        mock_open.return_value.__iter__.return_value = file_data

        patterns = IgnoreManager.get_config()
        self.assertEqual(
            (self.get_ignored(patterns), self.get_whitelisted(patterns)),
            (['/test'], ['/ignore']))
Пример #5
0
    def test_ignores_commented_lines(self, mock_open, _):
        file_data = ['', '# comment', '', '*.py']
        mock_open.return_value.__iter__.return_value = file_data

        patterns = IgnoreManager.get_config()
        self.assertEqual(
            (self.get_ignored(patterns), self.get_whitelisted(patterns)),
            (['*.py'], []))
Пример #6
0
 def test_ignored_lines(self, mock_open, _):
     configs = [('foo.c', 'foo.[dh]'), ('foo/foo.c', '/foo.c'),
                ('foo/foo.c', '/*.c'), ('foo/bar/', '/bar/'),
                ('foo/bar/', 'foo/bar/*'), ('foo/bar', 'foo?bar')]
     for (path, pattern) in configs:
         mock_open.return_value.__iter__.return_value = [pattern]
         patterns = IgnoreManager.get_config()
         self.assertEqual(
             (self.get_ignored(patterns), self.get_whitelisted(patterns)),
             ([pattern], []))
         assert list(IgnoreManager.find_matching(path, patterns)) == []
Пример #7
0
 def test_returns_two_empty_lists_if_file_is_not_present(self, _):
     patterns = IgnoreManager.get_config()
     self.assertEqual(patterns, [])
Пример #8
0
 def test_returns_two_empty_lists_if_file_is_not_present(self, _):
     result = IgnoreManager.get_config()
     self.assertEqual(result, ([], []))
Пример #9
0
    def test_trims_slash_prefix_from_abs_paths(self, mock_open, _):
        file_data = ['/test', '!/ignore']
        mock_open.return_value.__iter__.return_value = file_data

        result = IgnoreManager.get_config()
        self.assertEqual(result, (['test'], ['ignore']))
Пример #10
0
    def test_ignores_commented_lines(self, mock_open, _):
        file_data = ['', '# comment', '', '*.py']
        mock_open.return_value.__iter__.return_value = file_data

        result = IgnoreManager.get_config()
        self.assertEqual(result, (['*.py'], []))