summaryrefslogtreecommitdiffstats
path: root/library/python
diff options
context:
space:
mode:
authorAlexSm <[email protected]>2024-01-18 11:28:56 +0100
committerGitHub <[email protected]>2024-01-18 11:28:56 +0100
commit9d0a3761b3201e0d9db879a7adf91876ebdb0564 (patch)
tree541d11ac878c18efd7ebca81e35112aa0fef995b /library/python
parent404ef8886ecc9736bc58ade6da2fbd83b486a408 (diff)
Library import 8 (#1074)
* Library import 8 * Add contrib/libs/cxxsupp/libcxx/include/__verbose_abort
Diffstat (limited to 'library/python')
-rw-r--r--library/python/svn_version/__init__.py24
-rw-r--r--library/python/svn_version/ut/test_simple.py24
-rw-r--r--library/python/svn_version/ut/ya.make13
-rw-r--r--library/python/svn_version/ya.make6
-rw-r--r--library/python/windows/__init__.py43
-rw-r--r--library/python/windows/ut/test_windows.py97
-rw-r--r--library/python/windows/ut/ya.make13
-rw-r--r--library/python/windows/ya.make10
8 files changed, 218 insertions, 12 deletions
diff --git a/library/python/svn_version/__init__.py b/library/python/svn_version/__init__.py
index caaef65bfe3..b5c05d6bc06 100644
--- a/library/python/svn_version/__init__.py
+++ b/library/python/svn_version/__init__.py
@@ -1,5 +1,25 @@
-from .__svn_version import svn_version, commit_id, svn_revision, svn_last_revision, hash, svn_branch, svn_tag, patch_number, vcs, svn_timestamp
+from .__svn_version import (
+ svn_version,
+ commit_id,
+ svn_revision,
+ svn_last_revision,
+ hash,
+ svn_branch,
+ svn_tag,
+ patch_number,
+ vcs,
+ svn_timestamp,
+)
__all__ = (
- 'svn_version', 'commit_id', 'svn_revision', 'svn_last_revision', 'hash', 'svn_branch', 'svn_tag', 'patch_number', 'vcs', 'svn_timestamp'
+ 'svn_version',
+ 'commit_id',
+ 'svn_revision',
+ 'svn_last_revision',
+ 'hash',
+ 'svn_branch',
+ 'svn_tag',
+ 'patch_number',
+ 'vcs',
+ 'svn_timestamp',
)
diff --git a/library/python/svn_version/ut/test_simple.py b/library/python/svn_version/ut/test_simple.py
new file mode 100644
index 00000000000..50fa78f55d8
--- /dev/null
+++ b/library/python/svn_version/ut/test_simple.py
@@ -0,0 +1,24 @@
+import library.python.svn_version as sv
+
+
+def test_simple():
+ assert sv.svn_version()
+ assert isinstance(sv.svn_version(), str)
+
+ assert sv.vcs()
+ assert isinstance(sv.vcs(), str)
+
+ # svn_revision() will be -1 on non-trunk commits via arc
+ # svn revision of 0 technically may exist, but practiacally it will never appear here
+ assert sv.svn_revision() >= 0 or (sv.vcs() != "svn" and sv.svn_revision() == -1)
+ assert isinstance(sv.svn_revision(), int)
+
+ # svn_last_revision() will be equal to zero on non-trunk commits
+ assert sv.svn_last_revision() >= 0 or (sv.vcs() != "svn" and sv.svn_last_revision() == -1)
+ assert isinstance(sv.svn_last_revision(), int)
+
+ assert sv.commit_id()
+ assert isinstance(sv.commit_id(), str)
+ assert len(sv.commit_id()) > 0
+ assert isinstance(sv.hash(), str)
+ assert isinstance(sv.patch_number(), int)
diff --git a/library/python/svn_version/ut/ya.make b/library/python/svn_version/ut/ya.make
new file mode 100644
index 00000000000..c96b843565e
--- /dev/null
+++ b/library/python/svn_version/ut/ya.make
@@ -0,0 +1,13 @@
+PY23_TEST()
+
+STYLE_PYTHON()
+
+PEERDIR(
+ library/python/svn_version
+)
+
+TEST_SRCS(
+ test_simple.py
+)
+
+END()
diff --git a/library/python/svn_version/ya.make b/library/python/svn_version/ya.make
index f168ea4a94b..8fdcd508190 100644
--- a/library/python/svn_version/ya.make
+++ b/library/python/svn_version/ya.make
@@ -1,5 +1,7 @@
PY23_LIBRARY()
+STYLE_PYTHON()
+
PEERDIR(
library/cpp/svnversion
contrib/python/future
@@ -11,3 +13,7 @@ PY_SRCS(
)
END()
+
+RECURSE_FOR_TESTS(
+ ut
+)
diff --git a/library/python/windows/__init__.py b/library/python/windows/__init__.py
index eb520a8d2d0..fe7a2c01401 100644
--- a/library/python/windows/__init__.py
+++ b/library/python/windows/__init__.py
@@ -191,7 +191,9 @@ if on_win():
def transcode_error(windows_error, to_enc='utf-8'):
from_enc = 'utf-8' if getattr(windows_error, 'utf8', False) else library.python.strings.guess_default_encoding()
if from_enc != to_enc:
- windows_error.strerror = library.python.strings.to_str(windows_error.strerror, to_enc=to_enc, from_enc=from_enc)
+ windows_error.strerror = library.python.strings.to_str(
+ windows_error.strerror, to_enc=to_enc, from_enc=from_enc
+ )
setattr(windows_error, 'utf8', to_enc == 'utf-8')
class Transaction(object):
@@ -230,14 +232,26 @@ if on_win():
@win_only
@require_ctypes
def replace_file(src, dst):
- if not ctypes.windll.kernel32.MoveFileExW(unicode_path(src), unicode_path(dst), _MOVEFILE_REPLACE_EXISTING | _MOVEFILE_WRITE_THROUGH):
+ if not ctypes.windll.kernel32.MoveFileExW(
+ unicode_path(src), unicode_path(dst), _MOVEFILE_REPLACE_EXISTING | _MOVEFILE_WRITE_THROUGH
+ ):
raise ctypes.WinError()
@win_only
@require_ctypes
def replace_file_across_devices(src, dst):
- with Transaction(timeout=_ATOMIC_RENAME_FILE_TRANSACTION_DEFAULT_TIMEOUT, description='ya library.python.windows replace_file_across_devices') as transaction:
- if not ctypes.windll.kernel32.MoveFileTransactedW(unicode_path(src), unicode_path(dst), None, None, _MOVEFILE_REPLACE_EXISTING | _MOVEFILE_WRITE_THROUGH, transaction):
+ with Transaction(
+ timeout=_ATOMIC_RENAME_FILE_TRANSACTION_DEFAULT_TIMEOUT,
+ description='ya library.python.windows replace_file_across_devices',
+ ) as transaction:
+ if not ctypes.windll.kernel32.MoveFileTransactedW(
+ unicode_path(src),
+ unicode_path(dst),
+ None,
+ None,
+ _MOVEFILE_REPLACE_EXISTING | _MOVEFILE_WRITE_THROUGH,
+ transaction,
+ ):
raise ctypes.WinError()
@win_only
@@ -259,13 +273,17 @@ if on_win():
@win_disabled
@require_ctypes
def symlink_dir(src, lnk):
- if not ctypes.windll.kernel32.CreateSymbolicLinkW(unicode_path(lnk), unicode_path(src), _SYMBOLIC_LINK_FLAG_DIRECTORY):
+ if not ctypes.windll.kernel32.CreateSymbolicLinkW(
+ unicode_path(lnk), unicode_path(src), _SYMBOLIC_LINK_FLAG_DIRECTORY
+ ):
raise ctypes.WinError()
@win_only
@require_ctypes
def lock_file(f, offset, length, raises=True):
- locked = ctypes.windll.kernel32.LockFile(file_handle(f), _low_dword(offset), _high_dword(offset), _low_dword(length), _high_dword(length))
+ locked = ctypes.windll.kernel32.LockFile(
+ file_handle(f), _low_dword(offset), _high_dword(offset), _low_dword(length), _high_dword(length)
+ )
if not raises:
return bool(locked)
if not locked:
@@ -274,7 +292,9 @@ if on_win():
@win_only
@require_ctypes
def unlock_file(f, offset, length, raises=True):
- unlocked = ctypes.windll.kernel32.UnlockFile(file_handle(f), _low_dword(offset), _high_dword(offset), _low_dword(length), _high_dword(length))
+ unlocked = ctypes.windll.kernel32.UnlockFile(
+ file_handle(f), _low_dword(offset), _high_dword(offset), _low_dword(length), _high_dword(length)
+ )
if not raises:
return bool(unlocked)
if not unlocked:
@@ -304,6 +324,7 @@ if on_win():
# propagate true last error if this attempt fails
return func(handling_path)
raise e
+
shutil.rmtree(path, onerror=error_handler)
# Don't display the Windows GPF dialog if the invoked program dies.
@@ -337,7 +358,9 @@ if on_win():
def get_process_handle_count(proc_handle):
assert isinstance(proc_handle, wintypes.HANDLE)
- GetProcessHandleCount = ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.HANDLE, wintypes.POINTER(wintypes.DWORD))(("GetProcessHandleCount", ctypes.windll.kernel32))
+ GetProcessHandleCount = ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.HANDLE, wintypes.POINTER(wintypes.DWORD))(
+ ("GetProcessHandleCount", ctypes.windll.kernel32)
+ )
hndcnt = wintypes.DWORD()
if not GetProcessHandleCount(proc_handle, ctypes.byref(hndcnt)):
raise ctypes.WinError()
@@ -349,7 +372,9 @@ if on_win():
for flag, value in [(inherit, 1), (protect_from_close, 2)]:
if flag is not None:
assert isinstance(flag, bool)
- if not ctypes.windll.kernel32.SetHandleInformation(file_handle(file), _low_dword(value), _low_dword(int(flag))):
+ if not ctypes.windll.kernel32.SetHandleInformation(
+ file_handle(file), _low_dword(value), _low_dword(int(flag))
+ ):
raise ctypes.WinError()
@win_only
diff --git a/library/python/windows/ut/test_windows.py b/library/python/windows/ut/test_windows.py
new file mode 100644
index 00000000000..beaa5fc3aa3
--- /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 00000000000..c321141f37e
--- /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()
diff --git a/library/python/windows/ya.make b/library/python/windows/ya.make
index 97c6f48f23a..14f7dfac71d 100644
--- a/library/python/windows/ya.make
+++ b/library/python/windows/ya.make
@@ -1,6 +1,10 @@
PY23_LIBRARY()
-PY_SRCS(__init__.py)
+STYLE_PYTHON()
+
+PY_SRCS(
+ __init__.py
+)
PEERDIR(
library/python/func
@@ -9,3 +13,7 @@ PEERDIR(
)
END()
+
+RECURSE_FOR_TESTS(
+ ut
+)