diff options
author | vvvv <vvvv@ydb.tech> | 2023-08-30 20:49:53 +0300 |
---|---|---|
committer | vvvv <vvvv@ydb.tech> | 2023-08-30 21:17:44 +0300 |
commit | f154e22342f327342effe873b0a00ad80c975e76 (patch) | |
tree | fff231496c10fbfcff025ed953b512bf2a82d7c0 /library/python/cyson/ut/test_py_reader_writer.py | |
parent | 4ebafdd49d8b0706c5af76ef7c2d0b3b498d0310 (diff) | |
download | ydb-f154e22342f327342effe873b0a00ad80c975e76.tar.gz |
Moved udf_test and refactored test_framework
Локально упавший тест выполняется
%%
vvvv@mr-nvme-testing-08:~/repo/arcadia/statbox/nile/tests/yql/py2/part_2$ arc checkout move_udf_test_and_refactor_tf
Switched to branch 'move_udf_test_and_refactor_tf'
vvvv@mr-nvme-testing-08:~/repo/arcadia/statbox/nile/tests/yql/py2/part_2$ ya make -tA -F '*test_unchanged_table*'
Warn[-WPluginErr]: in $B/statbox/nile/tests/yql/py2/part_2/libpy2-part_2.so: Requirement cpu is redefined 2 -> 4
Warn[-WPluginErr]: in $B/statbox/nile/tests/yql/py2/part_2/libpy2-part_2.so: Requirement ram is redefined 16 -> 9
Number of suites skipped by name: 2, by filter *test_unchanged_table*
Total 1 suite:
1 - GOOD
Total 4 tests:
4 - GOOD
Ok
%%
судя по ошибке он flaky
Diffstat (limited to 'library/python/cyson/ut/test_py_reader_writer.py')
-rw-r--r-- | library/python/cyson/ut/test_py_reader_writer.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/library/python/cyson/ut/test_py_reader_writer.py b/library/python/cyson/ut/test_py_reader_writer.py new file mode 100644 index 0000000000..0238040f50 --- /dev/null +++ b/library/python/cyson/ut/test_py_reader_writer.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- + +from __future__ import print_function, absolute_import, division + +import pytest +import six + +from cyson import PyWriter, PyReader, dumps, loads, dumps_into + + +if six.PY3: + unicode = str + + +def switch_string_type(string): + if isinstance(string, unicode): + return string.encode('utf8') + elif isinstance(string, bytes): + return string.decode('utf8') + + raise TypeError('expected bytes or unicode, got {!r}'.format(string)) + + +CASES = [ + None, + # int + 0, 1, -1, 2**63, -2**63, 2**64 - 1, + # float + 0.0, 100.0, -100.0, + # long + 10**100, 2**300, -7**100, + # bytes + b'', b'hello', u'Привет'.encode('utf8'), + # unicode + u'', u'hello', u'Привет', + # tuple + (), (0,), (1, 'hello'), (17, 'q') * 100, + # list + [], [0], ['hello', set([1, 2, 3])], [17, 'q'] * 100, + # dict + {}, {'a': 'b'}, {'a': 17}, {'a': frozenset([1, 2, 3])}, {b'a': 1, u'b': 2}, + {1: 2, 3: 4, 5: None}, {(1, 2, 3): (1, 4, 9), None: 0}, + # set + set(), {1, 2, 3}, {'hello', 'world'}, + # frozenset + frozenset(), frozenset([1, 2, 3]), frozenset(['hello', 'world']), +] + + +@pytest.mark.parametrize('format', ['binary', 'text', 'pretty']) +@pytest.mark.parametrize('value', CASES) +def test_roundtrip(value, format): + encoded = dumps(value, format=format, Writer=PyWriter) + decoded = loads(encoded, Reader=PyReader) + assert encoded == dumps(value, format=switch_string_type(format), Writer=PyWriter) + assert type(decoded) is type(value) + assert decoded == value + + +@pytest.mark.parametrize('format', ['binary', 'text', 'pretty']) +@pytest.mark.parametrize('value', CASES) +def test_roundtrip_bytearray(value, format): + encoded1 = bytearray() + encoded2 = bytearray() + dumps_into(encoded1, value, format=format, Writer=PyWriter) + dumps_into(encoded2, value, format=switch_string_type(format), Writer=PyWriter) + decoded = loads(encoded1, Reader=PyReader) + assert decoded == loads(encoded2, Reader=PyReader) + assert type(decoded) is type(value) + assert decoded == value |