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)
Ejemplo n.º 2
0
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):
    provider = directory_watcher.SequentialGFileProvider(
        path,
        path_filter=IsTensorFlowEventsFile)
    return directory_watcher.DirectoryWatcher(provider, loader_factory)
  else:
    return loader_factory(path)
    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'])