get_test_info.py 2.1 KB

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