您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728
  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')