test_labelme_1.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. man_file = osp.realpath(osp.join(here, '../../../docs/man/labelme.1'))
  12. with open(man_file) as f:
  13. man_actual = f.read().splitlines()
  14. patterns_exclude = [
  15. r'^\.TH .*',
  16. r'^config file.*',
  17. ]
  18. PASS = 1
  19. for line_expected, line_actual in zip(man_expected, man_actual):
  20. for pattern in patterns_exclude:
  21. if re.match(pattern, line_expected) or re.match(pattern, line_actual):
  22. break
  23. else:
  24. if line_expected != line_actual:
  25. print(repr('> {}'.format(line_expected)), file=sys.stderr)
  26. print(repr('< {}'.format(line_actual)), file=sys.stderr)
  27. PASS = 0
  28. if not PASS:
  29. print(
  30. 'Please run:\n\n\thelp2man labelme > {}\n'.format(man_file),
  31. file=sys.stderr,
  32. )
  33. assert PASS