get_test_info.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  2. # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
  3. from glob import glob
  4. from os.path import basename, join, splitext
  5. from pylint.testutils.constants import SYS_VERS_STR
  6. def _get_tests_info(input_dir, msg_dir, prefix, suffix):
  7. """get python input examples and output messages
  8. We use following conventions for input files and messages:
  9. for different inputs:
  10. test for python >= x.y -> input = <name>_pyxy.py
  11. test for python < x.y -> input = <name>_py_xy.py
  12. for one input and different messages:
  13. message for python >= x.y -> message = <name>_pyxy.txt
  14. lower versions -> message with highest num
  15. """
  16. result = []
  17. for fname in glob(join(input_dir, prefix + "*" + suffix)):
  18. infile = basename(fname)
  19. fbase = splitext(infile)[0]
  20. # filter input files :
  21. pyrestr = fbase.rsplit("_py", 1)[-1] # like _26 or 26
  22. if pyrestr.isdigit(): # '24', '25'...
  23. if pyrestr.isdigit() and int(SYS_VERS_STR) < int(pyrestr):
  24. continue
  25. if pyrestr.startswith("_") and pyrestr[1:].isdigit():
  26. # skip test for higher python versions
  27. if pyrestr[1:].isdigit() and int(SYS_VERS_STR) >= int(pyrestr[1:]):
  28. continue
  29. messages = glob(join(msg_dir, fbase + "*.txt"))
  30. # the last one will be without ext, i.e. for all or upper versions:
  31. if messages:
  32. for outfile in sorted(messages, reverse=True):
  33. py_rest = outfile.rsplit("_py", 1)[-1][:-4]
  34. if py_rest.isdigit() and int(SYS_VERS_STR) >= int(py_rest):
  35. break
  36. else:
  37. # This will provide an error message indicating the missing filename.
  38. outfile = join(msg_dir, fbase + ".txt")
  39. result.append((infile, outfile))
  40. return result