def _GeneratorFromPath(path): """Create an event generator for file or directory at given path string.""" if gcs.IsGCSPath(path): provider = directory_watcher.SequentialGCSProvider( path, path_filter=IsTensorFlowEventsFile) return directory_watcher.DirectoryWatcher( provider, gcs_file_loader.GCSFileLoader) elif gfile.IsDirectory(path): provider = directory_watcher.SequentialGFileProvider( path, path_filter=IsTensorFlowEventsFile) return directory_watcher.DirectoryWatcher( provider, event_file_loader.EventFileLoader) else: return event_file_loader.EventFileLoader(path)
def _GeneratorFromPath(path): """Create an event generator for file or directory at given path string.""" if IsTensorFlowEventsFile(path): return event_file_loader.EventFileLoader(path) else: return directory_watcher.DirectoryWatcher( path, event_file_loader.EventFileLoader, IsTensorFlowEventsFile)
def setUp(self): # Put everything in a directory so it's easier to delete. self._directory = os.path.join(self.get_temp_dir(), 'monitor_dir') os.mkdir(self._directory) self._watcher = directory_watcher.DirectoryWatcher( directory_watcher.SequentialGFileProvider(self._directory), _ByteLoader)
def setUp(self): # Put everything in a directory so it's easier to delete. self._directory = os.path.join(self.get_temp_dir(), 'monitor_dir') os.mkdir(self._directory) self._watcher = directory_watcher.DirectoryWatcher( self._directory, _ByteLoader) self.stubs = googletest.StubOutForTesting()
def _GeneratorFromPath(path): """Create an event generator for file or directory at given path string.""" loader_factory = event_file_loader.EventFileLoader if gfile.IsDirectory(path): return directory_watcher.DirectoryWatcher(path, loader_factory, IsTensorFlowEventsFile) else: return loader_factory(path)
def _GeneratorFromPath(path): """Create an event generator for file or directory at given path string.""" if not path: raise ValueError('path must be a valid string') if IsTensorFlowEventsFile(path): return event_file_loader.EventFileLoader(path) else: return directory_watcher.DirectoryWatcher( path, event_file_loader.EventFileLoader, IsTensorFlowEventsFile)
def testFileFilter(self): self._watcher = directory_watcher.DirectoryWatcher( self._directory, _ByteLoader, path_filter=lambda path: 'do_not_watch_me' not in path) self._WriteToFile('a', 'a') self._WriteToFile('do_not_watch_me', 'b') self._WriteToFile('c', 'c') self.assertWatcherYields(['a', 'c'])
def _GeneratorFromPath(path): """Create an event generator for file or directory at given path string.""" if IsTensorFlowEventsFile(path): return io_wrapper.CreateFileLoader(path) else: provider = directory_watcher.SequentialFileProvider( path, path_filter=IsTensorFlowEventsFile) return directory_watcher.DirectoryWatcher(provider, io_wrapper.CreateFileLoader)
def testPathFilter(self): self._watcher = directory_watcher.DirectoryWatcher( self._directory, _ByteLoader, lambda path: 'do_not_watch_me' not in path) self._WriteToFile('a', 'a') self._WriteToFile('do_not_watch_me', 'b') self._WriteToFile('c', 'c') self.assertWatcherYields(['a', 'c']) self.assertFalse(self._watcher.OutOfOrderWritesDetected())
def testPathFilter(self): provider = directory_watcher.SequentialGFileProvider( self._directory, path_filter=lambda path: 'do_not_watch_me' not in path) self._watcher = directory_watcher.DirectoryWatcher( provider, _ByteLoader) self._WriteToFile('a', 'a') self._WriteToFile('do_not_watch_me', 'b') self._WriteToFile('c', 'c') self.assertWatcherYields(['a', 'c'])
def testRaisesWithBadArguments(self): with self.assertRaises(ValueError): directory_watcher.DirectoryWatcher(None, lambda x: None) with self.assertRaises(ValueError): directory_watcher.DirectoryWatcher('dir', None)