data.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # ex:ts=4:sw=4:sts=4:et
  2. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  3. #
  4. # patchtestdata: module used to share command line arguments between
  5. # patchtest & test suite and a data store between test cases
  6. #
  7. # Copyright (C) 2016 Intel Corporation
  8. #
  9. # SPDX-License-Identifier: GPL-2.0-only
  10. #
  11. # NOTE: Strictly speaking, unit test should be isolated from outside,
  12. # but patchtest test suites uses command line input data and
  13. # pretest and test test cases may use the datastore defined
  14. # on this module
  15. import os
  16. import argparse
  17. import collections
  18. import tempfile
  19. import logging
  20. logger=logging.getLogger('patchtest')
  21. info=logger.info
  22. default_testdir = os.path.abspath(os.path.dirname(__file__) + "/tests")
  23. default_repodir = os.path.abspath(os.path.dirname(__file__) + "/../../..")
  24. # Data store commonly used to share values between pre and post-merge tests
  25. PatchTestDataStore = collections.defaultdict(str)
  26. class PatchTestInput(object):
  27. """Abstract the patchtest argument parser"""
  28. @classmethod
  29. def set_namespace(cls):
  30. parser = cls.get_parser()
  31. parser.parse_args(namespace=cls)
  32. @classmethod
  33. def get_parser(cls):
  34. parser = argparse.ArgumentParser()
  35. target_patch_group = parser.add_mutually_exclusive_group(required=True)
  36. target_patch_group.add_argument('--patch', metavar='PATCH', dest='patch_path',
  37. help='The patch to be tested')
  38. target_patch_group.add_argument('--directory', metavar='DIRECTORY', dest='patch_path',
  39. help='The directory containing patches to be tested')
  40. parser.add_argument('--repodir', metavar='REPO',
  41. default=default_repodir,
  42. help="Name of the repository where patch is merged")
  43. parser.add_argument('--testdir', metavar='TESTDIR',
  44. default=default_testdir,
  45. help="Directory where test cases are located")
  46. parser.add_argument('--top-level-directory', '-t',
  47. dest='topdir',
  48. default=None,
  49. help="Top level directory of project (defaults to start directory)")
  50. parser.add_argument('--pattern', '-p',
  51. dest='pattern',
  52. default='test*.py',
  53. help="Pattern to match test files")
  54. parser.add_argument('--base-branch', '-b',
  55. dest='basebranch',
  56. help="Branch name used by patchtest to branch from. By default, it uses the current one.")
  57. parser.add_argument('--base-commit', '-c',
  58. dest='basecommit',
  59. help="Commit ID used by patchtest to branch from. By default, it uses HEAD.")
  60. parser.add_argument('--debug', '-d',
  61. action='store_true',
  62. help='Enable debug output')
  63. parser.add_argument('--log-results',
  64. action='store_true',
  65. help='Enable logging to a file matching the target patch name with ".testresult" appended')
  66. return parser