aboutsummaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorrnefyodov <rnefyodov@yandex-team.ru>2022-02-10 16:47:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:17 +0300
commitc22320e8c4f3d7be38c504706f137034e91d31e6 (patch)
tree35cc6c382a1bd8cb932449ffa734056fcc73e6d4 /library
parent93e9e4639b6ee2afbdf45cf3927cea6d340e19b0 (diff)
downloadydb-c22320e8c4f3d7be38c504706f137034e91d31e6.tar.gz
Restoring authorship annotation for <rnefyodov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library')
-rw-r--r--library/cpp/cgiparam/fuzz/ya.make2
-rw-r--r--library/cpp/colorizer/colors.cpp94
-rw-r--r--library/cpp/colorizer/colors.h18
-rw-r--r--library/cpp/colorizer/output.h22
-rw-r--r--library/cpp/http/fetch/ya.make2
-rw-r--r--library/cpp/http/io/fuzz/ya.make2
-rw-r--r--library/cpp/json/fuzzy_test/ya.make2
-rw-r--r--library/cpp/resource/registry.cpp2
-rw-r--r--library/cpp/testing/unittest/utmain.cpp26
-rw-r--r--library/python/filelock/__init__.py2
-rw-r--r--library/python/fs/__init__.py196
-rw-r--r--library/python/func/__init__.py102
-rw-r--r--library/python/func/ut/test_func.py144
-rw-r--r--library/python/pytest/yatest_tools.py42
-rw-r--r--library/python/ya.make2
15 files changed, 329 insertions, 329 deletions
diff --git a/library/cpp/cgiparam/fuzz/ya.make b/library/cpp/cgiparam/fuzz/ya.make
index 8fb9d50d3b..e55c7e9634 100644
--- a/library/cpp/cgiparam/fuzz/ya.make
+++ b/library/cpp/cgiparam/fuzz/ya.make
@@ -1,4 +1,4 @@
-FUZZ()
+FUZZ()
OWNER(
pg
diff --git a/library/cpp/colorizer/colors.cpp b/library/cpp/colorizer/colors.cpp
index decc5c9847..85c148893b 100644
--- a/library/cpp/colorizer/colors.cpp
+++ b/library/cpp/colorizer/colors.cpp
@@ -1,9 +1,9 @@
#include "colors.h"
-
+
#include <util/stream/output.h>
#include <util/generic/singleton.h>
#include <util/system/env.h>
-
+
#include <cstdlib>
#if defined(_unix_)
@@ -11,7 +11,7 @@
#endif
using namespace NColorizer;
-
+
namespace {
constexpr TStringBuf ToStringBufC(NColorizer::EAnsiCode x) {
switch(x) {
@@ -171,30 +171,30 @@ TColors::TColors(FILE* f)
{
SetIsTTY(CalcIsTTY(f));
}
-
+
TColors::TColors(bool ontty)
: IsTTY_(true)
{
SetIsTTY(ontty);
-}
-
+}
+
TStringBuf TColors::Reset() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::RESET) : ToStringBufC(EAnsiCode::INVALID);
-}
-
+}
+
TStringBuf TColors::StyleLight() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::ST_LIGHT) : ToStringBufC(EAnsiCode::INVALID);
-}
+}
TStringBuf TColors::StyleDark() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::ST_DARK) : ToStringBufC(EAnsiCode::INVALID);
}
TStringBuf TColors::StyleNormal() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::ST_NORMAL) : ToStringBufC(EAnsiCode::INVALID);
}
-
+
TStringBuf TColors::ItalicOn() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::ITALIC_ON) : ToStringBufC(EAnsiCode::INVALID);
-}
+}
TStringBuf TColors::ItalicOff() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::ITALIC_OFF) : ToStringBufC(EAnsiCode::INVALID);
}
@@ -204,10 +204,10 @@ TStringBuf TColors::UnderlineOn() const noexcept {
TStringBuf TColors::UnderlineOff() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::UNDERLINE_OFF) : ToStringBufC(EAnsiCode::INVALID);
}
-
+
TStringBuf TColors::ForeDefault() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::FG_DEFAULT) : ToStringBufC(EAnsiCode::INVALID);
-}
+}
TStringBuf TColors::ForeBlack() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::FG_BLACK) : ToStringBufC(EAnsiCode::INVALID);
}
@@ -232,10 +232,10 @@ TStringBuf TColors::ForeCyan() const noexcept {
TStringBuf TColors::ForeWhite() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::FG_WHITE) : ToStringBufC(EAnsiCode::INVALID);
}
-
+
TStringBuf TColors::BackDefault() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::BG_DEFAULT) : ToStringBufC(EAnsiCode::INVALID);
-}
+}
TStringBuf TColors::BackBlack() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::BG_BLACK) : ToStringBufC(EAnsiCode::INVALID);
}
@@ -260,10 +260,10 @@ TStringBuf TColors::BackCyan() const noexcept {
TStringBuf TColors::BackWhite() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::BG_WHITE) : ToStringBufC(EAnsiCode::INVALID);
}
-
+
TStringBuf TColors::Default() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::DEFAULT) : ToStringBufC(EAnsiCode::INVALID);
-}
+}
TStringBuf TColors::Black() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::BLACK) : ToStringBufC(EAnsiCode::INVALID);
}
@@ -288,10 +288,10 @@ TStringBuf TColors::Cyan() const noexcept {
TStringBuf TColors::White() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::WHITE) : ToStringBufC(EAnsiCode::INVALID);
}
-
+
TStringBuf TColors::LightDefault() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::LIGHT_DEFAULT) : ToStringBufC(EAnsiCode::INVALID);
-}
+}
TStringBuf TColors::LightBlack() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::LIGHT_BLACK) : ToStringBufC(EAnsiCode::INVALID);
}
@@ -316,10 +316,10 @@ TStringBuf TColors::LightCyan() const noexcept {
TStringBuf TColors::LightWhite() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::LIGHT_WHITE) : ToStringBufC(EAnsiCode::INVALID);
}
-
+
TStringBuf TColors::DarkDefault() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::DARK_DEFAULT) : ToStringBufC(EAnsiCode::INVALID);
-}
+}
TStringBuf TColors::DarkBlack() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::DARK_BLACK) : ToStringBufC(EAnsiCode::INVALID);
}
@@ -344,47 +344,47 @@ TStringBuf TColors::DarkCyan() const noexcept {
TStringBuf TColors::DarkWhite() const noexcept {
return IsTTY() ? ToStringBufC(EAnsiCode::DARK_WHITE) : ToStringBufC(EAnsiCode::INVALID);
}
-
+
TStringBuf TColors::OldColor() const noexcept {
return IsTTY() ? "\033[22;39m" : "";
-}
-
+}
+
TStringBuf TColors::BoldColor() const noexcept {
return IsTTY() ? "\033[1m" : "";
-}
-
+}
+
TStringBuf TColors::BlackColor() const noexcept {
return IsTTY() ? "\033[22;30m" : "";
-}
-
+}
+
TStringBuf TColors::BlueColor() const noexcept {
return IsTTY() ? "\033[22;34m" : "";
-}
-
+}
+
TStringBuf TColors::GreenColor() const noexcept {
return IsTTY() ? "\033[22;32m" : "";
-}
-
+}
+
TStringBuf TColors::CyanColor() const noexcept {
return IsTTY() ? "\033[22;36m" : "";
-}
-
+}
+
TStringBuf TColors::RedColor() const noexcept {
return IsTTY() ? "\033[22;31m" : "";
-}
-
+}
+
TStringBuf TColors::PurpleColor() const noexcept {
return IsTTY() ? "\033[22;35m" : "";
-}
-
+}
+
TStringBuf TColors::BrownColor() const noexcept {
return IsTTY() ? "\033[22;33m" : "";
-}
-
+}
+
TStringBuf TColors::LightGrayColor() const noexcept {
return IsTTY() ? "\033[22;37m" : "";
-}
-
+}
+
TStringBuf TColors::DarkGrayColor() const noexcept {
return IsTTY() ? "\033[1;30m" : "";
}
@@ -404,15 +404,15 @@ TStringBuf TColors::LightCyanColor() const noexcept {
TStringBuf TColors::LightRedColor() const noexcept {
return IsTTY() ? "\033[1;31m" : "";
}
-
+
TStringBuf TColors::LightPurpleColor() const noexcept {
return IsTTY() ? "\033[1;35m" : "";
-}
-
+}
+
TStringBuf TColors::YellowColor() const noexcept {
return IsTTY() ? "\033[1;33m" : "";
-}
-
+}
+
TStringBuf TColors::WhiteColor() const noexcept {
return IsTTY() ? "\033[1;37m" : "";
}
diff --git a/library/cpp/colorizer/colors.h b/library/cpp/colorizer/colors.h
index 474a918994..2966c98375 100644
--- a/library/cpp/colorizer/colors.h
+++ b/library/cpp/colorizer/colors.h
@@ -1,10 +1,10 @@
-#pragma once
+#pragma once
#include "fwd.h"
-
+
#include <util/generic/string.h>
#include <util/generic/strbuf.h>
-
+
#include <cstdio>
namespace NColorizer {
@@ -106,13 +106,13 @@ namespace NColorizer {
public:
explicit TColors(FILE* = stderr);
explicit TColors(bool ontty);
-
+
TStringBuf Reset() const noexcept;
-
+
TStringBuf StyleLight() const noexcept;
TStringBuf StyleDark() const noexcept;
TStringBuf StyleNormal() const noexcept;
-
+
TStringBuf ItalicOn() const noexcept;
TStringBuf ItalicOff() const noexcept;
TStringBuf UnderlineOn() const noexcept;
@@ -195,7 +195,7 @@ namespace NColorizer {
inline bool IsTTY() const noexcept {
return IsTTY_;
}
-
+
inline void SetIsTTY(bool value) noexcept {
IsTTY_ = value;
}
@@ -210,7 +210,7 @@ namespace NColorizer {
private:
bool IsTTY_;
- };
+ };
/// Singletone `TColors` instances for stderr/stdout.
TColors& StdErr();
@@ -222,7 +222,7 @@ namespace NColorizer {
/// Calculate total length of all ANSI escape codes in the text.
size_t TotalAnsiEscapeCodeLen(TStringBuf text);
-}
+}
TStringBuf ToStringBuf(NColorizer::EAnsiCode x);
TString ToString(NColorizer::EAnsiCode x);
diff --git a/library/cpp/colorizer/output.h b/library/cpp/colorizer/output.h
index 99afbd3427..e2d5afcec4 100644
--- a/library/cpp/colorizer/output.h
+++ b/library/cpp/colorizer/output.h
@@ -25,19 +25,19 @@ namespace NColorizer {
}
DEF(Old)
- DEF(Black)
+ DEF(Black)
DEF(Green)
- DEF(Cyan)
+ DEF(Cyan)
DEF(Red)
- DEF(Purple)
- DEF(Brown)
- DEF(LightGray)
- DEF(DarkGray)
- DEF(LightBlue)
- DEF(LightGreen)
- DEF(LightCyan)
- DEF(LightRed)
- DEF(LightPurple)
+ DEF(Purple)
+ DEF(Brown)
+ DEF(LightGray)
+ DEF(DarkGray)
+ DEF(LightBlue)
+ DEF(LightGreen)
+ DEF(LightCyan)
+ DEF(LightRed)
+ DEF(LightPurple)
DEF(Yellow)
DEF(White)
diff --git a/library/cpp/http/fetch/ya.make b/library/cpp/http/fetch/ya.make
index 7737127463..bda332045a 100644
--- a/library/cpp/http/fetch/ya.make
+++ b/library/cpp/http/fetch/ya.make
@@ -31,7 +31,7 @@ SRCS(
GENERATE_ENUM_SERIALIZATION(httpheader.h)
-SET(RAGEL6_FLAGS -CF1)
+SET(RAGEL6_FLAGS -CF1)
END()
diff --git a/library/cpp/http/io/fuzz/ya.make b/library/cpp/http/io/fuzz/ya.make
index 8b3ccb1969..0a901fe0d4 100644
--- a/library/cpp/http/io/fuzz/ya.make
+++ b/library/cpp/http/io/fuzz/ya.make
@@ -1,4 +1,4 @@
-FUZZ()
+FUZZ()
OWNER(
pg
diff --git a/library/cpp/json/fuzzy_test/ya.make b/library/cpp/json/fuzzy_test/ya.make
index ff50bc1f62..aec610841f 100644
--- a/library/cpp/json/fuzzy_test/ya.make
+++ b/library/cpp/json/fuzzy_test/ya.make
@@ -1,4 +1,4 @@
-FUZZ()
+FUZZ()
OWNER(pg)
diff --git a/library/cpp/resource/registry.cpp b/library/cpp/resource/registry.cpp
index 66001c4769..8f5a718a81 100644
--- a/library/cpp/resource/registry.cpp
+++ b/library/cpp/resource/registry.cpp
@@ -40,7 +40,7 @@ namespace {
" new size: %zu.",
TString{key}.Quote().c_str(), vsize, dsize);
}
- }
+ }
} else {
D_.push_back(TDescriptor(key, data));
(*this)[key] = &D_.back();
diff --git a/library/cpp/testing/unittest/utmain.cpp b/library/cpp/testing/unittest/utmain.cpp
index 305bc6b40f..55564fd3d3 100644
--- a/library/cpp/testing/unittest/utmain.cpp
+++ b/library/cpp/testing/unittest/utmain.cpp
@@ -542,28 +542,28 @@ public:
TEnumeratingProcessor(bool verbose, IOutputStream& stream) noexcept
: Verbose_(verbose)
, Stream_(stream)
- {
- }
-
+ {
+ }
+
~TEnumeratingProcessor() override {
}
bool CheckAccess(TString name, size_t /*num*/) override {
- if (Verbose_) {
- return true;
- } else {
+ if (Verbose_) {
+ return true;
+ } else {
Stream_ << name << "\n";
- return false;
- }
- }
-
+ return false;
+ }
+ }
+
bool CheckAccessTest(TString suite, const char* name) override {
Stream_ << suite << "::" << name << "\n";
return false;
}
-
-private:
- bool Verbose_;
+
+private:
+ bool Verbose_;
IOutputStream& Stream_;
};
diff --git a/library/python/filelock/__init__.py b/library/python/filelock/__init__.py
index f81ff67f37..1d0fe9b535 100644
--- a/library/python/filelock/__init__.py
+++ b/library/python/filelock/__init__.py
@@ -41,7 +41,7 @@ class _NixFileLock(AbstractFileLock):
super(_NixFileLock, self).__init__(path)
from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB
self._locker = lambda lock, blocking: flock(lock, LOCK_EX if blocking else LOCK_EX | LOCK_NB)
- self._unlocker = lambda lock: flock(lock, LOCK_UN)
+ self._unlocker = lambda lock: flock(lock, LOCK_UN)
self._lock = open(self.path, 'a')
set_close_on_exec(self._lock)
diff --git a/library/python/fs/__init__.py b/library/python/fs/__init__.py
index b1b7cde079..f5d2a2b2ce 100644
--- a/library/python/fs/__init__.py
+++ b/library/python/fs/__init__.py
@@ -1,21 +1,21 @@
# coding: utf-8
import codecs
-import errno
-import logging
-import os
+import errno
+import logging
+import os
import random
-import shutil
+import shutil
import six
import stat
import sys
-
+
import library.python.func
import library.python.strings
import library.python.windows
-
+
logger = logging.getLogger(__name__)
-
+
try:
WindowsError
@@ -40,12 +40,12 @@ class CustomFsError(OSError):
# Throws OSError
@errorfix_win
def ensure_dir(path):
- try:
- os.makedirs(path)
- except OSError as e:
+ try:
+ os.makedirs(path)
+ except OSError as e:
if e.errno != errno.EEXIST or not os.path.isdir(path):
- raise
-
+ raise
+
# Directories creation
# If dst is already exists and is a directory - does nothing
@@ -54,9 +54,9 @@ def ensure_dir(path):
@errorfix_win
def create_dirs(path):
ensure_dir(path)
- return path
-
-
+ return path
+
+
# Atomic file/directory move (rename)
# Doesn't guarantee dst replacement
# Atomic if no device boundaries are crossed
@@ -72,8 +72,8 @@ def create_dirs(path):
@library.python.windows.diehard(library.python.windows.RETRIABLE_FILE_ERRORS, tries=_diehard_win_tries)
def move(src, dst):
os.rename(src, dst)
-
-
+
+
# Atomic replacing file move (rename)
# Replaces dst if exists and not a dir
# Doesn't guarantee dst dir replacement
@@ -372,94 +372,94 @@ def copytree3(
ignore_dangling_symlinks=False,
dirs_exist_ok=False,
):
- """Recursively copy a directory tree.
-
- The copytree3 is a port of shutil.copytree function from python-3.2.
- It has additional useful parameters and may be helpful while we are
- on python-2.x. It has to be removed as soon as we have moved to
- python-3.2 or higher.
-
- The destination directory must not already exist.
- If exception(s) occur, an Error is raised with a list of reasons.
-
- If the optional symlinks flag is true, symbolic links in the
- source tree result in symbolic links in the destination tree; if
- it is false, the contents of the files pointed to by symbolic
- links are copied. If the file pointed by the symlink doesn't
- exist, an exception will be added in the list of errors raised in
- an Error exception at the end of the copy process.
-
- You can set the optional ignore_dangling_symlinks flag to true if you
- want to silence this exception. Notice that this has no effect on
- platforms that don't support os.symlink.
-
- The optional ignore argument is a callable. If given, it
- is called with the `src` parameter, which is the directory
- being visited by copytree3(), and `names` which is the list of
- `src` contents, as returned by os.listdir():
-
- callable(src, names) -> ignored_names
-
- Since copytree3() is called recursively, the callable will be
- called once for each directory that is copied. It returns a
- list of names relative to the `src` directory that should
- not be copied.
-
- The optional copy_function argument is a callable that will be used
- to copy each file. It will be called with the source path and the
- destination path as arguments. By default, copy2() is used, but any
- function that supports the same signature (like copy()) can be used.
-
- """
- names = os.listdir(src)
- if ignore is not None:
- ignored_names = ignore(src, names)
- else:
- ignored_names = set()
-
+ """Recursively copy a directory tree.
+
+ The copytree3 is a port of shutil.copytree function from python-3.2.
+ It has additional useful parameters and may be helpful while we are
+ on python-2.x. It has to be removed as soon as we have moved to
+ python-3.2 or higher.
+
+ The destination directory must not already exist.
+ If exception(s) occur, an Error is raised with a list of reasons.
+
+ If the optional symlinks flag is true, symbolic links in the
+ source tree result in symbolic links in the destination tree; if
+ it is false, the contents of the files pointed to by symbolic
+ links are copied. If the file pointed by the symlink doesn't
+ exist, an exception will be added in the list of errors raised in
+ an Error exception at the end of the copy process.
+
+ You can set the optional ignore_dangling_symlinks flag to true if you
+ want to silence this exception. Notice that this has no effect on
+ platforms that don't support os.symlink.
+
+ The optional ignore argument is a callable. If given, it
+ is called with the `src` parameter, which is the directory
+ being visited by copytree3(), and `names` which is the list of
+ `src` contents, as returned by os.listdir():
+
+ callable(src, names) -> ignored_names
+
+ Since copytree3() is called recursively, the callable will be
+ called once for each directory that is copied. It returns a
+ list of names relative to the `src` directory that should
+ not be copied.
+
+ The optional copy_function argument is a callable that will be used
+ to copy each file. It will be called with the source path and the
+ destination path as arguments. By default, copy2() is used, but any
+ function that supports the same signature (like copy()) can be used.
+
+ """
+ names = os.listdir(src)
+ if ignore is not None:
+ ignored_names = ignore(src, names)
+ else:
+ ignored_names = set()
+
if not (dirs_exist_ok and os.path.isdir(dst)):
os.makedirs(dst)
- errors = []
- for name in names:
- if name in ignored_names:
- continue
- srcname = os.path.join(src, name)
- dstname = os.path.join(dst, name)
- try:
- if os.path.islink(srcname):
- linkto = os.readlink(srcname)
- if symlinks:
- # We can't just leave it to `copy_function` because legacy
- # code with a custom `copy_function` may rely on copytree3
- # doing the right thing.
- os.symlink(linkto, dstname)
- else:
- # ignore dangling symlink if the flag is on
- if not os.path.exists(linkto) and ignore_dangling_symlinks:
- continue
- # otherwise let the copy occurs. copy2 will raise an error
- copy_function(srcname, dstname)
- elif os.path.isdir(srcname):
+ errors = []
+ for name in names:
+ if name in ignored_names:
+ continue
+ srcname = os.path.join(src, name)
+ dstname = os.path.join(dst, name)
+ try:
+ if os.path.islink(srcname):
+ linkto = os.readlink(srcname)
+ if symlinks:
+ # We can't just leave it to `copy_function` because legacy
+ # code with a custom `copy_function` may rely on copytree3
+ # doing the right thing.
+ os.symlink(linkto, dstname)
+ else:
+ # ignore dangling symlink if the flag is on
+ if not os.path.exists(linkto) and ignore_dangling_symlinks:
+ continue
+ # otherwise let the copy occurs. copy2 will raise an error
+ copy_function(srcname, dstname)
+ elif os.path.isdir(srcname):
copytree3(srcname, dstname, symlinks, ignore, copy_function, dirs_exist_ok=dirs_exist_ok)
- else:
- # Will raise a SpecialFileError for unsupported file types
- copy_function(srcname, dstname)
- # catch the Error from the recursive copytree3 so that we can
- # continue with other files
+ else:
+ # Will raise a SpecialFileError for unsupported file types
+ copy_function(srcname, dstname)
+ # catch the Error from the recursive copytree3 so that we can
+ # continue with other files
except shutil.Error as err:
- errors.extend(err.args[0])
+ errors.extend(err.args[0])
except EnvironmentError as why:
- errors.append((srcname, dstname, str(why)))
- try:
- shutil.copystat(src, dst)
+ errors.append((srcname, dstname, str(why)))
+ try:
+ shutil.copystat(src, dst)
except OSError as why:
- if WindowsError is not None and isinstance(why, WindowsError):
- # Copying file access times may fail on Windows
- pass
- else:
- errors.extend((src, dst, str(why)))
- if errors:
+ if WindowsError is not None and isinstance(why, WindowsError):
+ # Copying file access times may fail on Windows
+ pass
+ else:
+ errors.extend((src, dst, str(why)))
+ if errors:
raise shutil.Error(errors)
diff --git a/library/python/func/__init__.py b/library/python/func/__init__.py
index 7424361635..5e20802bc7 100644
--- a/library/python/func/__init__.py
+++ b/library/python/func/__init__.py
@@ -1,49 +1,49 @@
-import functools
+import functools
import threading
import collections
-
-
-def map0(func, value):
- return func(value) if value is not None else value
-
-
-def single(x):
- if len(x) != 1:
- raise Exception('Length of {} is not equal to 1'.format(x))
- return x[0]
-
-
-class _Result(object):
- pass
-
-
-def lazy(func):
- result = _Result()
-
+
+
+def map0(func, value):
+ return func(value) if value is not None else value
+
+
+def single(x):
+ if len(x) != 1:
+ raise Exception('Length of {} is not equal to 1'.format(x))
+ return x[0]
+
+
+class _Result(object):
+ pass
+
+
+def lazy(func):
+ result = _Result()
+
@functools.wraps(func)
def wrapper(*args):
- try:
- return result.result
- except AttributeError:
+ try:
+ return result.result
+ except AttributeError:
result.result = func(*args)
-
- return result.result
-
- return wrapper
-
-
-def lazy_property(fn):
- attr_name = '_lazy_' + fn.__name__
-
- @property
- def _lazy_property(self):
- if not hasattr(self, attr_name):
- setattr(self, attr_name, fn(self))
- return getattr(self, attr_name)
-
- return _lazy_property
-
-
+
+ return result.result
+
+ return wrapper
+
+
+def lazy_property(fn):
+ attr_name = '_lazy_' + fn.__name__
+
+ @property
+ def _lazy_property(self):
+ if not hasattr(self, attr_name):
+ setattr(self, attr_name, fn(self))
+ return getattr(self, attr_name)
+
+ return _lazy_property
+
+
class classproperty(object):
def __init__(self, func):
self.func = func
@@ -67,7 +67,7 @@ class lazy_classproperty(object):
def memoize(limit=0, thread_local=False):
assert limit >= 0
- def decorator(func):
+ def decorator(func):
memory = {}
lock = threading.Lock()
@@ -86,7 +86,7 @@ def memoize(limit=0, thread_local=False):
if len(keys) > limit:
del memory[keys.popleft()]
return memory[args]
-
+
else:
def get(args):
@@ -112,15 +112,15 @@ def memoize(limit=0, thread_local=False):
return wrapper
- return decorator
-
-
-# XXX: add test
-def compose(*functions):
- def compose2(f, g):
- return lambda x: f(g(x))
+ return decorator
+
+
+# XXX: add test
+def compose(*functions):
+ def compose2(f, g):
+ return lambda x: f(g(x))
- return functools.reduce(compose2, functions, lambda x: x)
+ return functools.reduce(compose2, functions, lambda x: x)
class Singleton(type):
diff --git a/library/python/func/ut/test_func.py b/library/python/func/ut/test_func.py
index 3c4fad1a07..f3605bafcf 100644
--- a/library/python/func/ut/test_func.py
+++ b/library/python/func/ut/test_func.py
@@ -1,87 +1,87 @@
-import pytest
+import pytest
import threading
-
+
import library.python.func as func
-
-
-def test_map0():
+
+
+def test_map0():
assert None is func.map0(lambda x: x + 1, None)
- assert 3 == func.map0(lambda x: x + 1, 2)
+ assert 3 == func.map0(lambda x: x + 1, 2)
assert None is func.map0(len, None)
- assert 2 == func.map0(len, [1, 2])
-
-
-def test_single():
- assert 1 == func.single([1])
- with pytest.raises(Exception):
- assert 1 == func.single([])
- with pytest.raises(Exception):
- assert 1 == func.single([1, 2])
-
-
-def test_memoize():
- class Counter(object):
- @staticmethod
- def inc():
- Counter._qty = getattr(Counter, '_qty', 0) + 1
- return Counter._qty
-
+ assert 2 == func.map0(len, [1, 2])
+
+
+def test_single():
+ assert 1 == func.single([1])
+ with pytest.raises(Exception):
+ assert 1 == func.single([])
+ with pytest.raises(Exception):
+ assert 1 == func.single([1, 2])
+
+
+def test_memoize():
+ class Counter(object):
+ @staticmethod
+ def inc():
+ Counter._qty = getattr(Counter, '_qty', 0) + 1
+ return Counter._qty
+
@func.memoize()
- def t1(a):
- return a, Counter.inc()
-
+ def t1(a):
+ return a, Counter.inc()
+
@func.memoize()
- def t2(a):
- return a, Counter.inc()
-
+ def t2(a):
+ return a, Counter.inc()
+
@func.memoize()
- def t3(a):
- return a, Counter.inc()
-
+ def t3(a):
+ return a, Counter.inc()
+
@func.memoize()
- def t4(a):
- return a, Counter.inc()
-
+ def t4(a):
+ return a, Counter.inc()
+
@func.memoize()
- def t5(a, b, c):
- return a + b + c, Counter.inc()
-
+ def t5(a, b, c):
+ return a + b + c, Counter.inc()
+
@func.memoize()
- def t6():
- return Counter.inc()
-
+ def t6():
+ return Counter.inc()
+
@func.memoize(limit=2)
def t7(a, _b):
return a, Counter.inc()
- assert (1, 1) == t1(1)
- assert (1, 1) == t1(1)
- assert (2, 2) == t1(2)
- assert (2, 2) == t1(2)
-
- assert (1, 3) == t2(1)
- assert (1, 3) == t2(1)
- assert (2, 4) == t2(2)
- assert (2, 4) == t2(2)
-
- assert (1, 5) == t3(1)
- assert (1, 5) == t3(1)
- assert (2, 6) == t3(2)
- assert (2, 6) == t3(2)
-
- assert (1, 7) == t4(1)
- assert (1, 7) == t4(1)
- assert (2, 8) == t4(2)
- assert (2, 8) == t4(2)
-
- assert (6, 9) == t5(1, 2, 3)
- assert (6, 9) == t5(1, 2, 3)
- assert (7, 10) == t5(1, 2, 4)
- assert (7, 10) == t5(1, 2, 4)
-
- assert 11 == t6()
- assert 11 == t6()
-
+ assert (1, 1) == t1(1)
+ assert (1, 1) == t1(1)
+ assert (2, 2) == t1(2)
+ assert (2, 2) == t1(2)
+
+ assert (1, 3) == t2(1)
+ assert (1, 3) == t2(1)
+ assert (2, 4) == t2(2)
+ assert (2, 4) == t2(2)
+
+ assert (1, 5) == t3(1)
+ assert (1, 5) == t3(1)
+ assert (2, 6) == t3(2)
+ assert (2, 6) == t3(2)
+
+ assert (1, 7) == t4(1)
+ assert (1, 7) == t4(1)
+ assert (2, 8) == t4(2)
+ assert (2, 8) == t4(2)
+
+ assert (6, 9) == t5(1, 2, 3)
+ assert (6, 9) == t5(1, 2, 3)
+ assert (7, 10) == t5(1, 2, 4)
+ assert (7, 10) == t5(1, 2, 4)
+
+ assert 11 == t6()
+ assert 11 == t6()
+
assert (1, 12) == t7(1, None)
assert (2, 13) == t7(2, None)
assert (1, 12) == t7(1, None)
@@ -158,5 +158,5 @@ def test_memoize_thread_local():
th.join()
-if __name__ == '__main__':
- pytest.main([__file__])
+if __name__ == '__main__':
+ pytest.main([__file__])
diff --git a/library/python/pytest/yatest_tools.py b/library/python/pytest/yatest_tools.py
index 6b8b896394..72175cdffa 100644
--- a/library/python/pytest/yatest_tools.py
+++ b/library/python/pytest/yatest_tools.py
@@ -127,27 +127,27 @@ class Test(object):
return [x.status for x in self.subtests].count(status)
-class NoMd5FileException(Exception):
- pass
-
-
-TEST_SUBTEST_SEPARATOR = '::'
-
-
-# TODO: extract color theme logic from ya
-COLOR_THEME = {
- 'test_name': 'light-blue',
- 'test_project_path': 'dark-blue',
- 'test_dir_desc': 'dark-magenta',
- 'test_binary_path': 'light-gray',
-}
-
-
-# XXX: remove me
-class YaCtx(object):
- pass
-
-ya_ctx = YaCtx()
+class NoMd5FileException(Exception):
+ pass
+
+
+TEST_SUBTEST_SEPARATOR = '::'
+
+
+# TODO: extract color theme logic from ya
+COLOR_THEME = {
+ 'test_name': 'light-blue',
+ 'test_project_path': 'dark-blue',
+ 'test_dir_desc': 'dark-magenta',
+ 'test_binary_path': 'light-gray',
+}
+
+
+# XXX: remove me
+class YaCtx(object):
+ pass
+
+ya_ctx = YaCtx()
TRACE_FILE_NAME = "ytest.report.trace"
diff --git a/library/python/ya.make b/library/python/ya.make
index 2e1eb6e0e1..f534798383 100644
--- a/library/python/ya.make
+++ b/library/python/ya.make
@@ -138,7 +138,7 @@ RECURSE(
path
path/tests
protobuf
- pymain
+ pymain
pyscopg2
pytest
pytest-mongodb