You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
881B

  1. """
  2. Test utility for error checking
  3. """
  4. from contextlib import contextmanager
  5. from typing import Iterator
  6. import subprocess
  7. from pathlib import Path
  8. import tempfile
  9. import os
  10. @contextmanager
  11. def expect_error_marker(expect: str) -> Iterator[None]:
  12. tdir = Path(tempfile.mkdtemp())
  13. err_file = tdir / 'error'
  14. try:
  15. os.environ['DDS_WRITE_ERROR_MARKER'] = str(err_file)
  16. yield
  17. assert False, 'dds subprocess did not raise CallProcessError'
  18. except subprocess.CalledProcessError:
  19. assert err_file.exists(), \
  20. f'No error marker file was generated, but dds exited with an error (Expected "{expect}")'
  21. marker = err_file.read_text().strip()
  22. assert marker == expect, \
  23. f'dds did not produce the expected error (Expected {expect}, got {marker})'
  24. finally:
  25. os.environ.pop('DDS_WRITE_ERROR_MARKER')