diff options
author | AlexSm <alex@ydb.tech> | 2024-01-18 11:28:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-18 11:28:56 +0100 |
commit | 9d0a3761b3201e0d9db879a7adf91876ebdb0564 (patch) | |
tree | 541d11ac878c18efd7ebca81e35112aa0fef995b /library/python/windows/ut | |
parent | 404ef8886ecc9736bc58ade6da2fbd83b486a408 (diff) | |
download | ydb-9d0a3761b3201e0d9db879a7adf91876ebdb0564.tar.gz |
Library import 8 (#1074)
* Library import 8
* Add contrib/libs/cxxsupp/libcxx/include/__verbose_abort
Diffstat (limited to 'library/python/windows/ut')
-rw-r--r-- | library/python/windows/ut/test_windows.py | 97 | ||||
-rw-r--r-- | library/python/windows/ut/ya.make | 13 |
2 files changed, 110 insertions, 0 deletions
diff --git a/library/python/windows/ut/test_windows.py b/library/python/windows/ut/test_windows.py new file mode 100644 index 0000000000..beaa5fc3aa --- /dev/null +++ b/library/python/windows/ut/test_windows.py @@ -0,0 +1,97 @@ +# coding=utf-8 + +import errno +import os +import pytest +import six + +import library.python.strings +import library.python.windows + + +def gen_error_access_denied(): + if library.python.windows.on_win(): + err = WindowsError() + err.errno = errno.EACCES + err.strerror = '' + err.winerror = library.python.windows.ERRORS['ACCESS_DENIED'] + else: + err = OSError() + err.errno = errno.EACCES + err.strerror = os.strerror(err.errno) + err.filename = 'unknown/file' + raise err + + +def test_errorfix_buggy(): + @library.python.windows.errorfix + def erroneous_func(): + gen_error_access_denied() + + with pytest.raises(OSError) as errinfo: + erroneous_func() + assert errinfo.value.errno == errno.EACCES + assert errinfo.value.filename == 'unknown/file' + assert isinstance(errinfo.value.strerror, six.string_types) + assert errinfo.value.strerror + + +def test_errorfix_explicit(): + @library.python.windows.errorfix + def erroneous_func(): + if library.python.windows.on_win(): + err = WindowsError() + err.winerror = library.python.windows.ERRORS['ACCESS_DENIED'] + else: + err = OSError() + err.errno = errno.EACCES + err.strerror = 'Some error description' + err.filename = 'unknown/file' + raise err + + with pytest.raises(OSError) as errinfo: + erroneous_func() + assert errinfo.value.errno == errno.EACCES + assert errinfo.value.filename == 'unknown/file' + assert errinfo.value.strerror == 'Some error description' + + +def test_errorfix_decoding_cp1251(): + @library.python.windows.errorfix + def erroneous_func(): + model_msg = u'Какое-то описание ошибки' + if library.python.windows.on_win(): + err = WindowsError() + err.strerror = library.python.strings.to_str(model_msg, 'cp1251') + else: + err = OSError() + err.strerror = library.python.strings.to_str(model_msg) + raise err + + with pytest.raises(OSError) as errinfo: + erroneous_func() + error_msg = errinfo.value.strerror + if not isinstance(errinfo.value.strerror, six.text_type): + error_msg = library.python.strings.to_unicode(error_msg) + assert error_msg == u'Какое-то описание ошибки' + + +def test_diehard(): + @library.python.windows.diehard(library.python.windows.ERRORS['ACCESS_DENIED'], tries=5) + def erroneous_func(errors): + try: + gen_error_access_denied() + except Exception as e: + errors.append(e) + raise + + raised_errors = [] + with pytest.raises(OSError) as errinfo: + erroneous_func(raised_errors) + assert errinfo.value.errno == errno.EACCES + assert any(e.errno == errno.EACCES for e in raised_errors) + assert raised_errors and errinfo.value == raised_errors[-1] + if library.python.windows.on_win(): + assert len(raised_errors) == 5 + else: + assert len(raised_errors) == 1 diff --git a/library/python/windows/ut/ya.make b/library/python/windows/ut/ya.make new file mode 100644 index 0000000000..c321141f37 --- /dev/null +++ b/library/python/windows/ut/ya.make @@ -0,0 +1,13 @@ +PY23_TEST() + +STYLE_PYTHON() + +TEST_SRCS( + test_windows.py +) + +PEERDIR( + library/python/windows +) + +END() |