__init__.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. # coding: utf-8
  2. import re
  3. RESTART_TEST_INDICATOR = '##restart-test##'
  4. INFRASTRUCTURE_ERROR_INDICATOR = '##infrastructure-error##'
  5. RESTART_TEST_INDICATORS = [
  6. RESTART_TEST_INDICATOR,
  7. "network error",
  8. ]
  9. UID_PREFIX_DELIMITER = '-'
  10. # testing
  11. BIN_DIRECTORY = 'bin'
  12. CANON_DATA_DIR_NAME = "canondata"
  13. CANON_RESULT_FILE_NAME = "result.json"
  14. CANONIZATION_RESULT_FILE_NAME = "canonization_res.json"
  15. COMMON_CONTEXT_FILE_NAME = "common_test.context"
  16. CONSOLE_SNIPPET_LIMIT = 5000
  17. FAKE_OUTPUT_EXTS = frozenset([".mf", ".fake", ".cpf", ".cpsf"])
  18. LIST_NODE_LOG_FILE = "test_list.log"
  19. LIST_NODE_RESULT_FILE = "test_list.json"
  20. LIST_RESULT_NODE_LOG_FILE = "list_result.log"
  21. LIST_TRACE_FILE_NAME = "ytest_list.report.trace"
  22. MAX_FILE_SIZE = 1024 * 1024 * 2 # 2 MB
  23. MAX_TEST_RESTART_COUNT = 3
  24. NO_LISTED_TESTS = "NO_LISTED_TESTS"
  25. REPORT_SNIPPET_LIMIT = 12000
  26. SANITIZER_ERROR_RC = 100
  27. SUITE_CONTEXT_FILE_NAME = "test.context"
  28. TEST_LIST_FILE = "test_names_list.json"
  29. TEST_SUBTEST_SEPARATOR = '::'
  30. TESTING_OUT_DIR_NAME = "testing_out_stuff"
  31. TESTING_OUT_RAM_DRIVE_DIR_NAME = "ram_drive_output"
  32. TESTING_OUT_TAR_NAME = TESTING_OUT_DIR_NAME + ".tar.zstd"
  33. TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S.%f"
  34. TRACE_FILE_NAME = "ytest.report.trace"
  35. TRUNCATING_IGNORE_FILE_LIST = {TRACE_FILE_NAME, SUITE_CONTEXT_FILE_NAME, "run_test.log"}
  36. YT_RUN_TEST_DIR_NAME = "yt_run_test"
  37. YT_RUN_TEST_TAR_NAME = "yt_run_test.tar"
  38. COVERAGE_CFLAGS = ["-fprofile-instr-generate", "-fcoverage-mapping", "-DCLANG_COVERAGE"]
  39. COVERAGE_LDFLAGS = ["-fprofile-instr-generate", "-fcoverage-mapping"]
  40. CANON_BACKEND_KEY = "{canondata_backend}"
  41. DEFAULT_CANONIZATION_BACKEND = "storage.yandex-team.ru/get-devtools"
  42. MDS_URI_PREFIX = 'https://storage.yandex-team.ru/get-devtools/'
  43. BACKEND_URI_PREFIX = 'https://' + CANON_BACKEND_KEY + '/'
  44. MDS_SCHEME = 'mds'
  45. CANON_MDS_RESOURCE_REGEX = re.compile(re.escape(MDS_URI_PREFIX) + r'(.*?)($|#)')
  46. CANON_BACKEND_RESOURCE_REGEX = re.compile(re.escape(BACKEND_URI_PREFIX) + r'(.*?)($|#)')
  47. CANON_SBR_RESOURCE_REGEX = re.compile(r'(sbr:/?/?(\d+))')
  48. MANDATORY_ENV_VAR_NAME = 'YA_MANDATORY_ENV_VARS'
  49. STYLE_CPP_SOURCE_EXTS = [".cpp", ".cxx", ".cc", ".c", ".C"]
  50. STYLE_CPP_HEADER_EXTS = [".h", ".H", ".hh", ".hpp", ".hxx", ".ipp"]
  51. STYLE_CPP_ALL_EXTS = STYLE_CPP_SOURCE_EXTS + STYLE_CPP_HEADER_EXTS
  52. BUILD_FLAGS_ALLOWED_IN_CONTEXT = {
  53. 'AUTOCHECK',
  54. # Required for local test runs
  55. 'TESTS_REQUESTED',
  56. 'USE_ARCADIA_PYTHON',
  57. 'USE_SYSTEM_PYTHON',
  58. }
  59. STYLE_TEST_TYPES = [
  60. "classpath.clash",
  61. "clang_tidy",
  62. "eslint",
  63. "gofmt",
  64. "govet",
  65. "java.style",
  66. "ktlint",
  67. "py2_flake8",
  68. "flake8",
  69. "black",
  70. "ruff",
  71. "tsc_typecheck",
  72. ]
  73. REGULAR_TEST_TYPES = [
  74. "benchmark",
  75. "boost_test",
  76. "exectest",
  77. "fuzz",
  78. "g_benchmark",
  79. "go_bench",
  80. "go_test",
  81. "gtest",
  82. "hermione",
  83. "java",
  84. "jest",
  85. "py2test",
  86. "py3test",
  87. "pytest",
  88. "unittest",
  89. ]
  90. TEST_NODE_OUTPUT_RESULTS = [TESTING_OUT_TAR_NAME, YT_RUN_TEST_TAR_NAME]
  91. # kvm
  92. DEFAULT_RAM_REQUIREMENTS_FOR_KVM = 4
  93. MAX_RAM_REQUIREMENTS_FOR_KVM = 16
  94. # distbuild
  95. DISTBUILD_STATUS_REPORT_ENV_NAME = 'NODE_EXTENDED_STATUS_FILE_PATH'
  96. DEFAULT_TEST_NODE_TIMEOUT = 15 * 60
  97. TEST_NODE_FINISHING_TIME = 5 * 60
  98. # coverage
  99. COVERAGE_FUNCTION_ENTRIES_LIMIT = 2
  100. COVERAGE_PYTHON_EXTS = (".py", ".pyx", ".pxi", ".pxd")
  101. COVERAGE_RESOLVED_FILE_NAME_PATTERN = "coverage_resolved.{}.json"
  102. CPP_COVERAGE_RESOLVED_FILE_NAME = COVERAGE_RESOLVED_FILE_NAME_PATTERN.format("cpp")
  103. GO_COVERAGE_RESOLVED_FILE_NAME = COVERAGE_RESOLVED_FILE_NAME_PATTERN.format("go")
  104. JAVA_COVERAGE_RESOLVED_FILE_NAME = COVERAGE_RESOLVED_FILE_NAME_PATTERN.format("java")
  105. NLG_COVERAGE_RESOLVED_FILE_NAME = COVERAGE_RESOLVED_FILE_NAME_PATTERN.format("nlg")
  106. PYTHON2_COVERAGE_RESOLVED_FILE_NAME = COVERAGE_RESOLVED_FILE_NAME_PATTERN.format("py2")
  107. PYTHON3_COVERAGE_RESOLVED_FILE_NAME = COVERAGE_RESOLVED_FILE_NAME_PATTERN.format("py3")
  108. TS_COVERAGE_RESOLVED_FILE_NAME = COVERAGE_RESOLVED_FILE_NAME_PATTERN.format("ts")
  109. COVERAGE_CLANG_ENV_NAME = 'LLVM_PROFILE_FILE'
  110. COVERAGE_GCOV_ENV_NAME = 'GCOV_PREFIX'
  111. COVERAGE_GO_ENV_NAME = 'GO_COVERAGE_PREFIX'
  112. COVERAGE_PYTHON_ENV_NAME = 'PYTHON_COVERAGE_PREFIX'
  113. COVERAGE_TS_ENV_NAME = 'TS_COVERAGE_PREFIX'
  114. COVERAGE_NLG_ENV_NAME = 'NLG_COVERAGE_FILENAME'
  115. COVERAGE_ENV_VARS = (
  116. COVERAGE_CLANG_ENV_NAME,
  117. COVERAGE_GCOV_ENV_NAME,
  118. COVERAGE_GO_ENV_NAME,
  119. COVERAGE_NLG_ENV_NAME,
  120. COVERAGE_PYTHON_ENV_NAME,
  121. COVERAGE_TS_ENV_NAME,
  122. )
  123. PYTHON_COVERAGE_PREFIX_FILTER_ENV_NAME = 'PYTHON_COVERAGE_PREFIX_FILTER'
  124. PYTHON_COVERAGE_EXCLUDE_REGEXP_ENV_NAME = 'PYTHON_COVERAGE_EXCLUDE_REGEXP'
  125. # TODO get rid of this list - resolve nodes should be added automatically depending on the lang of the target module and their deps
  126. CLANG_COVERAGE_TEST_TYPES = (
  127. "boost_test",
  128. "coverage_extractor",
  129. "exectest",
  130. "fuzz",
  131. "gtest",
  132. "go_test",
  133. # java tests might use shared libraries
  134. "java",
  135. "py2test",
  136. "py3test",
  137. "pytest",
  138. "unittest",
  139. )
  140. COVERAGE_TABLE_CHUNKS = 20
  141. COVERAGE_TESTS_TIMEOUT_FACTOR = 1.5
  142. COVERAGE_YT_PROXY = "hahn.yt.yandex.net"
  143. COVERAGE_YT_ROOT_PATH = "//home/codecoverage"
  144. COVERAGE_YT_TABLE_PREFIX = "datatable"
  145. # fuzzing
  146. CORPUS_DATA_FILE_NAME = 'corpus.json'
  147. CORPUS_DATA_ROOT_DIR = 'fuzzing'
  148. CORPUS_DIR_NAME = 'corpus'
  149. FUZZING_COVERAGE_ARGS = ['--sanitize-coverage=trace-div,trace-gep']
  150. FUZZING_COMPRESSION_COEF = 1.1
  151. FUZZING_DEFAULT_TIMEOUT = 3600
  152. FUZZING_FINISHING_TIME = 600
  153. FUZZING_TIMEOUT_RE = re.compile(r'(^|\s)-max_total_time=(?P<max_time>\d+)')
  154. GENERATED_CORPUS_DIR_NAME = 'mined_corpus'
  155. MAX_CORPUS_RESOURCES_ALLOWED = 5
  156. # hermione
  157. HERMIONE_REPORT_DIR_NAME = "hermione-report"
  158. HERMIONE_REPORT_TAR_NAME = HERMIONE_REPORT_DIR_NAME + ".tar"
  159. HERMIONE_REPORT_INDEX_FILE_NAME = "index.html"
  160. HERMIONE_REPORT_DB_URLS_FILE_NAME = "databaseUrls.json"
  161. HERMIONE_TESTS_READ_FILE_NAME = "tests.json"
  162. HERMIONE_TESTS_READ_STDOUT_FILE_NAME = "read_tests.out"
  163. HERMIONE_TESTS_READ_STDERR_FILE_NAME = "read_tests.err"
  164. HERMIONE_TESTS_RUN_FILE_NAME = "test_results.jsonl"
  165. HERMIONE_TESTS_RUN_STDOUT_FILE_NAME = "run_tests.out"
  166. HERMIONE_TESTS_RUN_STDERR_FILE_NAME = "run_tests.err"
  167. # yt
  168. YT_OPERATION_ID_SUBSTITUTION = '$OPERATION_ID'
  169. YT_SANDBOX_ROOT_PREFIX = '$(YT_SANDBOX_ROOT)'
  170. # sandbox
  171. SANDBOX_RUN_TEST_YT_TOKEN_VALUE_NAME = 'YA_MAKE_SANDBOX_RUN_TEST_YT_TOKEN'
  172. # global resources
  173. ANDROID_AVD_ROOT = 'ANDROID_AVD_RESOURCE_GLOBAL'
  174. ANDROID_SDK_ROOT = 'ANDROID_SDK_RESOURCE_GLOBAL'
  175. COVERAGE_PUSH_TOOL_LOCAL = 'USE_SYSTEM_COVERAGE_PUSH_TOOL'
  176. COVERAGE_PUSH_TOOL_RESOURCE = 'COVERAGE_PUSH_TOOL_RESOURCE_GLOBAL'
  177. COVERAGE_PUSH_TOOL_LB_LOCAL = 'USE_SYSTEM_COVERAGE_PUSH_TOOL_LB'
  178. COVERAGE_PUSH_TOOL_LB_RESOURCE = 'COVERAGE_PUSH_TOOL_LB_RESOURCE_GLOBAL'
  179. FLAKE8_PY2_RESOURCE = 'FLAKE8_PY2_RESOURCE_GLOBAL'
  180. FLAKE8_PY3_RESOURCE = 'FLAKE8_PY3_RESOURCE_GLOBAL'
  181. GO_TOOLS_RESOURCE = 'GO_TOOLS_RESOURCE_GLOBAL'
  182. JSTYLE_RUNNER_LIB = 'JSTYLE_LIB_RESOURCE_GLOBAL'
  183. NODEJS_RESOURCE = 'NODEJS_RESOURCE_GLOBAL'
  184. NYC_RESOURCE = 'NYC_RESOURCE_GLOBAL'
  185. RUFF_RESOURCE = 'RUFF_RESOURCE_GLOBAL'
  186. # test_tool resource for host platform.
  187. # source - build/platform/test_tool/host.ya.make.inc.
  188. # always using this test_tool resource except 2 cases:
  189. # 1. when we use TEST_TOOL_TARGET
  190. # 2. when --test-tool-bin passed
  191. TEST_TOOL_HOST = 'TEST_TOOL_HOST_RESOURCE_GLOBAL'
  192. # path to locally built test_tool passed by --test-tool-bin opt
  193. TEST_TOOL_HOST_LOCAL = 'TEST_TOOL_HOST_LOCAL'
  194. # test_tool resource for target platform.
  195. # source - build/platform/test_tool/ya.make.
  196. # The only usage of this resource is running tests under ios emulator
  197. TEST_TOOL_TARGET = 'TEST_TOOL_TARGET_RESOURCE_GLOBAL'
  198. # path to locally built test_tool passed by --test-tool-bin opt
  199. # always same as TEST_TOOL_HOST_LOCAL
  200. # The only usage of this path is running tests under ios emulator
  201. TEST_TOOL_TARGET_LOCAL = 'TEST_TOOL_TARGET_LOCAL'
  202. XCODE_TOOLS_RESOURCE = 'XCODE_TOOLS_ROOT_RESOURCE_GLOBAL'
  203. WINE_TOOL = 'WINE_TOOL_RESOURCE_GLOBAL'
  204. WINE32_TOOL = 'WINE32_TOOL_RESOURCE_GLOBAL'
  205. class Enum(object):
  206. @classmethod
  207. def enumerate(cls):
  208. return [v for k, v in cls.__dict__.items() if not k.startswith("_")]
  209. class TestRequirements(Enum):
  210. Container = 'container'
  211. Cpu = 'cpu'
  212. DiskUsage = 'disk_usage'
  213. Dns = 'dns'
  214. Kvm = 'kvm'
  215. Network = 'network'
  216. Ram = 'ram'
  217. RamDisk = 'ram_disk'
  218. SbVault = 'sb_vault'
  219. YavSecret = 'yav'
  220. class TestRequirementsConstants(Enum):
  221. All = 'all'
  222. AllCpuValue = 50
  223. AllRamDiskValue = 50
  224. MinCpu = 1
  225. MinRam = 1
  226. MinRamDisk = 0
  227. @classmethod
  228. def is_all_cpu(cls, value):
  229. return value == cls.All
  230. @classmethod
  231. def get_cpu_value(cls, value):
  232. return cls.AllCpuValue if cls.is_all_cpu(value) else value
  233. @classmethod
  234. def is_all_ram_disk(cls, value):
  235. return value == cls.All
  236. @classmethod
  237. def get_ram_disk_value(cls, value):
  238. return cls.AllRamDiskValue if cls.is_all_ram_disk(value) else value
  239. class TestSize(Enum):
  240. Small = 'small'
  241. Medium = 'medium'
  242. Large = 'large'
  243. DefaultTimeouts = {
  244. Small: 60,
  245. Medium: 600,
  246. Large: 3600,
  247. }
  248. DefaultPriorities = {
  249. Small: -1,
  250. Medium: -2,
  251. Large: -3,
  252. }
  253. DefaultRequirements = {
  254. Small: {
  255. TestRequirements.Cpu: 1,
  256. TestRequirements.Ram: 8,
  257. # TestRequirements.Ram: 2,
  258. TestRequirements.RamDisk: 0,
  259. },
  260. Medium: {
  261. TestRequirements.Cpu: 1,
  262. TestRequirements.Ram: 8,
  263. # TestRequirements.Ram: 4,
  264. TestRequirements.RamDisk: 0,
  265. },
  266. Large: {
  267. TestRequirements.Cpu: 1,
  268. TestRequirements.Ram: 8,
  269. # TestRequirements.Ram: 8,
  270. TestRequirements.RamDisk: 0,
  271. },
  272. }
  273. MaxRequirements = {
  274. Small: {
  275. TestRequirements.Cpu: 4,
  276. TestRequirements.Ram: 32,
  277. # TestRequirements.Ram: 4,
  278. TestRequirements.RamDisk: 32,
  279. },
  280. Medium: {
  281. TestRequirements.Cpu: 4,
  282. # TestRequirements.Cpu: 8,
  283. TestRequirements.Ram: 32,
  284. # TestRequirements.Ram: 16,
  285. TestRequirements.RamDisk: 32,
  286. },
  287. Large: {
  288. TestRequirements.Cpu: 4,
  289. TestRequirements.Ram: 32,
  290. TestRequirements.RamDisk: 32,
  291. },
  292. }
  293. LargeMarker = "TL"
  294. MediumMarker = "TM"
  295. SmallMarker = "TS"
  296. SizeMarkers = (LargeMarker, MediumMarker, SmallMarker)
  297. SizeShorthandMap = {
  298. Large: LargeMarker,
  299. Medium: MediumMarker,
  300. Small: SmallMarker,
  301. }
  302. @classmethod
  303. def sizes(cls):
  304. return cls.DefaultTimeouts.keys()
  305. @classmethod
  306. def get_shorthand(cls, size):
  307. return cls.SizeShorthandMap[size]
  308. @classmethod
  309. def is_test_shorthand(cls, name):
  310. return name in cls.SizeMarkers
  311. @classmethod
  312. def get_default_timeout(cls, size):
  313. if size in cls.DefaultTimeouts:
  314. return cls.DefaultTimeouts[size]
  315. raise Exception("Unknown test size '{}'".format(size))
  316. @classmethod
  317. def get_default_priorities(cls, size):
  318. if size in cls.DefaultPriorities:
  319. return cls.DefaultPriorities[size]
  320. raise Exception("Unknown test size '{}'".format(size))
  321. @classmethod
  322. def get_default_requirements(cls, size):
  323. if size in cls.DefaultRequirements:
  324. return cls.DefaultRequirements[size]
  325. raise Exception("Unknown test size '{}'".format(size))
  326. @classmethod
  327. def get_max_requirements(cls, size):
  328. if size in cls.MaxRequirements:
  329. return cls.MaxRequirements[size]
  330. raise Exception("Unknown test size '{}'".format(size))
  331. class ModuleLang(Enum):
  332. ABSENT = "absent"
  333. NUMEROUS = "numerous"
  334. UNKNOWN = "unknown"
  335. CPP = "cpp"
  336. DOCS = "docs"
  337. GO = "go"
  338. JAVA = "java"
  339. KOTLIN = "kotlin"
  340. PY = "py"
  341. TS = "ts"
  342. class NodeType(Enum):
  343. TEST = "test"
  344. TEST_AUX = "test-aux"
  345. TEST_RESULTS = "test-results"
  346. DOWNLOAD = "download"
  347. class TestRunExitCode(Enum):
  348. Skipped = 2
  349. Failed = 3
  350. TimeOut = 10
  351. InfrastructureError = 12
  352. class YaTestTags(Enum):
  353. AlwaysMinimize = "ya:always_minimize"
  354. Dirty = "ya:dirty"
  355. DumpNodeEnvironment = "ya:dump_node_env"
  356. DumpTestEnvironment = "ya:dump_test_env"
  357. ExoticPlatform = "ya:exotic_platform"
  358. External = "ya:external"
  359. Fat = "ya:fat"
  360. ForceDistbuild = "ya:force_distbuild"
  361. ForceSandbox = "ya:force_sandbox"
  362. GoNoSubtestReport = "ya:go_no_subtest_report"
  363. GoTotalReport = "ya:go_total_report"
  364. HugeLogs = "ya:huge_logs"
  365. Manual = "ya:manual"
  366. MapRootUser = "ya:map_root_user"
  367. NoGracefulShutdown = "ya:no_graceful_shutdown"
  368. Norestart = "ya:norestart"
  369. Noretries = "ya:noretries"
  370. NotAutocheck = "ya:not_autocheck"
  371. Notags = "ya:notags"
  372. PerfTest = "ya:perftest"
  373. Privileged = "ya:privileged"
  374. ReportChunks = "ya:report_chunks"
  375. RunWithAsserts = "ya:relwithdebinfo"
  376. SandboxCoverage = "ya:sandbox_coverage"
  377. SequentialRun = "ya:sequential_run"
  378. TraceOutput = "ya:trace_output"
  379. YtRunner = "ya:yt"
  380. CopyData = "ya:copydata"
  381. CopyDataRO = "ya:copydataro"
  382. NoPstreeTrim = "ya:no_pstree_trim"
  383. class ServiceTags(Enum):
  384. AnyTag = "ya:anytag"
  385. class Status(object):
  386. GOOD, XFAIL, FAIL, XPASS, MISSING, CRASHED, TIMEOUT = range(1, 8)
  387. SKIPPED = -100
  388. NOT_LAUNCHED = -200
  389. CANON_DIFF = -300
  390. DESELECTED = -400
  391. INTERNAL = -int(2**31 - 1) # maxint
  392. FLAKY = -50
  393. # XFAILDIFF is internal status and should be replaced
  394. # with XFAIL or XPASS during verification stage of canon data
  395. XFAILDIFF = -90
  396. BY_NAME = {
  397. 'crashed': CRASHED,
  398. 'deselected': DESELECTED,
  399. 'diff': CANON_DIFF,
  400. 'fail': FAIL,
  401. 'flaky': FLAKY,
  402. 'good': GOOD,
  403. 'internal': INTERNAL,
  404. 'missing': MISSING,
  405. 'not_launched': NOT_LAUNCHED,
  406. 'skipped': SKIPPED,
  407. 'timeout': TIMEOUT,
  408. 'xfail': XFAIL,
  409. 'xfaildiff': XFAILDIFF,
  410. 'xpass': XPASS,
  411. }
  412. TO_STR = {
  413. CANON_DIFF: 'diff',
  414. CRASHED: 'crashed',
  415. DESELECTED: 'deselected',
  416. FAIL: 'fail',
  417. FLAKY: 'flaky',
  418. GOOD: 'good',
  419. INTERNAL: 'internal',
  420. MISSING: 'missing',
  421. NOT_LAUNCHED: 'not_launched',
  422. SKIPPED: 'skipped',
  423. TIMEOUT: 'timeout',
  424. XFAIL: 'xfail',
  425. XFAILDIFF: 'xfaildiff',
  426. XPASS: 'xpass',
  427. }
  428. class _Colors(object):
  429. _NAMES = [
  430. "blue",
  431. "cyan",
  432. "default",
  433. "green",
  434. "grey",
  435. "magenta",
  436. "red",
  437. "white",
  438. "yellow",
  439. ]
  440. _PREFIXES = ["", "light", "dark"]
  441. def __init__(self):
  442. self._table = {}
  443. for prefix in self._PREFIXES:
  444. for value in self._NAMES:
  445. name = value
  446. if prefix:
  447. name = "{}_{}".format(prefix, value)
  448. value = "{}-{}".format(prefix, value)
  449. self.__add_color(name.upper(), value)
  450. def __add_color(self, name, value):
  451. self._table[name] = value
  452. self.__setattr__(name, value)
  453. Colors = _Colors()
  454. class _Highlight(object):
  455. _MARKERS = {
  456. # special
  457. "RESET": "rst",
  458. "IMPORTANT": "imp",
  459. "UNIMPORTANT": "unimp",
  460. "BAD": "bad",
  461. "WARNING": "warn",
  462. "GOOD": "good",
  463. "PATH": "path",
  464. "ALTERNATIVE1": "alt1",
  465. "ALTERNATIVE2": "alt2",
  466. "ALTERNATIVE3": "alt3",
  467. }
  468. def __init__(self):
  469. # setting attributes because __getattr__ is much slower
  470. for attr, value in self._MARKERS.items():
  471. self.__setattr__(attr, value)
  472. Highlight = _Highlight()
  473. class _StatusColorMap(object):
  474. # There should be no XFAILDIFF, because it's internal status.
  475. # It should be replaced with XFAIL or XPASS during verification of canon data.
  476. _MAP = {
  477. 'crashed': Highlight.WARNING,
  478. 'deselected': Highlight.UNIMPORTANT,
  479. 'diff': Highlight.BAD,
  480. 'fail': Highlight.BAD,
  481. 'flaky': Highlight.ALTERNATIVE3,
  482. 'good': Highlight.GOOD,
  483. 'internal': Highlight.BAD,
  484. 'missing': Highlight.ALTERNATIVE1,
  485. 'not_launched': Highlight.BAD,
  486. 'skipped': Highlight.UNIMPORTANT,
  487. 'timeout': Highlight.BAD,
  488. 'xfail': Highlight.WARNING,
  489. 'xpass': Highlight.WARNING,
  490. }
  491. def __getitem__(self, item):
  492. return self._MAP[item]
  493. StatusColorMap = _StatusColorMap()