_dart_fields.py 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234
  1. import base64
  2. import functools
  3. import json
  4. import operator
  5. import os
  6. import re
  7. import shlex
  8. import sys
  9. from functools import reduce
  10. import six
  11. import ymake
  12. import _common
  13. import lib.test_const as consts
  14. CANON_RESULT_FILE_NAME = 'result.json'
  15. CANON_DATA_DIR_NAME = 'canondata'
  16. CANON_OUTPUT_STORAGE = 'canondata_storage'
  17. KTLINT_CURRENT_EDITOR_CONFIG = "arcadia/build/platform/java/ktlint/.editorconfig"
  18. KTLINT_OLD_EDITOR_CONFIG = "arcadia/build/platform/java/ktlint_old/.editorconfig"
  19. class DartValueError(ValueError):
  20. pass
  21. def create_dart_record(fields, *args):
  22. return reduce(operator.or_, (value for field in fields if (value := field(*args))), {})
  23. def with_fields(fields):
  24. def inner(func):
  25. @functools.wraps(func)
  26. def innermost(*args, **kwargs):
  27. func(fields, *args, **kwargs)
  28. return innermost
  29. return inner
  30. def serialize_list(lst):
  31. lst = list(filter(None, lst))
  32. return '\"' + ';'.join(lst) + '\"' if lst else ''
  33. def deserialize_list(val):
  34. return list(filter(None, val.replace('"', "").split(";")))
  35. def get_unit_list_variable(unit, name):
  36. items = unit.get(name)
  37. if items:
  38. items = items.split(' ')
  39. assert items[0] == "${}".format(name), (items, name)
  40. return items[1:]
  41. return []
  42. def get_values_list(unit, key):
  43. res = map(str.strip, (unit.get(key) or '').replace('$' + key, '').strip().split())
  44. return [r for r in res if r and r not in ['""', "''"]]
  45. def _get_test_tags(unit, spec_args=None):
  46. if spec_args is None:
  47. spec_args = {}
  48. tags = spec_args.get('TAG', []) + get_values_list(unit, 'TEST_TAGS_VALUE')
  49. tags = set(tags)
  50. if unit.get('EXPORT_SEM') == 'yes':
  51. filter_only_tags = sorted(t for t in tags if ':' not in t)
  52. unit.set(['FILTER_ONLY_TEST_TAGS', ' '.join(filter_only_tags)])
  53. # DEVTOOLS-7571
  54. if unit.get('SKIP_TEST_VALUE') and consts.YaTestTags.Fat in tags:
  55. tags.add(consts.YaTestTags.NotAutocheck)
  56. return tags
  57. def format_recipes(data: str | None) -> str:
  58. if not data:
  59. return ""
  60. data = data.replace('"USE_RECIPE_DELIM"', "\n")
  61. data = data.replace("$TEST_RECIPES_VALUE", "")
  62. return data
  63. def prepare_recipes(data: str | None) -> bytes:
  64. formatted = format_recipes(data)
  65. return base64.b64encode(six.ensure_binary(formatted))
  66. def prepare_env(data):
  67. data = data.replace("$TEST_ENV_VALUE", "")
  68. return serialize_list(shlex.split(data))
  69. def get_norm_paths(unit, key):
  70. # return paths without trailing (back)slash
  71. return [x.rstrip('\\/').replace('${ARCADIA_ROOT}/', '') for x in get_values_list(unit, key)]
  72. def _load_canonical_file(filename, unit_path):
  73. try:
  74. with open(filename, 'rb') as results_file:
  75. return json.load(results_file)
  76. except Exception as e:
  77. print("malformed canonical data in {}: {} ({})".format(unit_path, e, filename), file=sys.stderr)
  78. return {}
  79. def _get_resource_from_uri(uri):
  80. m = consts.CANON_MDS_RESOURCE_REGEX.match(uri)
  81. if m:
  82. key = m.group(1)
  83. return "{}:{}".format(consts.MDS_SCHEME, key)
  84. m = consts.CANON_BACKEND_RESOURCE_REGEX.match(uri)
  85. if m:
  86. key = m.group(1)
  87. return "{}:{}".format(consts.MDS_SCHEME, key)
  88. m = consts.CANON_SBR_RESOURCE_REGEX.match(uri)
  89. if m:
  90. # There might be conflict between resources, because all resources in sandbox have 'resource.tar.gz' name
  91. # That's why we use notation with '=' to specify specific path for resource
  92. uri = m.group(1)
  93. res_id = m.group(2)
  94. return "{}={}".format(uri, '/'.join([CANON_OUTPUT_STORAGE, res_id]))
  95. def _get_external_resources_from_canon_data(data):
  96. # Method should work with both canonization versions:
  97. # result.json: {'uri':X 'checksum':Y}
  98. # result.json: {'testname': {'uri':X 'checksum':Y}}
  99. # result.json: {'testname': [{'uri':X 'checksum':Y}]}
  100. # Also there is a bug - if user returns {'uri': 1} from test - machinery will fail
  101. # That's why we check 'uri' and 'checksum' fields presence
  102. # (it's still a bug - user can return {'uri':X, 'checksum': Y}, we need to unify canonization format)
  103. res = set()
  104. if isinstance(data, dict):
  105. if 'uri' in data and 'checksum' in data:
  106. resource = _get_resource_from_uri(data['uri'])
  107. if resource:
  108. res.add(resource)
  109. else:
  110. for k, v in six.iteritems(data):
  111. res.update(_get_external_resources_from_canon_data(v))
  112. elif isinstance(data, list):
  113. for e in data:
  114. res.update(_get_external_resources_from_canon_data(e))
  115. return res
  116. def _get_canonical_data_resources_v2(filename, unit_path):
  117. return (_get_external_resources_from_canon_data(_load_canonical_file(filename, unit_path)), [filename])
  118. def get_canonical_test_resources(unit):
  119. unit_path = unit.path()
  120. if unit.get("CUSTOM_CANONDATA_PATH"):
  121. path_to_canondata = unit_path.replace("$S", unit.get("CUSTOM_CANONDATA_PATH"))
  122. else:
  123. path_to_canondata = unit.resolve(unit_path)
  124. canon_data_dir = os.path.join(path_to_canondata, CANON_DATA_DIR_NAME, unit.get('CANONIZE_SUB_PATH') or '')
  125. try:
  126. _, dirs, files = next(os.walk(canon_data_dir))
  127. except StopIteration:
  128. # path doesn't exist
  129. return [], []
  130. if CANON_RESULT_FILE_NAME in files:
  131. return _get_canonical_data_resources_v2(os.path.join(canon_data_dir, CANON_RESULT_FILE_NAME), unit_path)
  132. return [], []
  133. def java_srcdirs_to_data(unit, var, serialize_result=True):
  134. extra_data = []
  135. for srcdir in (unit.get(var) or '').replace('$' + var, '').split():
  136. if srcdir == '.':
  137. srcdir = unit.get('MODDIR')
  138. if srcdir.startswith('${ARCADIA_ROOT}/') or srcdir.startswith('$ARCADIA_ROOT/'):
  139. srcdir = srcdir.replace('${ARCADIA_ROOT}/', '$S/')
  140. srcdir = srcdir.replace('$ARCADIA_ROOT/', '$S/')
  141. if srcdir.startswith('${CURDIR}') or srcdir.startswith('$CURDIR'):
  142. srcdir = srcdir.replace('${CURDIR}', os.path.join('$S', unit.get('MODDIR')))
  143. srcdir = srcdir.replace('$CURDIR', os.path.join('$S', unit.get('MODDIR')))
  144. srcdir = unit.resolve_arc_path(srcdir)
  145. if not srcdir.startswith('$'):
  146. srcdir = os.path.join('$S', unit.get('MODDIR'), srcdir)
  147. if srcdir.startswith('$S'):
  148. extra_data.append(srcdir.replace('$S', 'arcadia'))
  149. return serialize_list(extra_data) if serialize_result else extra_data
  150. def extract_java_system_properties(unit, args):
  151. if len(args) % 2:
  152. return [], 'Wrong use of SYSTEM_PROPERTIES in {}: odd number of arguments'.format(unit.path())
  153. props = []
  154. for x, y in zip(args[::2], args[1::2]):
  155. if x == 'FILE':
  156. if y.startswith('${BINDIR}') or y.startswith('${ARCADIA_BUILD_ROOT}') or y.startswith('/'):
  157. return [], 'Wrong use of SYSTEM_PROPERTIES in {}: absolute/build file path {}'.format(unit.path(), y)
  158. y = _common.rootrel_arc_src(y, unit)
  159. if not os.path.exists(unit.resolve('$S/' + y)):
  160. return [], 'Wrong use of SYSTEM_PROPERTIES in {}: can\'t resolve {}'.format(unit.path(), y)
  161. y = '${ARCADIA_ROOT}/' + y
  162. props.append({'type': 'file', 'path': y})
  163. else:
  164. props.append({'type': 'inline', 'key': x, 'value': y})
  165. return props, None
  166. def _resolve_module_files(unit, mod_dir, file_paths):
  167. mod_dir_with_sep_len = len(mod_dir) + 1
  168. resolved_files = []
  169. for path in file_paths:
  170. resolved = _common.rootrel_arc_src(path, unit)
  171. if resolved.startswith(mod_dir):
  172. resolved = resolved[mod_dir_with_sep_len:]
  173. resolved_files.append(resolved)
  174. return resolved_files
  175. def _resolve_config_path(unit, test_runner, rel_to):
  176. config_path = unit.get("ESLINT_CONFIG_PATH") if test_runner == "eslint" else unit.get("TS_TEST_CONFIG_PATH")
  177. arc_config_path = unit.resolve_arc_path(config_path)
  178. abs_config_path = unit.resolve(arc_config_path)
  179. if not abs_config_path:
  180. raise Exception("{} config not found: {}".format(test_runner, config_path))
  181. unit.onsrcs([arc_config_path])
  182. abs_rel_to = unit.resolve(unit.resolve_arc_path(unit.get(rel_to)))
  183. return os.path.relpath(abs_config_path, start=abs_rel_to)
  184. def _get_ts_test_data_dirs(unit):
  185. return sorted(
  186. set(
  187. [
  188. os.path.dirname(_common.rootrel_arc_src(p, unit))
  189. for p in (get_values_list(unit, "_TS_TEST_DATA_VALUE") or [])
  190. ]
  191. )
  192. )
  193. class AndroidApkTestActivity:
  194. KEY = 'ANDROID_APK_TEST_ACTIVITY'
  195. @classmethod
  196. def value(cls, unit, flat_args, spec_args):
  197. return {cls.KEY: unit.get('ANDROID_APK_TEST_ACTIVITY_VALUE')}
  198. class BenchmarkOpts:
  199. KEY = 'BENCHMARK-OPTS'
  200. @classmethod
  201. def value(cls, unit, flat_args, spec_args):
  202. return {cls.KEY: serialize_list(get_unit_list_variable(unit, 'BENCHMARK_OPTS_VALUE'))}
  203. class BinaryPath:
  204. KEY = 'BINARY-PATH'
  205. @classmethod
  206. def normalized(cls, unit, flat_args, spec_args):
  207. unit_path = _common.get_norm_unit_path(unit)
  208. return {cls.KEY: os.path.join(unit_path, unit.filename())}
  209. @classmethod
  210. def stripped(cls, unit, flat_args, spec_args):
  211. unit_path = unit.path()
  212. binary_path = os.path.join(unit_path, unit.filename())
  213. if binary_path:
  214. return {cls.KEY: _common.strip_roots(binary_path)}
  215. @classmethod
  216. def stripped_without_pkg_ext(cls, unit, flat_args, spec_args):
  217. value = _common.strip_roots(os.path.join(unit.path(), unit.filename()).replace(".pkg", ""))
  218. return {cls.KEY: value}
  219. class Blob:
  220. KEY = 'BLOB'
  221. @classmethod
  222. def value(cls, unit, flat_args, spec_args):
  223. return {cls.KEY: unit.get('TEST_BLOB_DATA')}
  224. class BuildFolderPath:
  225. KEY = 'BUILD-FOLDER-PATH'
  226. @classmethod
  227. def normalized(cls, unit, flat_args, spec_args):
  228. return {cls.KEY: _common.get_norm_unit_path(unit)}
  229. @classmethod
  230. def stripped(cls, unit, flat_args, spec_args):
  231. return {cls.KEY: _common.strip_roots(unit.path())}
  232. class CanonizeSubPath:
  233. KEY = 'CANONIZE_SUB_PATH'
  234. @classmethod
  235. def value(cls, unit, flat_args, spec_args):
  236. return {cls.KEY: unit.get('CANONIZE_SUB_PATH')}
  237. class Classpath:
  238. KEY = 'CLASSPATH'
  239. @classmethod
  240. def value(cls, unit, flat_args, spec_args):
  241. ymake_java_test = unit.get('YMAKE_JAVA_TEST') == 'yes'
  242. if ymake_java_test:
  243. value = '$B/{}/{}.jar ${{DART_CLASSPATH}}'.format(unit.get('MODDIR'), unit.get('REALPRJNAME'))
  244. return {cls.KEY: value}
  245. class ConfigPath:
  246. KEY = 'CONFIG-PATH'
  247. @classmethod
  248. def value(cls, unit, flat_args, spec_args):
  249. test_runner, rel_to = flat_args
  250. return {cls.KEY: _resolve_config_path(unit, test_runner, rel_to=rel_to)}
  251. class CustomDependencies:
  252. KEY = 'CUSTOM-DEPENDENCIES'
  253. @classmethod
  254. def all_standard(cls, unit, flat_args, spec_args):
  255. custom_deps = ' '.join(spec_args.get('DEPENDS', []) + get_values_list(unit, 'TEST_DEPENDS_VALUE'))
  256. return {cls.KEY: custom_deps}
  257. @classmethod
  258. def depends_only(cls, unit, flat_args, spec_args):
  259. return {cls.KEY: " ".join(spec_args.get('DEPENDS', []))}
  260. @classmethod
  261. def test_depends_only(cls, unit, flat_args, spec_args):
  262. custom_deps = get_values_list(unit, 'TEST_DEPENDS_VALUE')
  263. return {cls.KEY: " ".join(custom_deps)}
  264. @classmethod
  265. def depends_with_linter(cls, unit, flat_args, spec_args):
  266. deps = []
  267. _, linter = flat_args
  268. deps.append(os.path.dirname(linter))
  269. deps += spec_args.get('DEPENDS', [])
  270. return {cls.KEY: " ".join(deps)}
  271. @classmethod
  272. def nots_with_recipies(cls, unit, flat_args, spec_args):
  273. deps = flat_args[0]
  274. recipes_lines = format_recipes(unit.get("TEST_RECIPES_VALUE")).strip().splitlines()
  275. if recipes_lines:
  276. deps = deps or []
  277. deps.extend([os.path.dirname(r.strip().split(" ")[0]) for r in recipes_lines])
  278. return {cls.KEY: " ".join(deps)}
  279. class EslintConfigPath:
  280. KEY = 'ESLINT_CONFIG_PATH'
  281. @classmethod
  282. def value(cls, unit, flat_args, spec_args):
  283. test_runner, rel_to = flat_args
  284. return {cls.KEY: _resolve_config_path(unit, test_runner, rel_to=rel_to)}
  285. class ForkMode:
  286. KEY = 'FORK-MODE'
  287. @classmethod
  288. def from_macro_and_unit(cls, unit, flat_args, spec_args):
  289. fork_mode = []
  290. if 'FORK_SUBTESTS' in spec_args:
  291. fork_mode.append('subtests')
  292. if 'FORK_TESTS' in spec_args:
  293. fork_mode.append('tests')
  294. fork_mode = fork_mode or spec_args.get('FORK_MODE', []) or unit.get('TEST_FORK_MODE').split()
  295. fork_mode = ' '.join(fork_mode) if fork_mode else ''
  296. return {cls.KEY: fork_mode}
  297. @classmethod
  298. def test_fork_mode(cls, unit, flat_args, spec_args):
  299. return {cls.KEY: unit.get('TEST_FORK_MODE')}
  300. class ForkTestFiles:
  301. KEY = 'FORK-TEST-FILES'
  302. @classmethod
  303. def value(cls, unit, flat_args, spec_args):
  304. return {cls.KEY: unit.get('FORK_TEST_FILES_MODE')}
  305. class FuzzDicts:
  306. KEY = 'FUZZ-DICTS'
  307. @classmethod
  308. def value(cls, unit, flat_args, spec_args):
  309. value = serialize_list(spec_args.get('FUZZ_DICTS', []) + get_unit_list_variable(unit, 'FUZZ_DICTS_VALUE'))
  310. return {cls.KEY: value}
  311. class FuzzOpts:
  312. KEY = 'FUZZ-OPTS'
  313. @classmethod
  314. def value(cls, unit, flat_args, spec_args):
  315. value = serialize_list(spec_args.get('FUZZ_OPTS', []) + get_unit_list_variable(unit, 'FUZZ_OPTS_VALUE'))
  316. return {cls.KEY: value}
  317. class Fuzzing:
  318. KEY = 'FUZZING'
  319. @classmethod
  320. def value(cls, unit, flat_args, spec_args):
  321. if unit.get('FUZZING') == 'yes':
  322. return {cls.KEY: '1'}
  323. class GlobalLibraryPath:
  324. KEY = 'GLOBAL-LIBRARY-PATH'
  325. @classmethod
  326. def value(cls, unit, flat_args, spec_args):
  327. return {cls.KEY: unit.global_filename()}
  328. class GoBenchTimeout:
  329. KEY = 'GO_BENCH_TIMEOUT'
  330. @classmethod
  331. def value(cls, unit, flat_args, spec_args):
  332. return {cls.KEY: unit.get('GO_BENCH_TIMEOUT')}
  333. class IgnoreClasspathClash:
  334. KEY = 'IGNORE_CLASSPATH_CLASH'
  335. @classmethod
  336. def value(cls, unit, flat_args, spec_args):
  337. value = ' '.join(get_values_list(unit, 'JAVA_IGNORE_CLASSPATH_CLASH_VALUE'))
  338. return {cls.KEY: value}
  339. class JavaClasspathCmdType:
  340. KEY = 'JAVA_CLASSPATH_CMD_TYPE'
  341. @classmethod
  342. def value(cls, unit, flat_args, spec_args):
  343. java_cp_arg_type = unit.get('JAVA_CLASSPATH_CMD_TYPE_VALUE') or 'MANIFEST'
  344. if java_cp_arg_type not in ('MANIFEST', 'COMMAND_FILE', 'LIST'):
  345. # TODO move error reporting out of field classes
  346. ymake.report_configure_error(
  347. '{}: TEST_JAVA_CLASSPATH_CMD_TYPE({}) are invalid. Choose argument from MANIFEST, COMMAND_FILE or LIST)'.format(
  348. unit.path(), java_cp_arg_type
  349. )
  350. )
  351. raise DartValueError
  352. return {cls.KEY: java_cp_arg_type}
  353. class JdkForTests:
  354. KEY = 'JDK_FOR_TESTS'
  355. @classmethod
  356. def value(cls, unit, flat_args, spec_args):
  357. value = 'JDK' + (unit.get('JDK_VERSION') or unit.get('JDK_REAL_VERSION') or '_DEFAULT') + '_FOR_TESTS'
  358. return {cls.KEY: value}
  359. class JdkLatestVersion:
  360. KEY = 'JDK_LATEST_VERSION'
  361. @classmethod
  362. def value(cls, unit, flat_args, spec_args):
  363. return {cls.KEY: unit.get('JDK_LATEST_VERSION')}
  364. class JdkResource:
  365. KEY = 'JDK_RESOURCE'
  366. @classmethod
  367. def value(cls, unit, flat_args, spec_args):
  368. value = 'JDK' + (unit.get('JDK_VERSION') or unit.get('JDK_REAL_VERSION') or '_DEFAULT')
  369. return {cls.KEY: value}
  370. class KtlintBaselineFile:
  371. KEY = 'KTLINT_BASELINE_FILE'
  372. @classmethod
  373. def value(cls, unit, flat_args, spec_args):
  374. if unit.get('_USE_KTLINT_OLD') != 'yes':
  375. baseline_path_relative = unit.get('_KTLINT_BASELINE_FILE')
  376. if baseline_path_relative:
  377. return {cls.KEY: baseline_path_relative}
  378. class KtlintBinary:
  379. KEY = 'KTLINT_BINARY'
  380. @classmethod
  381. def value(cls, unit, flat_args, spec_args):
  382. value = '$(KTLINT_OLD)/run.bat' if unit.get('_USE_KTLINT_OLD') == 'yes' else '$(KTLINT)/run.bat'
  383. return {cls.KEY: value}
  384. class LintFileProcessingTime:
  385. KEY = 'LINT-FILE-PROCESSING-TIME'
  386. class ModuleLang:
  387. KEY = 'MODULE_LANG'
  388. @classmethod
  389. def value(cls, unit, flat_args, spec_args):
  390. return {cls.KEY: unit.get("MODULE_LANG").lower() or consts.ModuleLang.UNKNOWN}
  391. class ModuleType:
  392. KEY = 'MODULE_TYPE'
  393. @classmethod
  394. def value(cls, unit, flat_args, spec_args):
  395. return {cls.KEY: unit.get('MODULE_TYPE')}
  396. class NoCheck:
  397. KEY = 'NO-CHECK'
  398. @classmethod
  399. def value(cls, unit, flat_args, spec_args):
  400. if unit.get('NO_CHECK_IMPORTS_FOR_VALUE') != "None":
  401. value = serialize_list(get_values_list(unit, 'NO_CHECK_IMPORTS_FOR_VALUE') or ["*"])
  402. return {cls.KEY: value}
  403. class NodejsRootVarName:
  404. KEY = 'NODEJS-ROOT-VAR-NAME'
  405. @classmethod
  406. def value(cls, unit, flat_args, spec_args):
  407. return {cls.KEY: unit.get("NODEJS-ROOT-VAR-NAME")}
  408. class NodeModulesBundleFilename:
  409. KEY = 'NODE-MODULES-BUNDLE-FILENAME'
  410. @classmethod
  411. def value(cls, unit, flat_args, spec_args):
  412. return {cls.KEY: spec_args.get('nm_bundle')}
  413. class PythonPaths:
  414. KEY = 'PYTHON-PATHS'
  415. @classmethod
  416. def value(cls, unit, flat_args, spec_args):
  417. python_paths = get_values_list(unit, 'TEST_PYTHON_PATH_VALUE')
  418. return {cls.KEY: serialize_list(python_paths)}
  419. class Requirements:
  420. KEY = 'REQUIREMENTS'
  421. @classmethod
  422. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  423. test_requirements = spec_args.get('REQUIREMENTS', []) + get_values_list(unit, 'TEST_REQUIREMENTS_VALUE')
  424. return {cls.KEY: serialize_list(test_requirements)}
  425. @classmethod
  426. def with_maybe_fuzzing(cls, unit, flat_args, spec_args):
  427. test_requirements = serialize_list(
  428. spec_args.get('REQUIREMENTS', []) + get_values_list(unit, 'TEST_REQUIREMENTS_VALUE')
  429. )
  430. if unit.get('FUZZING') == 'yes':
  431. value = serialize_list(filter(None, deserialize_list(test_requirements) + ["cpu:all", "ram:all"]))
  432. return {cls.KEY: value}
  433. else:
  434. return {cls.KEY: test_requirements}
  435. @classmethod
  436. def from_macro_args(cls, unit, flat_args, spec_args):
  437. value = " ".join(spec_args.get('REQUIREMENTS', []))
  438. return {cls.KEY: value}
  439. @classmethod
  440. def from_unit(cls, unit, flat_args, spec_args):
  441. requirements = get_values_list(unit, 'TEST_REQUIREMENTS_VALUE')
  442. return {cls.KEY: serialize_list(requirements)}
  443. @classmethod
  444. def from_unit_with_full_network(cls, unit, flat_args, spec_args):
  445. requirements = sorted(set(["network:full"] + get_values_list(unit, "TEST_REQUIREMENTS_VALUE")))
  446. return {cls.KEY: serialize_list(requirements)}
  447. class SbrUidExt:
  448. KEY = 'SBR-UID-EXT'
  449. @classmethod
  450. def value(cls, unit, flat_args, spec_args):
  451. uid_ext = unit.get("SBR_UID_EXT").split(" ", 1)[-1] # strip variable name
  452. return {cls.KEY: uid_ext}
  453. class ScriptRelPath:
  454. KEY = 'SCRIPT-REL-PATH'
  455. @classmethod
  456. def second_flat(cls, unit, flat_args, spec_args):
  457. return {cls.KEY: flat_args[1]}
  458. @classmethod
  459. def first_flat(cls, unit, flat_args, spec_args):
  460. return {cls.KEY: flat_args[0]}
  461. @classmethod
  462. def pytest(cls, unit, flat_args, spec_args):
  463. return {cls.KEY: 'py3test.bin' if (unit.get("PYTHON3") == 'yes') else "pytest.bin"}
  464. @classmethod
  465. def junit(cls, unit, flat_args, spec_args):
  466. return {cls.KEY: 'junit5.test' if unit.get('MODULE_TYPE') == 'JUNIT5' else 'junit.test'}
  467. class Size:
  468. KEY = 'SIZE'
  469. @classmethod
  470. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  471. return {cls.KEY: ''.join(spec_args.get('SIZE', [])) or unit.get('TEST_SIZE_NAME')}
  472. @classmethod
  473. def from_unit(cls, unit, flat_args, spec_args):
  474. return {cls.KEY: unit.get('TEST_SIZE_NAME')}
  475. class SkipTest:
  476. KEY = 'SKIP_TEST'
  477. @classmethod
  478. def value(cls, unit, flat_args, spec_args):
  479. return {cls.KEY: unit.get('SKIP_TEST_VALUE')}
  480. class SourceFolderPath:
  481. KEY = 'SOURCE-FOLDER-PATH'
  482. @classmethod
  483. def normalized(cls, unit, flat_args, spec_args):
  484. return {cls.KEY: _common.get_norm_unit_path(unit)}
  485. @classmethod
  486. def test_dir(cls, unit, flat_args, spec_args):
  487. test_dir = _common.get_norm_unit_path(unit)
  488. test_files = flat_args[1:]
  489. if test_files:
  490. test_dir = os.path.dirname(test_files[0]).lstrip("$S/")
  491. return {cls.KEY: test_dir}
  492. class SplitFactor:
  493. KEY = 'SPLIT-FACTOR'
  494. @classmethod
  495. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  496. value = ''.join(spec_args.get('SPLIT_FACTOR', [])) or unit.get('TEST_SPLIT_FACTOR')
  497. return {cls.KEY: value}
  498. @classmethod
  499. def from_unit(cls, unit, flat_args, spec_args):
  500. return {cls.KEY: unit.get('TEST_SPLIT_FACTOR')}
  501. class Tag:
  502. KEY = 'TAG'
  503. @classmethod
  504. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  505. tags = serialize_list(sorted(_get_test_tags(unit, spec_args)))
  506. return {cls.KEY: tags}
  507. @classmethod
  508. def from_unit(cls, unit, flat_args, spec_args):
  509. tags = serialize_list(get_values_list(unit, "TEST_TAGS_VALUE"))
  510. return {cls.KEY: tags}
  511. @classmethod
  512. def from_unit_fat_external_no_retries(cls, unit, flat_args, spec_args):
  513. tags = sorted(set(["ya:fat", "ya:external", "ya:noretries"] + get_values_list(unit, "TEST_TAGS_VALUE")))
  514. return {cls.KEY: serialize_list(tags)}
  515. class TestClasspath:
  516. KEY = 'TEST_CLASSPATH'
  517. @classmethod
  518. def value(cls, unit, flat_args, spec_args):
  519. test_classpath_origins = unit.get('TEST_CLASSPATH_VALUE')
  520. ymake_java_test = unit.get('YMAKE_JAVA_TEST') == 'yes'
  521. if test_classpath_origins:
  522. value = '${TEST_CLASSPATH_MANAGED}'
  523. return {cls.KEY: value}
  524. elif ymake_java_test:
  525. value = '${DART_CLASSPATH}'
  526. return {cls.KEY: value}
  527. class TestClasspathDeps:
  528. KEY = 'TEST_CLASSPATH_DEPS'
  529. @classmethod
  530. def value(cls, unit, flat_args, spec_args):
  531. test_classpath_origins = unit.get('TEST_CLASSPATH_VALUE')
  532. ymake_java_test = unit.get('YMAKE_JAVA_TEST') == 'yes'
  533. if not test_classpath_origins and ymake_java_test:
  534. return {cls.KEY: '${DART_CLASSPATH_DEPS}'}
  535. class TestClasspathOrigins:
  536. KEY = 'TEST_CLASSPATH_ORIGINS'
  537. @classmethod
  538. def value(cls, unit, flat_args, spec_args):
  539. test_classpath_origins = unit.get('TEST_CLASSPATH_VALUE')
  540. if test_classpath_origins:
  541. return {cls.KEY: test_classpath_origins}
  542. class TestCwd:
  543. KEY = 'TEST-CWD'
  544. @classmethod
  545. def from_unit(cls, unit, flat_args, spec_args):
  546. test_cwd = unit.get('TEST_CWD_VALUE') # TODO: validate test_cwd value
  547. return {cls.KEY: test_cwd}
  548. @classmethod
  549. def keywords_replaced(cls, unit, flat_args, spec_args):
  550. test_cwd = unit.get('TEST_CWD_VALUE') or ''
  551. if test_cwd:
  552. test_cwd = test_cwd.replace("$TEST_CWD_VALUE", "").replace('"MACRO_CALLS_DELIM"', "").strip()
  553. return {cls.KEY: test_cwd}
  554. @classmethod
  555. def moddir(cls, unit, flat_args, spec_args):
  556. return {cls.KEY: unit.get("MODDIR")}
  557. class TestData:
  558. KEY = 'TEST-DATA'
  559. @classmethod
  560. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  561. test_data = sorted(
  562. _common.filter_out_by_keyword(
  563. spec_args.get('DATA', []) + get_norm_paths(unit, 'TEST_DATA_VALUE'), 'AUTOUPDATED'
  564. )
  565. )
  566. return {cls.KEY: serialize_list(test_data)}
  567. @classmethod
  568. def from_macro_args_and_unit_with_canonical(cls, unit, flat_args, spec_args):
  569. test_data = sorted(
  570. _common.filter_out_by_keyword(
  571. spec_args.get('DATA', []) + get_norm_paths(unit, 'TEST_DATA_VALUE'), 'AUTOUPDATED'
  572. )
  573. )
  574. data, _ = get_canonical_test_resources(unit)
  575. test_data += data
  576. value = serialize_list(sorted(test_data))
  577. return {cls.KEY: value}
  578. @classmethod
  579. def ktlint(cls, unit, flat_args, spec_args):
  580. if unit.get('_USE_KTLINT_OLD') == 'yes':
  581. extra_test_data = [KTLINT_OLD_EDITOR_CONFIG]
  582. else:
  583. data_list = [KTLINT_CURRENT_EDITOR_CONFIG]
  584. baseline_path_relative = unit.get('_KTLINT_BASELINE_FILE')
  585. if baseline_path_relative:
  586. baseline_path = unit.resolve_arc_path(baseline_path_relative).replace('$S', 'arcadia')
  587. data_list += [baseline_path]
  588. extra_test_data = data_list
  589. # XXX
  590. if unit.get('_WITH_YA_1931') != 'yes':
  591. extra_test_data += java_srcdirs_to_data(unit, 'ALL_SRCDIRS', serialize_result=False)
  592. extra_test_data = serialize_list(extra_test_data)
  593. return {cls.KEY: extra_test_data}
  594. @classmethod
  595. def java_style(cls, unit, flat_args, spec_args):
  596. ymake_java_test = unit.get('YMAKE_JAVA_TEST') == 'yes'
  597. if ymake_java_test:
  598. return {cls.KEY: java_srcdirs_to_data(unit, 'ALL_SRCDIRS')}
  599. @classmethod
  600. def from_unit_with_canonical(cls, unit, flat_args, spec_args):
  601. test_data = get_norm_paths(unit, 'TEST_DATA_VALUE')
  602. data, _ = get_canonical_test_resources(unit)
  603. test_data += data
  604. value = serialize_list(sorted(_common.filter_out_by_keyword(test_data, 'AUTOUPDATED')))
  605. return {cls.KEY: value}
  606. @classmethod
  607. def java_test(cls, unit, flat_args, spec_args):
  608. test_data = get_norm_paths(unit, 'TEST_DATA_VALUE')
  609. test_data.append('arcadia/build/scripts/run_junit.py')
  610. test_data.append('arcadia/build/scripts/unpacking_jtest_runner.py')
  611. data, _ = get_canonical_test_resources(unit)
  612. test_data += data
  613. props, error_mgs = extract_java_system_properties(unit, get_values_list(unit, 'SYSTEM_PROPERTIES_VALUE'))
  614. if error_mgs:
  615. # TODO move error reporting out of field classes
  616. ymake.report_configure_error(error_mgs)
  617. raise DartValueError
  618. for prop in props:
  619. if prop['type'] == 'file':
  620. test_data.append(prop['path'].replace('${ARCADIA_ROOT}', 'arcadia'))
  621. value = serialize_list(sorted(_common.filter_out_by_keyword(test_data, 'AUTOUPDATED')))
  622. return {cls.KEY: value}
  623. @classmethod
  624. def from_unit(cls, unit, flat_args, spec_args):
  625. return {cls.KEY: serialize_list(get_values_list(unit, "TEST_DATA_VALUE"))}
  626. class TsConfigPath:
  627. KEY = 'TS_CONFIG_PATH'
  628. class TsStylelintConfig:
  629. KEY = 'TS_STYLELINT_CONFIG'
  630. @classmethod
  631. def value(cls, unit, flat_args, spec_args):
  632. test_config = unit.get('_TS_STYLELINT_CONFIG')
  633. abs_test_config = unit.resolve(unit.resolve_arc_path(test_config))
  634. if not abs_test_config:
  635. ymake.report_configure_error(
  636. f"Config for stylelint not found: {test_config}.\n"
  637. "Set the correct value in `TS_STYLELINT(<config_filename>)` macro in the `ya.make` file."
  638. )
  639. return {cls.KEY: test_config}
  640. class TsTestDataDirs:
  641. KEY = 'TS-TEST-DATA-DIRS'
  642. @classmethod
  643. def value(cls, unit, flat_args, spec_args):
  644. value = serialize_list(_get_ts_test_data_dirs(unit))
  645. return {cls.KEY: value}
  646. class TsTestDataDirsRename:
  647. KEY = 'TS-TEST-DATA-DIRS-RENAME'
  648. @classmethod
  649. def value(cls, unit, flat_args, spec_args):
  650. return {cls.KEY: unit.get("_TS_TEST_DATA_DIRS_RENAME_VALUE")}
  651. class TsTestForPath:
  652. KEY = 'TS-TEST-FOR-PATH'
  653. @classmethod
  654. def value(cls, unit, flat_args, spec_args):
  655. return {cls.KEY: unit.get("TS_TEST_FOR_PATH")}
  656. class TestedProjectFilename:
  657. KEY = 'TESTED-PROJECT-FILENAME'
  658. @classmethod
  659. def value(cls, unit, flat_args, spec_args):
  660. return {cls.KEY: unit.filename()}
  661. class TestedProjectName:
  662. KEY = 'TESTED-PROJECT-NAME'
  663. @classmethod
  664. def unit_name(cls, unit, flat_args, spec_args):
  665. return {cls.KEY: unit.name()}
  666. @classmethod
  667. def normalized_basename(cls, unit, flat_args, spec_args):
  668. test_dir = _common.get_norm_unit_path(unit)
  669. return {cls.KEY: os.path.basename(test_dir)}
  670. @classmethod
  671. def test_dir(cls, unit, flat_args, spec_args):
  672. test_dir = _common.get_norm_unit_path(unit)
  673. test_files = flat_args[1:]
  674. if test_files:
  675. test_dir = os.path.dirname(test_files[0]).lstrip("$S/")
  676. return {cls.KEY: os.path.basename(test_dir)}
  677. @classmethod
  678. def path_filename_basename(cls, unit, flat_args, spec_args):
  679. binary_path = os.path.join(unit.path(), unit.filename())
  680. return {cls.KEY: os.path.basename(binary_path)}
  681. @classmethod
  682. def normalized(cls, unit, flat_args, spec_args):
  683. return {cls.KEY: _common.get_norm_unit_path(unit)}
  684. @classmethod
  685. def path_filename_basename_without_pkg_ext(cls, unit, flat_args, spec_args):
  686. value = os.path.basename(os.path.join(unit.path(), unit.filename()).replace(".pkg", ""))
  687. return {cls.KEY: value}
  688. @classmethod
  689. def filename_without_ext(cls, unit, flat_args, spec_args):
  690. return {cls.KEY: os.path.splitext(unit.filename())[0]}
  691. class TestFiles:
  692. KEY = 'TEST-FILES'
  693. # TODO remove FILES, see DEVTOOLS-7052
  694. KEY2 = 'FILES'
  695. @classmethod
  696. def value(cls, unit, flat_args, spec_args):
  697. data_re = re.compile(r"sbr:/?/?(\d+)=?.*")
  698. data = flat_args[1:]
  699. resources = []
  700. for f in data:
  701. matched = re.match(data_re, f)
  702. if matched:
  703. resources.append(matched.group(1))
  704. value = serialize_list(resources)
  705. return {cls.KEY: value, cls.KEY2: value}
  706. @classmethod
  707. def flat_args_wo_first(cls, unit, flat_args, spec_args):
  708. value = serialize_list(flat_args[1:])
  709. return {cls.KEY: value, cls.KEY2: value}
  710. @classmethod
  711. def java_style(cls, unit, flat_args, spec_args):
  712. test_files = flat_args[1:]
  713. check_level = flat_args[1]
  714. allowed_levels = {
  715. 'base': '/yandex_checks.xml',
  716. 'strict': '/yandex_checks_strict.xml',
  717. 'extended': '/yandex_checks_extended.xml',
  718. 'library': '/yandex_checks_library.xml',
  719. }
  720. if check_level not in allowed_levels:
  721. raise Exception("'{}' is not allowed in LINT(), use one of {}".format(check_level, allowed_levels.keys()))
  722. test_files[0] = allowed_levels[check_level]
  723. value = serialize_list(test_files)
  724. return {cls.KEY: value, cls.KEY2: value}
  725. @classmethod
  726. def normalized(cls, unit, flat_args, spec_args):
  727. value = serialize_list([_common.get_norm_unit_path(unit, unit.filename())])
  728. return {cls.KEY: value, cls.KEY2: value}
  729. @classmethod
  730. def test_srcs(cls, unit, flat_args, spec_args):
  731. test_files = get_values_list(unit, 'TEST_SRCS_VALUE')
  732. return {cls.KEY: serialize_list(test_files)}
  733. @classmethod
  734. def ts_test_srcs(cls, unit, flat_args, spec_args):
  735. test_files = get_values_list(unit, "_TS_TEST_SRCS_VALUE")
  736. test_files = _resolve_module_files(unit, unit.get("MODDIR"), test_files)
  737. return {cls.KEY: serialize_list(test_files)}
  738. @classmethod
  739. def ts_input_files(cls, unit, flat_args, spec_args):
  740. typecheck_files = get_values_list(unit, "TS_INPUT_FILES")
  741. test_files = [_common.resolve_common_const(f) for f in typecheck_files]
  742. return {cls.KEY: serialize_list(test_files)}
  743. @classmethod
  744. def ts_lint_srcs(cls, unit, flat_args, spec_args):
  745. test_files = get_values_list(unit, "_TS_LINT_SRCS_VALUE")
  746. test_files = _resolve_module_files(unit, unit.get("MODDIR"), test_files)
  747. return {cls.KEY: serialize_list(test_files)}
  748. @classmethod
  749. def stylesheets(cls, unit, flat_args, spec_args):
  750. test_files = get_values_list(unit, "_TS_STYLELINT_FILES")
  751. test_files = _resolve_module_files(unit, unit.get("MODDIR"), test_files)
  752. return {cls.KEY: serialize_list(test_files)}
  753. class TestEnv:
  754. KEY = 'TEST-ENV'
  755. @classmethod
  756. def value(cls, unit, flat_args, spec_args):
  757. return {cls.KEY: prepare_env(unit.get("TEST_ENV_VALUE"))}
  758. class TestIosDeviceType:
  759. KEY = 'TEST_IOS_DEVICE_TYPE'
  760. @classmethod
  761. def value(cls, unit, flat_args, spec_args):
  762. return {cls.KEY: unit.get('TEST_IOS_DEVICE_TYPE_VALUE')}
  763. class TestIosRuntimeType:
  764. KEY = 'TEST_IOS_RUNTIME_TYPE'
  765. @classmethod
  766. def value(cls, unit, flat_args, spec_args):
  767. return {cls.KEY: unit.get('TEST_IOS_RUNTIME_TYPE_VALUE')}
  768. class TestJar:
  769. KEY = 'TEST_JAR'
  770. @classmethod
  771. def value(cls, unit, flat_args, spec_args):
  772. test_classpath_origins = unit.get('TEST_CLASSPATH_VALUE')
  773. ymake_java_test = unit.get('YMAKE_JAVA_TEST') == 'yes'
  774. if not test_classpath_origins and ymake_java_test:
  775. if unit.get('UNITTEST_DIR'):
  776. value = '${UNITTEST_MOD}'
  777. else:
  778. value = '{}/{}.jar'.format(unit.get('MODDIR'), unit.get('REALPRJNAME'))
  779. return {cls.KEY: value}
  780. class TestName:
  781. KEY = 'TEST-NAME'
  782. @classmethod
  783. def value(cls, unit, flat_args, spec_args):
  784. return {cls.KEY: flat_args[0]}
  785. @classmethod
  786. def first_flat_with_bench(cls, unit, flat_args, spec_args):
  787. return {cls.KEY: flat_args[0] + '_bench'}
  788. @classmethod
  789. def first_flat(cls, unit, flat_args, spec_args):
  790. return {cls.KEY: flat_args[0].lower()}
  791. @classmethod
  792. def filename_without_ext(cls, unit, flat_args, spec_args):
  793. test_name = os.path.basename(os.path.join(unit.path(), unit.filename()))
  794. return {cls.KEY: os.path.splitext(test_name)[0]}
  795. @classmethod
  796. def normalized_joined_dir_basename(cls, unit, flat_args, spec_args):
  797. path = _common.get_norm_unit_path(unit)
  798. value = '-'.join([os.path.basename(os.path.dirname(path)), os.path.basename(path)])
  799. return {cls.KEY: value}
  800. @classmethod
  801. def normalized_joined_dir_basename_deps(cls, unit, flat_args, spec_args):
  802. path = _common.get_norm_unit_path(unit)
  803. value = '-'.join([os.path.basename(os.path.dirname(path)), os.path.basename(path), 'dependencies']).strip('-')
  804. return {cls.KEY: value}
  805. @classmethod
  806. def filename_without_pkg_ext(cls, unit, flat_args, spec_args):
  807. test_name = os.path.basename(os.path.join(unit.path(), unit.filename()).replace(".pkg", ""))
  808. return {cls.KEY: os.path.splitext(test_name)[0]}
  809. class TestPartition:
  810. KEY = 'TEST_PARTITION'
  811. @classmethod
  812. def value(cls, unit, flat_args, spec_args):
  813. return {cls.KEY: unit.get("TEST_PARTITION")}
  814. class TestRecipes:
  815. KEY = 'TEST-RECIPES'
  816. @classmethod
  817. def value(cls, unit, flat_args, spec_args):
  818. return {cls.KEY: prepare_recipes(unit.get("TEST_RECIPES_VALUE"))}
  819. class TestRunnerBin:
  820. KEY = 'TEST-RUNNER-BIN'
  821. @classmethod
  822. def value(cls, unit, flat_args, spec_args):
  823. runner_bin = spec_args.get('RUNNER_BIN', [None])[0]
  824. if runner_bin:
  825. return {cls.KEY: runner_bin}
  826. class TestTimeout:
  827. KEY = 'TEST-TIMEOUT'
  828. @classmethod
  829. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  830. test_timeout = ''.join(spec_args.get('TIMEOUT', [])) or unit.get('TEST_TIMEOUT') or ''
  831. return {cls.KEY: test_timeout}
  832. @classmethod
  833. def from_unit_with_default(cls, unit, flat_args, spec_args):
  834. timeout = list(filter(None, [unit.get(["TEST_TIMEOUT"])]))
  835. if timeout:
  836. timeout = timeout[0]
  837. else:
  838. timeout = '0'
  839. return {cls.KEY: timeout}
  840. @classmethod
  841. def from_unit(cls, unit, flat_args, spec_args):
  842. return {cls.KEY: unit.get('TEST_TIMEOUT')}
  843. class TsResources:
  844. KEY = "{}-ROOT-VAR-NAME"
  845. @classmethod
  846. def value(cls, unit, flat_args, spec_args):
  847. erm_json = spec_args['erm_json']
  848. ret = {}
  849. for tool in erm_json.list_npm_packages():
  850. tool_resource_label = cls.KEY.format(tool.upper())
  851. tool_resource_value = unit.get(tool_resource_label)
  852. if tool_resource_value:
  853. ret[tool_resource_label] = tool_resource_value
  854. return ret
  855. class JvmArgs:
  856. KEY = 'JVM_ARGS'
  857. @classmethod
  858. def value(cls, unit, flat_args, spec_args):
  859. value = serialize_list(get_values_list(unit, 'JVM_ARGS_VALUE'))
  860. return {cls.KEY: value}
  861. class StrictClasspathClash:
  862. KEY = 'STRICT_CLASSPATH_CLASH'
  863. class SystemProperties:
  864. KEY = 'SYSTEM_PROPERTIES'
  865. @classmethod
  866. def value(cls, unit, flat_args, spec_args):
  867. props, error_mgs = extract_java_system_properties(unit, get_values_list(unit, 'SYSTEM_PROPERTIES_VALUE'))
  868. if error_mgs:
  869. # TODO move error reporting out of field classes
  870. ymake.report_configure_error(error_mgs)
  871. raise DartValueError
  872. props = base64.b64encode(six.ensure_binary(json.dumps(props)))
  873. return {cls.KEY: props}
  874. class UnittestDir:
  875. KEY = 'UNITTEST_DIR'
  876. @classmethod
  877. def value(cls, unit, flat_args, spec_args):
  878. return {cls.KEY: unit.get('UNITTEST_DIR')}
  879. class UseArcadiaPython:
  880. KEY = 'USE_ARCADIA_PYTHON'
  881. @classmethod
  882. def value(cls, unit, flat_args, spec_args):
  883. return {cls.KEY: unit.get('USE_ARCADIA_PYTHON')}
  884. class UseKtlintOld:
  885. KEY = 'USE_KTLINT_OLD'
  886. @classmethod
  887. def value(cls, unit, flat_args, spec_args):
  888. if unit.get('_USE_KTLINT_OLD') == 'yes':
  889. return {cls.KEY: 'yes'}
  890. class YtSpec:
  891. KEY = 'YT-SPEC'
  892. @classmethod
  893. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  894. value = serialize_list(spec_args.get('YT_SPEC', []) + get_unit_list_variable(unit, 'TEST_YT_SPEC_VALUE'))
  895. return {cls.KEY: value}
  896. @classmethod
  897. def from_unit(cls, unit, flat_args, spec_args):
  898. yt_spec = get_values_list(unit, 'TEST_YT_SPEC_VALUE')
  899. if yt_spec:
  900. return {cls.KEY: serialize_list(yt_spec)}
  901. @classmethod
  902. def from_unit_list_var(cls, unit, flat_args, spec_args):
  903. yt_spec_values = get_unit_list_variable(unit, 'TEST_YT_SPEC_VALUE')
  904. return {cls.KEY: serialize_list(yt_spec_values)}