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.""" 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 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 testRaisesWithBadArguments(self): with self.assertRaises(ValueError): directory_watcher.DirectoryWatcher(None, lambda x: None) with self.assertRaises(ValueError): directory_watcher.DirectoryWatcher('dir', None)