Ejemplo n.º 1
0
def test_SaveSampleTextObserver(tempdir: pathlib.Path):
    observer = sample_observers.SaveSampleTextObserver(tempdir)
    contents = "Hello, world!"
    sample = model_pb2.Sample(text=contents)

    assert observer.OnSample(sample)
    path = tempdir / f"{crypto.sha256_str(contents)}.txt"
    assert path.is_file()
    assert fs.Read(path) == contents
Ejemplo n.º 2
0
def SampleObserversFromFlags():
  """Instantiate sample observers from flag values."""
  sample_observers = []
  if FLAGS.min_samples <= 0:
    app.Warning(
        'Entering an infinite sample loop, this process will never end!')
  else:
    sample_observers.append(
        sample_observers_lib.MaxSampleCountObserver(FLAGS.min_samples))
  if FLAGS.print_samples:
    sample_observers.append(sample_observers_lib.PrintSampleObserver())
  if FLAGS.cache_samples:
    sample_observers.append(sample_observers_lib.LegacySampleCacheObserver())
  if FLAGS.sample_text_dir:
    sample_observers.append(
        sample_observers_lib.SaveSampleTextObserver(
            pathlib.Path(FLAGS.sample_text_dir)))
  return sample_observers