aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tools/pg-make-test/update-test-status
diff options
context:
space:
mode:
authormaxkovalev <maxkovalev@yandex-team.com>2024-11-02 12:22:02 +0300
committermaxkovalev <maxkovalev@yandex-team.com>2024-11-02 12:36:24 +0300
commitc9afd90243fb7161534fe20c6da35c24a14e905e (patch)
tree6ee0a521a9aabb0df9a2de1acb54afe2ff0568c6 /yql/essentials/tools/pg-make-test/update-test-status
parentc1e88b2643346523bc487519ca3615245fe372d2 (diff)
downloadydb-c9afd90243fb7161534fe20c6da35c24a14e905e.tar.gz
YQL-19206: Move contrib/ydb/library/yql/tools/pg* to yql/essentials/tools/pg*
YQL-19206: Move contrib/ydb/library/yql/tools to yql/essentials/tools commit_hash:4e16a5a9355fc868aa23f7aa8363d8057b912c71
Diffstat (limited to 'yql/essentials/tools/pg-make-test/update-test-status')
-rw-r--r--yql/essentials/tools/pg-make-test/update-test-status/__main__.py88
-rw-r--r--yql/essentials/tools/pg-make-test/update-test-status/ya.make11
2 files changed, 99 insertions, 0 deletions
diff --git a/yql/essentials/tools/pg-make-test/update-test-status/__main__.py b/yql/essentials/tools/pg-make-test/update-test-status/__main__.py
new file mode 100644
index 0000000000..0a1f9852a4
--- /dev/null
+++ b/yql/essentials/tools/pg-make-test/update-test-status/__main__.py
@@ -0,0 +1,88 @@
+import os
+from collections import namedtuple
+from datetime import date
+import csv
+from pathlib import Path
+import re
+import click
+
+
+TestCase = namedtuple('TestCase', 'statements successful ratio')
+
+
+def load_testcases(filename):
+ testcases = {}
+
+ with open(filename, newline='') as infile:
+ reader = csv.DictReader(infile, delimiter=',')
+ for row in reader:
+ testcases[row['testcase']] = TestCase(row['statements'], row['successful'], row['ratio'])
+
+ return testcases
+
+
+reIncrement = re.compile(r'(\d+)(?: ?\(+ ?(\d+)\))?')
+
+
+def format_success_count(old, new):
+ m = reIncrement.search(old)
+ if m is None:
+ return str(new)
+
+ old_count = int(m[1])
+ new_count = int(new)
+
+ if old_count < new_count:
+ return f'{new_count} (+{new_count - old_count})'
+
+ # we need it to keep old increments, if count stays the same
+ if old_count == new_count:
+ return str(old)
+
+ return str(new)
+
+
+reTableRow = re.compile(r'^\|\| \d+ \|')
+
+
+@click.command()
+@click.argument("reportfile", type=str, nargs=1)
+@click.argument("statusfile", type=str, nargs=1)
+def cli(reportfile, statusfile):
+ today = date.today().strftime('%d.%m.%Y')
+
+ testcases = load_testcases(reportfile)
+
+ outfile = Path(statusfile).with_suffix('.tmp')
+ with open(statusfile, 'r') as fin, open(outfile, 'w') as fout:
+ for line in fin:
+ if reTableRow.match(line):
+ testno, testname, stmts_count, success_count, ratio, when_updated, notes = line.split(' | ')
+ try:
+ testcase = testcases[testname]
+ new_success_count = format_success_count(success_count, testcase.successful)
+ fout.write(
+ ' | '.join(
+ [
+ testno,
+ testname,
+ testcase.statements,
+ new_success_count,
+ testcase.ratio,
+ today if new_success_count != success_count else when_updated,
+ notes,
+ ]
+ )
+ )
+ except KeyError:
+ fout.write(line)
+ else:
+ fout.write(line)
+
+ oldfile = Path(statusfile).with_suffix('.old')
+ os.rename(statusfile, oldfile)
+ os.rename(outfile, statusfile)
+
+
+if __name__ == '__main__':
+ cli()
diff --git a/yql/essentials/tools/pg-make-test/update-test-status/ya.make b/yql/essentials/tools/pg-make-test/update-test-status/ya.make
new file mode 100644
index 0000000000..353b8acfc5
--- /dev/null
+++ b/yql/essentials/tools/pg-make-test/update-test-status/ya.make
@@ -0,0 +1,11 @@
+PY3_PROGRAM(update-test-status)
+
+PY_SRCS(
+ __main__.py
+)
+
+PEERDIR(
+ contrib/python/click
+)
+
+END()