test_labelme_1.py 889 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import os.path as osp
  4. import re
  5. import shlex
  6. import subprocess
  7. import sys
  8. here = osp.dirname(osp.abspath(__file__))
  9. cmd = 'help2man labelme'
  10. man_expected = subprocess.check_output(shlex.split(cmd)).decode().splitlines()
  11. with open(osp.join(here, '../../../docs/man/labelme.1')) as f:
  12. man_actual = f.read().splitlines()
  13. patterns_exclude = [
  14. r'^\.TH .*',
  15. r'^config file.*',
  16. ]
  17. FAIL = 0
  18. for line_expected, line_actual in zip(man_expected, man_actual):
  19. for pattern in patterns_exclude:
  20. if re.match(pattern, line_expected) or re.match(pattern, line_actual):
  21. break
  22. else:
  23. if line_expected != line_actual:
  24. print(repr('> {}'.format(line_expected)), file=sys.stderr)
  25. print(repr('< {}'.format(line_actual)), file=sys.stderr)
  26. FAIL = 1
  27. sys.exit(FAIL)