summaryrefslogtreecommitdiffstats
path: root/yql/essentials/udfs/common/python/bindings/py_cast_ut.cpp
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2025-02-28 23:59:20 +0300
committerrobot-piglet <[email protected]>2025-03-01 00:13:10 +0300
commitb04e2faf41bf366d5f501c976bda00eb32d55660 (patch)
treef922ace378c0c471d912c33f2c0231144f898d78 /yql/essentials/udfs/common/python/bindings/py_cast_ut.cpp
parent9ba742f4d36b4a3d879b4cf8d9234165413f4a0d (diff)
Intermediate changes
commit_hash:e2da3ad430fabaa84a74178b1f2103b09ac69ae7
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.cpp41
1 files changed, 39 insertions, 2 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
index 47f65ab6fab..d4ee90278c2 100644
--- a/yql/essentials/udfs/common/python/bindings/py_cast_ut.cpp
+++ b/yql/essentials/udfs/common/python/bindings/py_cast_ut.cpp
@@ -1,9 +1,39 @@
-#include "ut3/py_test_engine.h"
+#include "py_test_engine.h"
#include <library/cpp/testing/unittest/registar.h>
+#include <util/string/strip.h>
using namespace NPython;
+namespace {
+template <typename TType>
+void TestBadUtf8Encode() {
+#if PY_MAJOR_VERSION == 2
+ // In Python 2, strings can encode single surrogate pairs, so this issue does not occur there.
+ return;
+#endif // PY_MAJOR_VERSION == 2
+
+ TPythonTestEngine engine;
+
+ constexpr char programToRun[] = R"(
+def Test():
+ return "\uDC00"
+)";
+ constexpr char expectedError[] = R"(
+Failed to convert the string to UTF-8 format. Original message is:
+UnicodeEncodeError: 'utf-8' codec can't encode character '\udc00' in position 0: surrogates not allowed
+)";
+
+ UNIT_ASSERT_EXCEPTION_CONTAINS(
+ engine.ToMiniKQL<TType>(
+ StripString(TString(programToRun)),
+ [](const NUdf::TUnboxedValuePod& value) {
+ Y_UNUSED(value);
+ }),
+ yexception, StripString(TString(expectedError)));
+}
+} // namespace
+
Y_UNIT_TEST_SUITE(TPyCastTest) {
Y_UNIT_TEST(FromPyStrToInt) {
TPythonTestEngine engine;
@@ -87,4 +117,11 @@ Y_UNIT_TEST_SUITE(TPyCastTest) {
yexception, "Cast error object " RETVAL " to Long");
}
-}
+ Y_UNIT_TEST(BadFromPythonUtf8) {
+ TestBadUtf8Encode<NUdf::TUtf8>();
+ }
+
+ Y_UNIT_TEST(BadFromPythonJson) {
+ TestBadUtf8Encode<NUdf::TJson>();
+ }
+} // Y_UNIT_TEST_SUITE(TPyCastTest)