def test_multiple_directories_in_exclude_list(self): """test case for multiple directories to exclude""" subdirectories_to_watch = [] exclude_list = [ 'f1/f2', 'f3/f1', 'f3/f3', ] with tempfile.TemporaryDirectory() as tmpdir: make_tree(tmpdir, [ 'f1', 'f1/f1', 'f1/f2', 'f2', 'f2/f1', 'f3', 'f3/f1', 'f3/f2', 'f3/f3' ]) ans_subdirectories_to_watch = [ (Path(tmpdir, 'f2'), True), (Path(tmpdir, 'f1/f1'), True), (Path(tmpdir, 'f3/f2'), True), (Path(tmpdir), False), (Path(tmpdir, 'f1'), False), (Path(tmpdir, 'f3'), False), ] subdirectories_to_watch = \ watch.minimal_watch_directories(tmpdir, exclude_list) self.assertEqual(set(subdirectories_to_watch), set(ans_subdirectories_to_watch))
def test_nested_sibling_exclusion(self): subdirectories_to_watch = [] exclude_list = [ 'f1/f1/f1/f1/f1', 'f1/f1/f1/f2', ] with tempfile.TemporaryDirectory() as tmpdir: make_tree(tmpdir, [ 'f1', 'f1/f1', 'f1/f1/f1', 'f1/f1/f1/f1', 'f1/f1/f1/f1/f1', 'f1/f1/f1/f1/f2', 'f1/f1/f1/f1/f3', 'f1/f1/f1/f2', ]) ans_subdirectories_to_watch = [ (Path(tmpdir, 'f1/f1/f1/f1/f2'), True), (Path(tmpdir, 'f1/f1/f1/f1/f3'), True), (Path(tmpdir), False), (Path(tmpdir, 'f1'), False), (Path(tmpdir, 'f1/f1'), False), (Path(tmpdir, 'f1/f1/f1'), False), (Path(tmpdir, 'f1/f1/f1/f1'), False), ] subdirectories_to_watch = \ watch.minimal_watch_directories(tmpdir, exclude_list) self.assertEqual(set(subdirectories_to_watch), set(ans_subdirectories_to_watch))
def test_nested_sibling_exclusion(self): subdirectories_to_watch = [] exclude_list = [ 'f1/f1/f1/f1/f1', 'f1/f1/f1/f2', ] self.make_tree( 'f1/f1/f1/f1/f1', 'f1/f1/f1/f1/f2', 'f1/f1/f1/f1/f3', 'f1/f1/f1/f2', ) ans_subdirectories_to_watch = [ (self._root / 'f1/f1/f1/f1/f2', True), (self._root / 'f1/f1/f1/f1/f3', True), (self._root, False), (self._root / 'f1', False), (self._root / 'f1/f1', False), (self._root / 'f1/f1/f1', False), (self._root / 'f1/f1/f1/f1', False), ] subdirectories_to_watch = watch.minimal_watch_directories( self._root, exclude_list) self.assertEqual(set(subdirectories_to_watch), set(ans_subdirectories_to_watch))
def test_multiple_directories_in_exclude_list(self): """test case for multiple directories to exclude""" subdirectories_to_watch = [] exclude_list = [ 'f1/f2', 'f3/f1', 'f3/f3', ] self.make_tree( 'f1/f1', 'f1/f2', 'f2/f1', 'f3/f1', 'f3/f2', 'f3/f3', ) ans_subdirectories_to_watch = [ (self._root / 'f2', True), (self._root / 'f1/f1', True), (self._root / 'f3/f2', True), (self._root, False), (self._root / 'f1', False), (self._root / 'f3', False), ] subdirectories_to_watch = watch.minimal_watch_directories( self._root, exclude_list) self.assertEqual(set(subdirectories_to_watch), set(ans_subdirectories_to_watch))
def test_empty_directory(self): subdirectories_to_watch = [] ans_subdirectories_to_watch = [(self._root, False)] subdirectories_to_watch = watch.minimal_watch_directories( self._root, 'f1') self.assertEqual(set(subdirectories_to_watch), set(ans_subdirectories_to_watch))
def test_empty_directory(self): subdirectories_to_watch = [] with tempfile.TemporaryDirectory() as tmpdir: ans_subdirectories_to_watch = [(Path(tmpdir), False)] subdirectories_to_watch = \ watch.minimal_watch_directories(tmpdir, 'f1') self.assertEqual(set(subdirectories_to_watch), set(ans_subdirectories_to_watch))
def test_non_exist_directories_to_exclude(self): subdirectories_to_watch = [] exclude_list = ['f3'] self.make_tree('f1', 'f2') ans_subdirectories_to_watch = [ (self._root / 'f1', True), (self._root / 'f2', True), (self._root, False), ] subdirectories_to_watch = watch.minimal_watch_directories( self._root, exclude_list) self.assertEqual(set(subdirectories_to_watch), set(ans_subdirectories_to_watch))
def test_two_layers_direcories(self): subdirectories_to_watch = [] exclude_list = ['f1/f2'] self.make_tree( 'f1/f1', 'f1/f2', 'f2/f1', ) ans_subdirectories_to_watch = [ (self._root / 'f2', True), (self._root / 'f1/f1', True), (self._root, False), (self._root / 'f1', False), ] subdirectories_to_watch = watch.minimal_watch_directories( self._root, exclude_list) self.assertEqual(set(subdirectories_to_watch), set(ans_subdirectories_to_watch))