diff options
author | imunkin <imunkin@yandex-team.com> | 2024-11-08 10:00:23 +0300 |
---|---|---|
committer | imunkin <imunkin@yandex-team.com> | 2024-11-08 10:12:13 +0300 |
commit | a784a2f943d6e15caa6241e2e96d80aac6dbf375 (patch) | |
tree | 05f1e5366c916b988a8afb75bdab8ddeee0f6e6d /yql/essentials/udfs/common/python/bindings/py_optional_ut.cpp | |
parent | d70137a7b530ccaa52834274913bbb5a3d1ca06e (diff) | |
download | ydb-a784a2f943d6e15caa6241e2e96d80aac6dbf375.tar.gz |
Move yql/udfs/common/ to /yql/essentials YQL-19206
Except the following directories:
* clickhouse/client
* datetime
* knn
* roaring
commit_hash:c7da95636144d28db109d6b17ddc762e9bacb59f
Diffstat (limited to 'yql/essentials/udfs/common/python/bindings/py_optional_ut.cpp')
-rw-r--r-- | yql/essentials/udfs/common/python/bindings/py_optional_ut.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/yql/essentials/udfs/common/python/bindings/py_optional_ut.cpp b/yql/essentials/udfs/common/python/bindings/py_optional_ut.cpp new file mode 100644 index 0000000000..d13ea65da6 --- /dev/null +++ b/yql/essentials/udfs/common/python/bindings/py_optional_ut.cpp @@ -0,0 +1,56 @@ +#include "ut3/py_test_engine.h" + +#include <library/cpp/testing/unittest/registar.h> + + +using namespace NPython; + +Y_UNIT_TEST_SUITE(FromPyNone) { + Y_UNIT_TEST(FromPyNone) { + TPythonTestEngine engine; + engine.ToMiniKQL<NUdf::TOptional<ui32>>( + "def Test(): return None", + [](const NUdf::TUnboxedValuePod& value) { + UNIT_ASSERT(!value); + }); + } + + Y_UNIT_TEST(FromPyObject) { + TPythonTestEngine engine; + engine.ToMiniKQL<NUdf::TOptional<ui32>>( + "def Test(): return 42", + [](const NUdf::TUnboxedValuePod& value) { + UNIT_ASSERT(value); + UNIT_ASSERT_EQUAL(value.Get<ui32>(), 42); + }); + } + + Y_UNIT_TEST(ToPyNone) { + TPythonTestEngine engine; + engine.ToPython<NUdf::TOptional<char*>>( + [](const TType* type, const NUdf::IValueBuilder& vb) { + Y_UNUSED(type); Y_UNUSED(vb); + return NUdf::TUnboxedValuePod(); + }, + "def Test(value):\n" + " assert value == None\n"); + } + + Y_UNIT_TEST(ToPyFilledOptional) { + TPythonTestEngine engine; + engine.ToPython<NUdf::TOptional<NUdf::TTuple<NUdf::TUtf8, bool>>>( + [](const TType* type, const NUdf::IValueBuilder& vb) { + const TOptionalType* optType = + static_cast<const TOptionalType*>(type); + NUdf::TUnboxedValue* items = nullptr; + auto tuple = vb.NewArray(static_cast<const TTupleType*>(optType->GetItemType())->GetElementsCount(), items); + items[0] = vb.NewString("test string"); + items[1] = NUdf::TUnboxedValuePod(false); + return NUdf::TUnboxedValue(tuple); + }, + "def Test(value):\n" + " assert isinstance(value, tuple)\n" + " assert len(value) == 2\n" + " assert value == ('test string', False)\n"); + } +} |