aboutsummaryrefslogtreecommitdiffstats
path: root/build/plugins/tests
diff options
context:
space:
mode:
authoralexv-smirnov <alex@ydb.tech>2023-06-13 11:05:01 +0300
committeralexv-smirnov <alex@ydb.tech>2023-06-13 11:05:01 +0300
commitbf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0 (patch)
tree1d1df72c0541a59a81439842f46d95396d3e7189 /build/plugins/tests
parent8bfdfa9a9bd19bddbc58d888e180fbd1218681be (diff)
downloadydb-bf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0.tar.gz
add ymake export to ydb
Diffstat (limited to 'build/plugins/tests')
-rw-r--r--build/plugins/tests/fake_ymake.py2
-rw-r--r--build/plugins/tests/test_code_generator.py25
-rw-r--r--build/plugins/tests/test_common.py49
-rw-r--r--build/plugins/tests/test_requirements.py91
-rw-r--r--build/plugins/tests/test_ssqls.py28
-rw-r--r--build/plugins/tests/ya.make25
6 files changed, 220 insertions, 0 deletions
diff --git a/build/plugins/tests/fake_ymake.py b/build/plugins/tests/fake_ymake.py
new file mode 100644
index 0000000000..a20d28525a
--- /dev/null
+++ b/build/plugins/tests/fake_ymake.py
@@ -0,0 +1,2 @@
+def addparser():
+ pass
diff --git a/build/plugins/tests/test_code_generator.py b/build/plugins/tests/test_code_generator.py
new file mode 100644
index 0000000000..7f3267a55e
--- /dev/null
+++ b/build/plugins/tests/test_code_generator.py
@@ -0,0 +1,25 @@
+import sys
+from build.plugins.tests import fake_ymake
+
+sys.modules['ymake'] = fake_ymake
+
+from build.plugins import code_generator
+
+
+def test_include_parser():
+ template_file = """
+ @ from 'util/namespace.macro' import namespace, change_namespace, close_namespaces
+ @ import 'market/tools/code_generator/templates/serialization/json.macro' as json
+ @ import 'market/tools/code_generator/templates/serialization/request_parameters.macro' as rp
+ #include <sss/abcdefg.h>
+ #include<fff/asd>
+ #include "hhh/quququ.h"
+ """
+
+ includes, induced = code_generator.CodeGeneratorTemplateParser.parse_includes(template_file.split('\n'))
+ assert includes == [
+ 'util/namespace.macro',
+ 'market/tools/code_generator/templates/serialization/json.macro',
+ 'market/tools/code_generator/templates/serialization/request_parameters.macro',
+ ]
+ assert induced == ['sss/abcdefg.h', 'fff/asd', 'hhh/quququ.h']
diff --git a/build/plugins/tests/test_common.py b/build/plugins/tests/test_common.py
new file mode 100644
index 0000000000..e1780354f8
--- /dev/null
+++ b/build/plugins/tests/test_common.py
@@ -0,0 +1,49 @@
+import pytest
+
+import build.plugins._common as pc
+
+
+def test_sort_by_keywords():
+ keywords = {'KEY1': 2, 'KEY2': 0, 'KEY3': 1}
+ args = 'aaaa bbbb KEY2 KEY1 kkk10 kkk11 ccc ddd KEY3 kkk3 eee'.split()
+ flat, spec = pc.sort_by_keywords(keywords, args)
+ assert flat == ['aaaa', 'bbbb', 'ccc', 'ddd', 'eee']
+ assert spec == {'KEY1': ['kkk10', 'kkk11'], 'KEY2': True, 'KEY3': ['kkk3']}
+
+ keywords = {'KEY1': 0, 'KEY2': 4}
+ args = 'aaaa KEY2 eee'.split()
+ flat, spec = pc.sort_by_keywords(keywords, args)
+ assert flat == ['aaaa']
+ assert spec == {'KEY2': ['eee']}
+
+ keywords = {'KEY1': 2, 'KEY2': 2}
+ args = 'KEY1 k10 KEY2 k20 KEY1 k11 KEY2 k21 KEY1 k13'.split()
+ flat, spec = pc.sort_by_keywords(keywords, args)
+ assert flat == []
+ assert spec == {'KEY1': ['k10', 'k11', 'k13'], 'KEY2': ['k20', 'k21']}
+
+
+def test_filter_out_by_keyword():
+ assert pc.filter_out_by_keyword([], 'A') == []
+ assert pc.filter_out_by_keyword(['x'], 'A') == ['x']
+ assert pc.filter_out_by_keyword(['x', 'A'], 'A') == ['x']
+ assert pc.filter_out_by_keyword(['x', 'A', 'B'], 'A') == ['x']
+ assert pc.filter_out_by_keyword(['x', 'A', 'B', 'y'], 'A') == ['x', 'y']
+ assert pc.filter_out_by_keyword(['x', 'A', 'A', 'y'], 'A') == ['x', 'y']
+ assert pc.filter_out_by_keyword(['x', 'A', 'A', 'A'], 'A') == ['x']
+ assert pc.filter_out_by_keyword(['x', 'A', 'A', 'A', 'B', 'y'], 'A') == ['x', 'y']
+ assert pc.filter_out_by_keyword(['x', 'A', 'A', 'A', 'B', 'y', 'A'], 'A') == ['x', 'y']
+ assert pc.filter_out_by_keyword(['x', 'A', 'A', 'A', 'B', 'y', 'A', 'F', 'z'], 'A') == ['x', 'y', 'z']
+
+
+test_data = [
+ [[1, 2, 3], 1, [[1], [2], [3]]],
+ [[1, 2, 3], 2, [[1, 2], [3]]],
+ [[1, 2, 3, 4], 2, [[1, 2], [3, 4]]],
+ [[1], 5, [[1]]],
+]
+
+
+@pytest.mark.parametrize('lst, chunk_size, expected', test_data, ids=[str(num + 1) for num in range(len(test_data))])
+def test_generate_chunks(lst, chunk_size, expected):
+ assert list(pc.generate_chunks(lst, chunk_size)) == expected
diff --git a/build/plugins/tests/test_requirements.py b/build/plugins/tests/test_requirements.py
new file mode 100644
index 0000000000..0c41fbaad0
--- /dev/null
+++ b/build/plugins/tests/test_requirements.py
@@ -0,0 +1,91 @@
+import pytest
+
+import build.plugins._requirements as requirements
+import build.plugins.lib.test_const as consts
+
+
+class TestRequirements(object):
+ @pytest.mark.parametrize('test_size', consts.TestSize.sizes())
+ def test_cpu(self, test_size):
+ max_cpu = consts.TestSize.get_max_requirements(test_size).get(consts.TestRequirements.Cpu)
+ min_cpu = consts.TestRequirementsConstants.MinCpu
+ assert requirements.check_cpu(-1, test_size)
+ assert requirements.check_cpu(min_cpu - 1, test_size)
+ assert requirements.check_cpu("unknown", test_size)
+ assert not requirements.check_cpu(1, test_size)
+ assert not requirements.check_cpu(3, test_size)
+ assert requirements.check_cpu(1000, test_size)
+ if max_cpu != consts.TestRequirementsConstants.All:
+ assert requirements.check_cpu(max_cpu + 1, test_size)
+ assert requirements.check_cpu(max_cpu + 4, test_size)
+ assert requirements.check_cpu(consts.TestRequirementsConstants.All, test_size)
+ else:
+ assert not requirements.check_cpu(consts.TestRequirementsConstants.All, test_size)
+
+ @pytest.mark.parametrize('test_size', consts.TestSize.sizes())
+ def test_ram(self, test_size):
+ max_ram = consts.TestSize.get_max_requirements(test_size).get(consts.TestRequirements.Ram)
+ min_ram = consts.TestRequirementsConstants.MinRam
+ assert requirements.check_ram(-1, test_size)
+ assert requirements.check_ram(min_ram - 1, test_size)
+ assert requirements.check_ram(max_ram + 1, test_size)
+ assert not requirements.check_ram(1, test_size)
+ assert not requirements.check_ram(4, test_size)
+ assert not requirements.check_ram(5, test_size)
+ assert not requirements.check_ram(32, consts.TestSize.Large)
+ assert requirements.check_ram(48, consts.TestSize.Large)
+
+ assert not requirements.check_ram(1, test_size, is_kvm=True)
+ assert not requirements.check_ram(4, test_size, is_kvm=True)
+ assert not requirements.check_ram(16, test_size, is_kvm=True)
+ assert requirements.check_ram(32, test_size, is_kvm=True)
+
+ @pytest.mark.parametrize('test_size', consts.TestSize.sizes())
+ def test_ram_disk(self, test_size):
+ max_ram_disk = consts.TestSize.get_max_requirements(test_size).get(consts.TestRequirements.RamDisk)
+ min_ram_disk = consts.TestRequirementsConstants.MinRamDisk
+ assert requirements.check_ram_disk(-1, test_size)
+ assert requirements.check_ram_disk(min_ram_disk - 1, test_size)
+ assert requirements.check_ram_disk(max_ram_disk + 1, test_size)
+ assert requirements.check_ram_disk(33, test_size)
+ assert not requirements.check_ram_disk(32, test_size)
+ assert not requirements.check_ram_disk(1, test_size)
+ assert not requirements.check_ram_disk(4, test_size)
+ assert not requirements.validate_ram_disk_requirement(
+ 'ram_disk', '0', test_size, False, True, False, False, False, 1
+ )
+ assert not requirements.validate_ram_disk_requirement(
+ 'ram_disk', '1', test_size, False, True, False, False, False, 1
+ )
+ assert not requirements.validate_ram_disk_requirement(
+ 'ram_disk', '1', test_size, True, True, False, False, False, 0
+ )
+ assert not requirements.validate_ram_disk_requirement(
+ 'ram_disk', '1', test_size, False, False, False, False, False, 0
+ )
+ if test_size != consts.TestSize.Large:
+ assert requirements.validate_ram_disk_requirement(
+ 'ram_disk', '1', test_size, False, True, False, False, False, 0
+ )
+ assert requirements.validate_ram_disk_requirement(
+ 'ram_disk', '1', test_size, False, True, True, False, False, 0
+ )
+ assert requirements.validate_ram_disk_requirement(
+ 'ram_disk', '1', test_size, False, True, False, True, False, 0
+ )
+ assert requirements.validate_ram_disk_requirement(
+ 'ram_disk', '1', test_size, False, True, False, False, True, 0
+ )
+ else:
+ assert not requirements.validate_ram_disk_requirement(
+ 'ram_disk', '1', test_size, False, True, False, False, False, 0
+ )
+ assert not requirements.validate_ram_disk_requirement(
+ 'ram_disk', '1', test_size, False, True, True, False, False, 0
+ )
+ assert not requirements.validate_ram_disk_requirement(
+ 'ram_disk', '1', test_size, False, True, False, True, False, 0
+ )
+ assert not requirements.validate_ram_disk_requirement(
+ 'ram_disk', '1', test_size, False, True, False, False, True, 0
+ )
diff --git a/build/plugins/tests/test_ssqls.py b/build/plugins/tests/test_ssqls.py
new file mode 100644
index 0000000000..e5daae3a57
--- /dev/null
+++ b/build/plugins/tests/test_ssqls.py
@@ -0,0 +1,28 @@
+import sys
+from build.plugins.tests import fake_ymake
+
+sys.modules['ymake'] = fake_ymake
+
+import xml.etree.cElementTree as ET
+
+from build.plugins import ssqls
+
+
+example = '''\
+<?xml version="1.0" encoding="utf-8"?>
+<DbObject>
+ <include path="A.ssqls">&lt;a.h&gt;</include>
+ <include>"b.h"</include>
+
+ <ancestors>
+ <ancestor path="C.ssqls"/>
+ </ancestors>
+</DbObject>
+'''
+
+
+def test_include_parser():
+ doc = ET.fromstring(example)
+ xmls, headers = ssqls.SSQLSParser.parse_doc(doc)
+ assert headers == ['a.h', 'b.h', 'C.h']
+ assert xmls == ['A.ssqls', 'C.ssqls']
diff --git a/build/plugins/tests/ya.make b/build/plugins/tests/ya.make
new file mode 100644
index 0000000000..0c54899cc9
--- /dev/null
+++ b/build/plugins/tests/ya.make
@@ -0,0 +1,25 @@
+PY2TEST()
+
+OWNER(g:yatool)
+
+PEERDIR(
+ build/plugins
+)
+
+PY_SRCS(
+ fake_ymake.py
+)
+
+TEST_SRCS(
+ test_code_generator.py
+ test_common.py
+ test_requirements.py
+ test_ssqls.py
+)
+
+NO_CHECK_IMPORTS(
+ build.plugins.code_generator
+ build.plugins.ssqls
+)
+
+END()