aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/udfs/common/python/bindings/py_cast_ut.cpp
diff options
context:
space:
mode:
authorimunkin <imunkin@yandex-team.com>2024-11-08 10:00:23 +0300
committerimunkin <imunkin@yandex-team.com>2024-11-08 10:12:13 +0300
commita784a2f943d6e15caa6241e2e96d80aac6dbf375 (patch)
tree05f1e5366c916b988a8afb75bdab8ddeee0f6e6d /yql/essentials/udfs/common/python/bindings/py_cast_ut.cpp
parentd70137a7b530ccaa52834274913bbb5a3d1ca06e (diff)
downloadydb-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_cast_ut.cpp')
-rw-r--r--yql/essentials/udfs/common/python/bindings/py_cast_ut.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/yql/essentials/udfs/common/python/bindings/py_cast_ut.cpp b/yql/essentials/udfs/common/python/bindings/py_cast_ut.cpp
new file mode 100644
index 0000000000..47f65ab6fa
--- /dev/null
+++ b/yql/essentials/udfs/common/python/bindings/py_cast_ut.cpp
@@ -0,0 +1,90 @@
+#include "ut3/py_test_engine.h"
+
+#include <library/cpp/testing/unittest/registar.h>
+
+using namespace NPython;
+
+Y_UNIT_TEST_SUITE(TPyCastTest) {
+ Y_UNIT_TEST(FromPyStrToInt) {
+ TPythonTestEngine engine;
+ UNIT_ASSERT_EXCEPTION_CONTAINS(
+ engine.ToMiniKQL<i32>(
+ "def Test():\n"
+ " return '123a'",
+ [](const NUdf::TUnboxedValuePod& value) {
+ Y_UNUSED(value);
+ }),
+ yexception, "str");
+ }
+
+ Y_UNIT_TEST(FromPyTupleToLong) {
+ TPythonTestEngine engine;
+ UNIT_ASSERT_EXCEPTION_CONTAINS(
+ engine.ToMiniKQL<ui64>(
+ "def Test():\n"
+ " return 1, 1",
+ [](const NUdf::TUnboxedValuePod& value) {
+ Y_UNUSED(value);
+ }),
+ yexception, "tuple");
+ }
+
+ Y_UNIT_TEST(FromPyFuncToString) {
+ TPythonTestEngine engine;
+ UNIT_ASSERT_EXCEPTION_CONTAINS(
+ engine.ToMiniKQL<char*>(
+ "def f():\n"
+ " return 42\n"
+ "def Test():\n"
+ " return f",
+ [](const NUdf::TUnboxedValuePod& value) {
+ Y_UNUSED(value);
+ }),
+ yexception, "function");
+ }
+
+ Y_UNIT_TEST(FromPyNoneToString) {
+ TPythonTestEngine engine;
+ UNIT_ASSERT_EXCEPTION_CONTAINS(
+ engine.ToMiniKQL<char*>(
+ "def Test():\n"
+ " return None",
+ [](const NUdf::TUnboxedValuePod& value) {
+ Y_UNUSED(value);
+ }),
+ yexception, "None");
+ }
+
+ Y_UNIT_TEST(BadFromPythonFloat) {
+ TPythonTestEngine engine;
+ UNIT_ASSERT_EXCEPTION_CONTAINS(
+ engine.ToMiniKQL<float>(
+ "def Test():\n"
+ " return '3 <dot> 1415926'",
+ [](const NUdf::TUnboxedValuePod& value) {
+ Y_UNUSED(value);
+ Y_UNREACHABLE();
+ }),
+ yexception, "Cast error object '3 <dot> 1415926' to Float");
+ }
+
+#if PY_MAJOR_VERSION >= 3
+# define RETVAL "-1"
+#else
+# define RETVAL "-18446744073709551616L"
+#endif
+
+ Y_UNIT_TEST(BadFromPythonLong) {
+ TPythonTestEngine engine;
+ UNIT_ASSERT_EXCEPTION_CONTAINS(
+ engine.ToMiniKQL<ui64>(
+ "def Test():\n"
+ " return " RETVAL,
+ [](const NUdf::TUnboxedValuePod& value) {
+ Y_UNUSED(value);
+ Y_UNREACHABLE();
+ }),
+ yexception, "Cast error object " RETVAL " to Long");
+ }
+
+}