示例#1
0
 def __init__(self, temp_dir_for_excludes=None):
     Settings.__init__(self, None)
     self.add_section('Plugins')
     self.set('pythonpath', [])
     self.set('auto imports', [])
     if temp_dir_for_excludes:
         self.excludes = Excludes(temp_dir_for_excludes)
示例#2
0
 def test_when_exclude_file_points_to_directory(self):
     dir = tempfile.mkdtemp()
     os.mkdir(os.path.join(dir, 'excludes'))
     self.exclude = Excludes(dir)
     del self.file_path # not created nor used in this test
     self.assertRaises(NameError, self.exclude._get_exclude_file, 'w')
示例#3
0
 def setUp(self):
     self.exclude = Excludes(directory=tempfile.gettempdir())
     self.file_path = self.exclude._exclude_file_path
示例#4
0
class TestExcludes(unittest.TestCase):

    def setUp(self):
        self.exclude = Excludes(directory=tempfile.gettempdir())
        self.file_path = self.exclude._exclude_file_path

    def tearDown(self):
        if hasattr(self, 'file_path') and os.path.exists(self.file_path):
            os.remove(self.file_path)

    def test_update_excludes(self):
        self.exclude.update_excludes(['foo'])
        self.assertTrue(self.exclude.contains(_join('foo', 'bar')))

    def test_update_excludes_with_separator(self):
        self.exclude.update_excludes(['foo' + sep])
        self.assertTrue(self.exclude.contains(_join('foo')))
        self.assertTrue(self.exclude.contains('foo'))

    def test_updating_excludes_does_not_repeat_path(self):
        self.exclude.update_excludes(['foo'])
        self.exclude.update_excludes(['foo' + sep])
        self.assertTrue(self.exclude.contains(_join('foo', 'bar')))
        self.assertEqual(len(self.exclude._get_excludes()), 1)

    def test_updating_excludes_does_not_repeat_almost_similar_paths(self):
        data = os.path.join('foo', 'bar')
        self.exclude.update_excludes([data])
        self.exclude.update_excludes([data + os.path.sep])
        self.assertTrue(self.exclude.contains(_join('foo', 'bar')))

    def test_contains_when_there_is_no_path(self):
        self.assertFalse(self.exclude.contains(None))

    def test_remove_path(self):
        excludes = [_join('foo'), _join('bar', 'baz'), _join('qux'), _join('quux', 'corge')]
        removed = [_join('bar', 'baz'), _join('quux', 'corge')]
        self.exclude.update_excludes(excludes)
        self.assertTrue(all([self.exclude.contains(e) for e in excludes]))
        self.exclude.remove_path(removed[0])
        self.assertFalse(self.exclude.contains(removed[0]))
        self.exclude.remove_path(removed[1])
        self.assertFalse(self.exclude.contains(removed[1]))

    def test_when_exclude_file_points_to_directory(self):
        dir = tempfile.mkdtemp()
        os.mkdir(os.path.join(dir, 'excludes'))
        self.exclude = Excludes(dir)
        del self.file_path # not created nor used in this test
        self.assertRaises(NameError, self.exclude._get_exclude_file, 'w')
示例#5
0
class TestExcludes(unittest.TestCase):

    def setUp(self):
        self.exclude = Excludes(directory=tempfile.gettempdir())
        self.file_path = self.exclude._exclude_file_path

    def tearDown(self):
        if hasattr(self, 'file_path') and os.path.exists(self.file_path):
            os.remove(self.file_path)

    def test_update_excludes(self):
        self.exclude.update_excludes(['foo'])
        self._verify_exclude_file(['foo\n'])

    def test_updating_excludes_does_not_repeat_path(self):
        self.exclude.update_excludes(['foo'])
        self.exclude.update_excludes(['foo'])
        self._verify_exclude_file(['foo\n'])

    def test_updating_excludes_does_not_repeat_almost_similar_paths(self):
        self.exclude.update_excludes(['/foo/bar'])
        self.exclude.update_excludes(['/foo/bar/'])
        self._verify_exclude_file(['/foo/bar\n'])

    def test_contains(self):
        self.exclude.update_excludes(['/foo/bar/baz'])
        self.assertTrue(self.exclude.contains('/foo/bar/baz'))
        self._verify_exclude_file(['/foo/bar/baz\n'])

    def test_contains_when_file_is_in_excluded_directory(self):
        self.exclude.update_excludes(['/foo'])
        self.assertTrue(self.exclude.contains('/foo/bar/baz'))
        self.assertTrue(self.exclude.contains('/foo/bar/'))
        self.assertTrue(self.exclude.contains('/foo/'))
        self._verify_exclude_file(['/foo\n'])

    def test_contains_when_there_is_no_path(self):
        self.assertFalse(self.exclude.contains(None))

    def test_remove_path(self):
        excludes = ['/foo', '/bar/baz', '/qux', '/quux/corge']
        removed = ['/bar/baz', '/quux/corge']
        self.exclude.update_excludes(excludes)
        self._verify_exclude_file([ex + '\n' for ex in excludes])
        self.exclude.remove_path(removed[0])
        self.assertEqual(len(self.exclude.get_excludes()), len(excludes)-1)
        self.exclude.remove_path(removed[1])
        self.assertEqual(len(self.exclude.get_excludes()), len(excludes)-2)

    def test_when_exclude_file_points_to_directory(self):
        dir = tempfile.mkdtemp()
        os.mkdir(os.path.join(dir, 'excludes'))
        self.exclude = Excludes(dir)
        del self.file_path # not created nor used in this test
        self.assertRaises(NameError, self.exclude._get_exclude_file, 'w')

    def _verify_exclude_file(self, expected):
        file_contents = open(self.file_path, 'r').readlines()
        self.assertEqual(file_contents, expected)