diff options
author | danila-eremin <danila-eremin@yandex-team.ru> | 2022-02-10 16:46:21 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:21 +0300 |
commit | 9d80afb43be16931e653a688c5e0f585101ff4f8 (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /library | |
parent | 358e631d1a69242d3ae4d6e6b1e4f7581d03133b (diff) | |
download | ydb-9d80afb43be16931e653a688c5e0f585101ff4f8.tar.gz |
Restoring authorship annotation for <danila-eremin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library')
-rw-r--r-- | library/cpp/digest/md5/bench/main.cpp | 12 | ||||
-rw-r--r-- | library/cpp/digest/md5/bench/ya.make | 2 | ||||
-rw-r--r-- | library/cpp/digest/md5/md5.cpp | 190 | ||||
-rw-r--r-- | library/cpp/digest/md5/md5.h | 46 | ||||
-rw-r--r-- | library/cpp/digest/md5/md5_ut.cpp | 8 | ||||
-rw-r--r-- | library/cpp/tvmauth/client/ut/settings_ut.cpp | 4 | ||||
-rw-r--r-- | library/python/pytest/plugins/collection.py | 72 | ||||
-rw-r--r-- | library/python/pytest/plugins/ya.py | 108 | ||||
-rw-r--r-- | library/python/pytest/rewrite.py | 20 | ||||
-rw-r--r-- | library/python/testing/yatest_common/yatest/common/runtime.py | 4 |
10 files changed, 233 insertions, 233 deletions
diff --git a/library/cpp/digest/md5/bench/main.cpp b/library/cpp/digest/md5/bench/main.cpp index e633a64704..70672e6741 100644 --- a/library/cpp/digest/md5/bench/main.cpp +++ b/library/cpp/digest/md5/bench/main.cpp @@ -1,15 +1,15 @@ -#include <benchmark/benchmark.h> - +#include <benchmark/benchmark.h> + #include <library/cpp/digest/md5/md5.h> #define MD5_DEF(N) \ - static void MD5Benchmark_##N(benchmark::State& st) { \ + static void MD5Benchmark_##N(benchmark::State& st) { \ char buf[N]; \ - for (auto _ : st) { \ + for (auto _ : st) { \ Y_DO_NOT_OPTIMIZE_AWAY(MD5().Update(buf, sizeof(buf))); \ } \ - } \ - BENCHMARK(MD5Benchmark_##N); + } \ + BENCHMARK(MD5Benchmark_##N); MD5_DEF(32) MD5_DEF(64) diff --git a/library/cpp/digest/md5/bench/ya.make b/library/cpp/digest/md5/bench/ya.make index 0c7211f82a..5c3e3c1c42 100644 --- a/library/cpp/digest/md5/bench/ya.make +++ b/library/cpp/digest/md5/bench/ya.make @@ -1,4 +1,4 @@ -G_BENCHMARK() +G_BENCHMARK() OWNER( pg diff --git a/library/cpp/digest/md5/md5.cpp b/library/cpp/digest/md5/md5.cpp index b10e63e425..24a5b69eef 100644 --- a/library/cpp/digest/md5/md5.cpp +++ b/library/cpp/digest/md5/md5.cpp @@ -1,17 +1,17 @@ #include "md5.h" -#include <library/cpp/string_utils/base64/base64.h> +#include <library/cpp/string_utils/base64/base64.h> #include <util/stream/input.h> #include <util/stream/file.h> #include <util/string/hex.h> -#include <contrib/libs/nayuki_md5/md5.h> +#include <contrib/libs/nayuki_md5/md5.h> namespace { - constexpr size_t MD5_BLOCK_LENGTH = 64; - constexpr size_t MD5_PADDING_SHIFT = 56; + constexpr size_t MD5_BLOCK_LENGTH = 64; + constexpr size_t MD5_PADDING_SHIFT = 56; constexpr size_t MD5_HEX_DIGEST_LENGTH = 32; struct TMd5Stream: public IOutputStream { @@ -26,14 +26,14 @@ namespace { MD5* M_; }; - - inline TArrayRef<const ui8> MakeUnsignedArrayRef(const void* data, const size_t size) { - return MakeArrayRef(static_cast<const ui8*>(data), size); - } - - inline TArrayRef<const ui8> MakeUnsignedArrayRef(const TArrayRef<const char>& data) { - return MakeUnsignedArrayRef(data.data(), data.size()); - } + + inline TArrayRef<const ui8> MakeUnsignedArrayRef(const void* data, const size_t size) { + return MakeArrayRef(static_cast<const ui8*>(data), size); + } + + inline TArrayRef<const ui8> MakeUnsignedArrayRef(const TArrayRef<const char>& data) { + return MakeUnsignedArrayRef(data.data(), data.size()); + } } char* MD5::File(const char* filename, char* buf) { @@ -57,23 +57,23 @@ TString MD5::File(const TString& filename) { return buf; } -char* MD5::Data(const TArrayRef<const ui8>& data, char* buf) { - return MD5().Update(data).End(buf); -} - +char* MD5::Data(const TArrayRef<const ui8>& data, char* buf) { + return MD5().Update(data).End(buf); +} + char* MD5::Data(const void* data, size_t len, char* buf) { - return Data(MakeUnsignedArrayRef(data, len), buf); + return Data(MakeUnsignedArrayRef(data, len), buf); } -TString MD5::Data(const TArrayRef<const ui8>& data) { +TString MD5::Data(const TArrayRef<const ui8>& data) { TString buf; buf.ReserveAndResize(MD5_HEX_DIGEST_LENGTH); - Data(data, buf.begin()); + Data(data, buf.begin()); return buf; } TString MD5::Data(TStringBuf data) { - return Data(MakeUnsignedArrayRef(data)); + return Data(MakeUnsignedArrayRef(data)); } char* MD5::Stream(IInputStream* in, char* buf) { @@ -88,7 +88,7 @@ MD5& MD5::Update(IInputStream* in) { return *this; } -static const ui8 PADDING[MD5_BLOCK_LENGTH] = { +static const ui8 PADDING[MD5_BLOCK_LENGTH] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -96,8 +96,8 @@ static const ui8 PADDING[MD5_BLOCK_LENGTH] = { /* MD5 initialization. Begins an MD5 operation, writing a new context. */ void MD5::Init() { - BufferSize = 0; - StreamSize = 0; + BufferSize = 0; + StreamSize = 0; /* Load magic initialization constants. */ State[0] = 0x67452301; State[1] = 0xefcdab89; @@ -111,30 +111,30 @@ void MD5::Init() { * context. */ -void MD5::UpdatePart(TArrayRef<const ui8> data) { - /* Count input bytes */ - StreamSize += data.size(); - if (BufferSize > 0) { - /* Filling remaining buffer */ - const ui8 freeBufferSize = MD5_BLOCK_LENGTH - BufferSize; - const ui8 partLen = data.size() >= freeBufferSize ? freeBufferSize : data.size(); - memcpy(&Buffer[BufferSize], data.data(), partLen); - BufferSize += partLen; - data = data.Slice(partLen); - if (BufferSize == MD5_BLOCK_LENGTH) { - /* Buffer is full and ready for hashing */ - md5_compress(State, Buffer); - BufferSize = 0; - } - } - /* Processing input by chanks */ - while (data.size() >= MD5_BLOCK_LENGTH) { - md5_compress(State, data.data()); - data = data.Slice(MD5_BLOCK_LENGTH); - } - /* Save remaining input in buffer */ - memcpy(Buffer, data.data(), data.size()); - BufferSize += data.size(); +void MD5::UpdatePart(TArrayRef<const ui8> data) { + /* Count input bytes */ + StreamSize += data.size(); + if (BufferSize > 0) { + /* Filling remaining buffer */ + const ui8 freeBufferSize = MD5_BLOCK_LENGTH - BufferSize; + const ui8 partLen = data.size() >= freeBufferSize ? freeBufferSize : data.size(); + memcpy(&Buffer[BufferSize], data.data(), partLen); + BufferSize += partLen; + data = data.Slice(partLen); + if (BufferSize == MD5_BLOCK_LENGTH) { + /* Buffer is full and ready for hashing */ + md5_compress(State, Buffer); + BufferSize = 0; + } + } + /* Processing input by chanks */ + while (data.size() >= MD5_BLOCK_LENGTH) { + md5_compress(State, data.data()); + data = data.Slice(MD5_BLOCK_LENGTH); + } + /* Save remaining input in buffer */ + memcpy(Buffer, data.data(), data.size()); + BufferSize += data.size(); } /* @@ -142,19 +142,19 @@ void MD5::UpdatePart(TArrayRef<const ui8> data) { */ void MD5::Pad() { - size_t streamSize = StreamSize; - - const size_t paddingSize = (MD5_PADDING_SHIFT > BufferSize) ? (MD5_PADDING_SHIFT - BufferSize) : (MD5_PADDING_SHIFT + MD5_BLOCK_LENGTH - BufferSize); - Update(PADDING, paddingSize); - - // Size of stream in bits - // If size greater than 2^64 - 1 only lower 64 bits used - streamSize <<= 3; - for (int i = 0; i < 8; ++i, streamSize >>= 8) { - // Storing in reverse order - Buffer[MD5_PADDING_SHIFT + i] = static_cast<ui8>(streamSize & 0xFFU); - } - md5_compress(State, Buffer); + size_t streamSize = StreamSize; + + const size_t paddingSize = (MD5_PADDING_SHIFT > BufferSize) ? (MD5_PADDING_SHIFT - BufferSize) : (MD5_PADDING_SHIFT + MD5_BLOCK_LENGTH - BufferSize); + Update(PADDING, paddingSize); + + // Size of stream in bits + // If size greater than 2^64 - 1 only lower 64 bits used + streamSize <<= 3; + for (int i = 0; i < 8; ++i, streamSize >>= 8) { + // Storing in reverse order + Buffer[MD5_PADDING_SHIFT + i] = static_cast<ui8>(streamSize & 0xFFU); + } + md5_compress(State, Buffer); } /* @@ -162,35 +162,35 @@ void MD5::Pad() { * the message digest and zeroizing the context. */ -ui8* MD5::Final(ui8 digest[16]) { +ui8* MD5::Final(ui8 digest[16]) { /* Do padding. */ Pad(); /* Store state in digest */ - memcpy(digest, State, 16); + memcpy(digest, State, 16); /* Zeroize sensitive information. */ - Init(); + Init(); return digest; } char* MD5::End(char* buf) { static const char hex[] = "0123456789abcdef"; - ui8 digest[16]; + ui8 digest[16]; if (!buf) buf = (char*)malloc(33); if (!buf) return nullptr; Final(digest); - for (ui8 i = 0; i < MD5_HEX_DIGEST_LENGTH / 2; i++) { - buf[i * 2] = hex[digest[i] >> 4]; - buf[i * 2 + 1] = hex[digest[i] & 0x0f]; + for (ui8 i = 0; i < MD5_HEX_DIGEST_LENGTH / 2; i++) { + buf[i * 2] = hex[digest[i] >> 4]; + buf[i * 2 + 1] = hex[digest[i] & 0x0f]; } - buf[32] = '\0'; + buf[32] = '\0'; return buf; } char* MD5::End_b64(char* buf) { - ui8 digest[16]; + ui8 digest[16]; if (!buf) buf = (char*)malloc(25); if (!buf) @@ -202,7 +202,7 @@ char* MD5::End_b64(char* buf) { } ui64 MD5::EndHalfMix() { - ui8 digest[16]; + ui8 digest[16]; Final(digest); ui64 res = 0; for (int i = 3; i >= 0; i--) { @@ -212,47 +212,47 @@ ui64 MD5::EndHalfMix() { return res; } -TString MD5::Calc(TStringBuf data) { - return Calc(MakeUnsignedArrayRef(data)); -} +TString MD5::Calc(TStringBuf data) { + return Calc(MakeUnsignedArrayRef(data)); +} -TString MD5::Calc(const TArrayRef<const ui8>& data) { - return Data(data); -} +TString MD5::Calc(const TArrayRef<const ui8>& data) { + return Data(data); +} -TString MD5::CalcRaw(TStringBuf data) { - return CalcRaw(MakeUnsignedArrayRef(data)); +TString MD5::CalcRaw(TStringBuf data) { + return CalcRaw(MakeUnsignedArrayRef(data)); } -TString MD5::CalcRaw(const TArrayRef<const ui8>& data) { +TString MD5::CalcRaw(const TArrayRef<const ui8>& data) { TString result; - result.ReserveAndResize(16); - MD5().Update(data).Final(reinterpret_cast<ui8*>(result.begin())); + result.ReserveAndResize(16); + MD5().Update(data).Final(reinterpret_cast<ui8*>(result.begin())); return result; } ui64 MD5::CalcHalfMix(const char* data, size_t len) { - return CalcHalfMix(MakeUnsignedArrayRef(data, len)); + return CalcHalfMix(MakeUnsignedArrayRef(data, len)); +} + +ui64 MD5::CalcHalfMix(TStringBuf data) { + return CalcHalfMix(MakeUnsignedArrayRef(data)); +} + +ui64 MD5::CalcHalfMix(const TArrayRef<const ui8>& data) { + return MD5().Update(data).EndHalfMix(); } -ui64 MD5::CalcHalfMix(TStringBuf data) { - return CalcHalfMix(MakeUnsignedArrayRef(data)); +bool MD5::IsMD5(TStringBuf data) { + return IsMD5(MakeUnsignedArrayRef(data)); } -ui64 MD5::CalcHalfMix(const TArrayRef<const ui8>& data) { - return MD5().Update(data).EndHalfMix(); -} - -bool MD5::IsMD5(TStringBuf data) { - return IsMD5(MakeUnsignedArrayRef(data)); -} - -bool MD5::IsMD5(const TArrayRef<const ui8>& data) { +bool MD5::IsMD5(const TArrayRef<const ui8>& data) { if (data.size() != 32) { return false; } - for (const ui8 *p = data.data(), *e = data.data() + data.size(); p != e; ++p) { - if (Char2DigitTable[*p] == '\xff') { + for (const ui8 *p = data.data(), *e = data.data() + data.size(); p != e; ++p) { + if (Char2DigitTable[*p] == '\xff') { return false; } } diff --git a/library/cpp/digest/md5/md5.h b/library/cpp/digest/md5/md5.h index 6dea247e3d..2c17aa0518 100644 --- a/library/cpp/digest/md5/md5.h +++ b/library/cpp/digest/md5/md5.h @@ -14,20 +14,20 @@ public: void Init(); inline MD5& Update(const void* data, size_t len) { - return Update(MakeArrayRef(static_cast<const ui8*>(data), len)); - } + return Update(MakeArrayRef(static_cast<const ui8*>(data), len)); + } - inline MD5& Update(TStringBuf data) { - return Update(data.data(), data.size()); - } + inline MD5& Update(TStringBuf data) { + return Update(data.data(), data.size()); + } - inline MD5& Update(const TArrayRef<const ui8> data) { - UpdatePart(data); + inline MD5& Update(const TArrayRef<const ui8> data) { + UpdatePart(data); return *this; } void Pad(); - ui8* Final(ui8[16]); + ui8* Final(ui8[16]); // buf must be char[33]; char* End(char* buf); @@ -49,29 +49,29 @@ public: static TString File(const TString& filename); static char* Data(const void* data, size_t len, char* buf); - static char* Data(const TArrayRef<const ui8>& data, char* buf); - static TString Data(const TArrayRef<const ui8>& data); + static char* Data(const TArrayRef<const ui8>& data, char* buf); + static TString Data(const TArrayRef<const ui8>& data); static TString Data(TStringBuf data); static char* Stream(IInputStream* in, char* buf); - static TString Calc(TStringBuf data); // 32-byte hex-encoded - static TString Calc(const TArrayRef<const ui8>& data); // 32-byte hex-encoded - static TString CalcRaw(TStringBuf data); // 16-byte raw - static TString CalcRaw(const TArrayRef<const ui8>& data); // 16-byte raw + static TString Calc(TStringBuf data); // 32-byte hex-encoded + static TString Calc(const TArrayRef<const ui8>& data); // 32-byte hex-encoded + static TString CalcRaw(TStringBuf data); // 16-byte raw + static TString CalcRaw(const TArrayRef<const ui8>& data); // 16-byte raw - static ui64 CalcHalfMix(TStringBuf data); - static ui64 CalcHalfMix(const TArrayRef<const ui8>& data); + static ui64 CalcHalfMix(TStringBuf data); + static ui64 CalcHalfMix(const TArrayRef<const ui8>& data); static ui64 CalcHalfMix(const char* data, size_t len); - static bool IsMD5(TStringBuf data); - static bool IsMD5(const TArrayRef<const ui8>& data); + static bool IsMD5(TStringBuf data); + static bool IsMD5(const TArrayRef<const ui8>& data); private: - void UpdatePart(TArrayRef<const ui8> data); + void UpdatePart(TArrayRef<const ui8> data); private: - ui8 BufferSize; /* size of buffer */ - ui8 Buffer[64]; /* input buffer */ - ui32 State[4]; /* state (ABCD) */ - ui64 StreamSize; /* total bytes in input stream */ + ui8 BufferSize; /* size of buffer */ + ui8 Buffer[64]; /* input buffer */ + ui32 State[4]; /* state (ABCD) */ + ui64 StreamSize; /* total bytes in input stream */ }; diff --git a/library/cpp/digest/md5/md5_ut.cpp b/library/cpp/digest/md5/md5_ut.cpp index 3b596d9d74..1c3e4ad0a9 100644 --- a/library/cpp/digest/md5/md5_ut.cpp +++ b/library/cpp/digest/md5/md5_ut.cpp @@ -18,11 +18,11 @@ Y_UNIT_TEST_SUITE(TMD5Test) { TString s(r.End(rs)); s.to_lower(); - UNIT_ASSERT_NO_DIFF(s, TStringBuf("3ac00dd696b966fd74deee3c35a59d8f")); + UNIT_ASSERT_NO_DIFF(s, TStringBuf("3ac00dd696b966fd74deee3c35a59d8f")); TString result = r.Calc(TStringBuf(b)); result.to_lower(); - UNIT_ASSERT_NO_DIFF(result, TStringBuf("3ac00dd696b966fd74deee3c35a59d8f")); + UNIT_ASSERT_NO_DIFF(result, TStringBuf("3ac00dd696b966fd74deee3c35a59d8f")); } Y_UNIT_TEST(TestFile) { @@ -39,10 +39,10 @@ Y_UNIT_TEST_SUITE(TMD5Test) { TString fileHash = MD5::File(tmpFile.data(), fileBuf); TString memoryHash = MD5::Data((const unsigned char*)s.data(), s.size(), memBuf); - UNIT_ASSERT_NO_DIFF(fileHash, memoryHash); + UNIT_ASSERT_NO_DIFF(fileHash, memoryHash); fileHash = MD5::File(tmpFile); - UNIT_ASSERT_NO_DIFF(fileHash, memoryHash); + UNIT_ASSERT_NO_DIFF(fileHash, memoryHash); NFs::Remove(tmpFile); fileHash = MD5::File(tmpFile); diff --git a/library/cpp/tvmauth/client/ut/settings_ut.cpp b/library/cpp/tvmauth/client/ut/settings_ut.cpp index dbb04272a1..76c9542442 100644 --- a/library/cpp/tvmauth/client/ut/settings_ut.cpp +++ b/library/cpp/tvmauth/client/ut/settings_ut.cpp @@ -37,7 +37,7 @@ Y_UNIT_TEST_SUITE(ClientSettings) { TTestCase{ .Name = "dsts with selfTvmId", .Settings = { - .SelfTvmId = 43, + .SelfTvmId = 43, .FetchServiceTicketsForDsts = {42}, }, .Err = "Secret is required for fetching of Service Tickets", @@ -47,7 +47,7 @@ Y_UNIT_TEST_SUITE(ClientSettings) { .Settings = { .SelfTvmId = 43, .Secret = TStringBuf("foobar"), - .FetchServiceTicketsForDsts = {42}, + .FetchServiceTicketsForDsts = {42}, }, .Err = "", }, diff --git a/library/python/pytest/plugins/collection.py b/library/python/pytest/plugins/collection.py index 9c29494de8..e36f47a78f 100644 --- a/library/python/pytest/plugins/collection.py +++ b/library/python/pytest/plugins/collection.py @@ -12,40 +12,40 @@ import library.python.testing.filter.filter as test_filter class LoadedModule(_pytest.python.Module): - def __init__(self, parent, name, **kwargs): - self.name = name + '.py' - self.session = parent - self.parent = parent - self.config = parent.config + def __init__(self, parent, name, **kwargs): + self.name = name + '.py' + self.session = parent + self.parent = parent + self.config = parent.config self.keywords = {} self.own_markers = [] - self.fspath = py.path.local() - - @classmethod - def from_parent(cls, **kwargs): - namespace = kwargs.pop('namespace', True) - kwargs.setdefault('fspath', py.path.local()) - - loaded_module = getattr(super(LoadedModule, cls), 'from_parent', cls)(**kwargs) - loaded_module.namespace = namespace - - return loaded_module - + self.fspath = py.path.local() + + @classmethod + def from_parent(cls, **kwargs): + namespace = kwargs.pop('namespace', True) + kwargs.setdefault('fspath', py.path.local()) + + loaded_module = getattr(super(LoadedModule, cls), 'from_parent', cls)(**kwargs) + loaded_module.namespace = namespace + + return loaded_module + @property - def _nodeid(self): - if os.getenv('CONFTEST_LOAD_POLICY') == 'LOCAL': + def _nodeid(self): + if os.getenv('CONFTEST_LOAD_POLICY') == 'LOCAL': return self._getobj().__file__ else: return self.name - - @property - def nodeid(self): - return self._nodeid + + @property + def nodeid(self): + return self._nodeid def _getobj(self): - module_name = self.name[:-len('.py')] + module_name = self.name[:-len('.py')] if self.namespace: - module_name = '__tests__.' + module_name + module_name = '__tests__.' + module_name __import__(module_name) return sys.modules[module_name] @@ -62,19 +62,19 @@ class DoctestModule(LoadedModule): runner = doctest.DebugRunner(verbose=0, optionflags=optionflags) try: - for test in finder.find(module, self.name[:-len('.py')]): + for test in finder.find(module, self.name[:-len('.py')]): if test.examples: # skip empty doctests - yield getattr(_pytest.doctest.DoctestItem, 'from_parent', _pytest.doctest.DoctestItem)( - name=test.name, - parent=self, - runner=runner, - dtest=test) + yield getattr(_pytest.doctest.DoctestItem, 'from_parent', _pytest.doctest.DoctestItem)( + name=test.name, + parent=self, + runner=runner, + dtest=test) except Exception: import logging logging.exception('DoctestModule failed, probably you can add NO_DOCTESTS() macro to ya.make') etype, exc, tb = sys.exc_info() msg = 'DoctestModule failed, probably you can add NO_DOCTESTS() macro to ya.make' - reraise(etype, type(exc)('{}\n{}'.format(exc, msg)), tb) + reraise(etype, type(exc)('{}\n{}'.format(exc, msg)), tb) # NOTE: Since we are overriding collect method of pytest session, pytest hooks are not invoked during collection. @@ -88,7 +88,7 @@ def pytest_ignore_collect(module, session, filenames_from_full_filters, accept_f test_file_filter = getattr(session.config.option, 'test_file_filter', None) if test_file_filter is None: return False - if module.name != test_file_filter.replace('/', '.'): + if module.name != test_file_filter.replace('/', '.'): return True return False @@ -112,17 +112,17 @@ class CollectionPlugin(object): filenames_filter = set(map(lambda x: x.split('::')[0], full_names_filter)) for test_module in self._test_modules: - module = LoadedModule.from_parent(name=test_module, parent=session) + module = LoadedModule.from_parent(name=test_module, parent=session) if not pytest_ignore_collect(module, session, filenames_filter, accept_filename_predicate): yield module if os.environ.get('YA_PYTEST_DISABLE_DOCTEST', 'no') == 'no': - module = DoctestModule.from_parent(name=test_module, parent=session) + module = DoctestModule.from_parent(name=test_module, parent=session) if not pytest_ignore_collect(module, session, filenames_filter, accept_filename_predicate): yield module if os.environ.get('YA_PYTEST_DISABLE_DOCTEST', 'no') == 'no': for doctest_module in self._doctest_modules: - yield DoctestModule.from_parent(name=doctest_module, parent=session, namespace=False) + yield DoctestModule.from_parent(name=doctest_module, parent=session, namespace=False) session.collect = collect diff --git a/library/python/pytest/plugins/ya.py b/library/python/pytest/plugins/ya.py index dae99f41d5..1bde03042d 100644 --- a/library/python/pytest/plugins/ya.py +++ b/library/python/pytest/plugins/ya.py @@ -23,9 +23,9 @@ import six import _pytest import _pytest._io -import _pytest.mark +import _pytest.mark import _pytest.outcomes -import _pytest.skipping +import _pytest.skipping from _pytest.warning_types import PytestUnhandledCoroutineWarning @@ -293,38 +293,38 @@ def pytest_configure(config): signal.signal(signal.SIGUSR2, _graceful_shutdown) -session_should_exit = False - - -def _graceful_shutdown_on_log(should_exit): - if should_exit: - pytest.exit("Graceful shutdown requested") - - -def pytest_runtest_logreport(report): - _graceful_shutdown_on_log(session_should_exit) - - -def pytest_runtest_logstart(nodeid, location): - _graceful_shutdown_on_log(session_should_exit) - - -def pytest_runtest_logfinish(nodeid, location): - _graceful_shutdown_on_log(session_should_exit) - - +session_should_exit = False + + +def _graceful_shutdown_on_log(should_exit): + if should_exit: + pytest.exit("Graceful shutdown requested") + + +def pytest_runtest_logreport(report): + _graceful_shutdown_on_log(session_should_exit) + + +def pytest_runtest_logstart(nodeid, location): + _graceful_shutdown_on_log(session_should_exit) + + +def pytest_runtest_logfinish(nodeid, location): + _graceful_shutdown_on_log(session_should_exit) + + def _graceful_shutdown(*args): - global session_should_exit - session_should_exit = True + global session_should_exit + session_should_exit = True try: import library.python.coverage library.python.coverage.stop_coverage_tracing() except ImportError: pass traceback.print_stack(file=sys.stderr) - capman = pytest_config.pluginmanager.getplugin("capturemanager") - capman.suspend(in_=True) - _graceful_shutdown_on_log(not capman.is_globally_capturing()) + capman = pytest_config.pluginmanager.getplugin("capturemanager") + capman.suspend(in_=True) + _graceful_shutdown_on_log(not capman.is_globally_capturing()) def _get_rusage(): @@ -368,7 +368,7 @@ def _collect_test_rusage(item): def _get_item_tags(item): tags = [] for key, value in item.keywords.items(): - if key == 'pytestmark' and isinstance(value, list): + if key == 'pytestmark' and isinstance(value, list): for mark in value: tags.append(mark.name) elif isinstance(value, _pytest.mark.MarkDecorator): @@ -541,7 +541,7 @@ def pytest_pyfunc_call(pyfuncitem): return True -@pytest.hookimpl(hookwrapper=True) +@pytest.hookimpl(hookwrapper=True) def pytest_runtest_makereport(item, call): def logreport(report, result, call): test_item = TestItem(report, result, pytest_config.option.test_suffix) @@ -550,10 +550,10 @@ def pytest_runtest_makereport(item, call): pytest_config.ya_trace_reporter.dump_suite_metrics() pytest_config.ya_trace_reporter.on_log_report(test_item) - - if report.outcome == "failed": - yatest_logger.error(report.longrepr) - + + if report.outcome == "failed": + yatest_logger.error(report.longrepr) + if report.when == "call": _collect_test_rusage(item) pytest_config.ya_trace_reporter.on_finish_test_case(test_item) @@ -572,16 +572,16 @@ def pytest_runtest_makereport(item, call): pytest_config.ya_trace_reporter.on_finish_test_case(test_item, duration_only=True) pytest_config.ya_trace_reporter.on_finish_test_class(test_item) - outcome = yield - rep = outcome.get_result() - result = None + outcome = yield + rep = outcome.get_result() + result = None if hasattr(item, 'retval') and item.retval is not None: result = item.retval if not pytest_config.from_ya_test: ti = TestItem(rep, result, pytest_config.option.test_suffix) tr = pytest_config.pluginmanager.getplugin('terminalreporter') tr.write_line("{} - Validating canonical data is not supported when running standalone binary".format(ti), yellow=True, bold=True) - logreport(rep, result, call) + logreport(rep, result, call) def pytest_make_parametrize_id(config, val, argname): @@ -652,25 +652,25 @@ class TestItem(object): self.set_error(report.when + " failed:\n" + self._error) else: self.set_error("") - - report_teststatus = _pytest.skipping.pytest_report_teststatus(report) - if report_teststatus is not None: - report_teststatus = report_teststatus[0] - - if report_teststatus == 'xfailed': - self._status = 'xfail' - self.set_error(report.wasxfail, 'imp') - elif report_teststatus == 'xpassed': - self._status = 'xpass' - self.set_error("Test unexpectedly passed") - elif report.skipped: - self._status = 'skipped' - self.set_error(yatest_lib.tools.to_utf8(report.longrepr[-1])) - elif report.passed: + + report_teststatus = _pytest.skipping.pytest_report_teststatus(report) + if report_teststatus is not None: + report_teststatus = report_teststatus[0] + + if report_teststatus == 'xfailed': + self._status = 'xfail' + self.set_error(report.wasxfail, 'imp') + elif report_teststatus == 'xpassed': + self._status = 'xpass' + self.set_error("Test unexpectedly passed") + elif report.skipped: + self._status = 'skipped' + self.set_error(yatest_lib.tools.to_utf8(report.longrepr[-1])) + elif report.passed: self._status = 'good' self.set_error("") - else: - self._status = 'fail' + else: + self._status = 'fail' @property def status(self): diff --git a/library/python/pytest/rewrite.py b/library/python/pytest/rewrite.py index 5171dbd345..4cebcb1edd 100644 --- a/library/python/pytest/rewrite.py +++ b/library/python/pytest/rewrite.py @@ -10,12 +10,12 @@ try: import importlib.util except ImportError: pass - -try: - from pathlib import Path -except ImportError: - pass - + +try: + from pathlib import Path +except ImportError: + pass + from __res import importer import sys import six @@ -49,10 +49,10 @@ class AssertionRewritingHook(rewrite.AssertionRewritingHook): except ImportError: return None - if hasattr(self._rewritten_names, 'add'): - self._rewritten_names.add(name) - else: - self._rewritten_names[name] = Path(path[0]) + if hasattr(self._rewritten_names, 'add'): + self._rewritten_names.add(name) + else: + self._rewritten_names[name] = Path(path[0]) state.trace("rewriting %s" % name) co = _rewrite_test(self.config, name) diff --git a/library/python/testing/yatest_common/yatest/common/runtime.py b/library/python/testing/yatest_common/yatest/common/runtime.py index f1b133a27f..e55e193446 100644 --- a/library/python/testing/yatest_common/yatest/common/runtime.py +++ b/library/python/testing/yatest_common/yatest/common/runtime.py @@ -212,7 +212,7 @@ def test_output_path(path=None): """ Get dir in the suite output_path for the current test case """ - test_out_dir = os.path.splitext(_get_ya_config().current_test_log_path)[0] + test_out_dir = os.path.splitext(_get_ya_config().current_test_log_path)[0] try: os.makedirs(test_out_dir) except OSError as e: @@ -313,7 +313,7 @@ class Context(object): @property def test_name(self): - return _get_ya_config().current_test_name + return _get_ya_config().current_test_name @property def sanitize(self): |