test_params.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import json
  2. from library.python.testing.custom_linter_util import linter_params
  3. from yatest.common import work_path
  4. SOURCE_ROOT = "TEST_SOURCE_ROOT"
  5. PROJECT_PATH = "TEST_PROJECT_PATH"
  6. OUTPUT_PATH = "TEST_OUTPUT_PATH"
  7. REPORT_FILE = "TEST_REPORT_FILE"
  8. LINT_NAME = "important-lint"
  9. DEPS = {
  10. "dep1": "/path/to/dep1",
  11. "dep2": "/path/to/dep2",
  12. }
  13. GLOBAL_RESOURCES = {
  14. "TOOL1_GLOBAL_RESOURCES": "/path/to/resource1",
  15. "TOOL2_GLOBAL_RESOURCES": "/path/to/resource2",
  16. }
  17. CONFIGS = ["path/to/config1", "path/to/config2"]
  18. EXTRA_PARAMS = {
  19. "var1": "val1",
  20. "var2": "val2",
  21. }
  22. FILES = ["file1.cpp", "file2.cpp"]
  23. EXPECTED = linter_params.LinterArgs(
  24. source_root=SOURCE_ROOT,
  25. project_path=PROJECT_PATH,
  26. output_path=OUTPUT_PATH,
  27. report_file=REPORT_FILE,
  28. lint_name=LINT_NAME,
  29. depends=DEPS,
  30. global_resources=GLOBAL_RESOURCES,
  31. configs=CONFIGS,
  32. extra_params=EXTRA_PARAMS,
  33. files=FILES,
  34. )
  35. def test_cmd_line_params():
  36. raw_args = [
  37. "--source-root", SOURCE_ROOT,
  38. "--project-path", PROJECT_PATH,
  39. "--output-path", OUTPUT_PATH,
  40. "--report-file", REPORT_FILE,
  41. "--lint-name", LINT_NAME,
  42. ]
  43. for rel, abs in DEPS.items():
  44. raw_args += ["--depends", ":".join([rel, abs])]
  45. for var, path in GLOBAL_RESOURCES.items():
  46. raw_args += ["--global-resource", ":".join([var, path])]
  47. for cfg in CONFIGS:
  48. raw_args += ["--config", cfg]
  49. for var, val in EXTRA_PARAMS.items():
  50. raw_args += ["--extra-param", "=".join([var, val])]
  51. raw_args += FILES
  52. got = linter_params.get_params(raw_args)
  53. assert got == EXPECTED
  54. def test_json_params():
  55. params_file = work_path("params.josn")
  56. params = {
  57. "source_root": SOURCE_ROOT,
  58. "project_path": PROJECT_PATH,
  59. "output_path": OUTPUT_PATH,
  60. "report_file": REPORT_FILE,
  61. "lint_name": LINT_NAME,
  62. "depends": DEPS,
  63. "global_resources": GLOBAL_RESOURCES,
  64. "configs": CONFIGS,
  65. "extra_params": EXTRA_PARAMS,
  66. "files": FILES,
  67. }
  68. with open(params_file, "w") as f:
  69. json.dump(params, f)
  70. got = linter_params.get_params(["--params", params_file])
  71. assert got == EXPECTED