How to use time_check_output method in pandera

Best Python code snippet using pandera_python

test.py

Source:test.py Github

copy

Full Screen

1import random2import sys3import time4import pytest5try:6 import user as user_code7except ImportError:8 pass9# предполагаем, что вывод пользователя output не нужен - проверяем только дeкораторы10class MsgError: # вывод сообщения в зависимости от типа ошибки11 def __init__(self, method_name, *args, **kwargs):12 self.result = getattr(self, method_name)(*args, **kwargs)13 def method_exist(self, method_name):14 return f'Проверьте не удален ли декоратор `{method_name} в исходном коде`'15 def method_correct(self, method_name):16 return f'Проверьте корректность работы метода `{method_name}`'17 def is_cached(self, method_name):18 return f'Проверьте, что декоратор `{method_name}()` кэширует данные при вызове'19@pytest.fixture20def msg_err():21 def _msg_err(msg_name, *args, **kwargs):22 msg = MsgError(msg_name, *args, **kwargs)23 return msg.result24 return _msg_err25@pytest.fixture26def input_time_cache():27 data = []28 n1 = random.randint(1, 2)/1029 data.append(n1)30 data.append(random.randint(3, 4)/10)31 data.append(n1)32 return data33@pytest.fixture34def output_time_cache(input_time_cache):35 return input_time_cache[:len(input_time_cache)-1]+[0.0]36class TestFunc:37 time_args = [(0.3,), (0.1,)]38 def test_has_method_time_check(self, msg_err):39 assert hasattr(user_code, 'time_check'), msg_err('method_exist', 'time_check')40 @pytest.mark.parametrize("args", time_args)41 def test_time_check(self, args, msg_err):42 original_stdout = sys.stdout43 with open('time_check_output.txt', 'w', encoding="utf-8") as f:44 sys.stdout = f45 measured_sleep = user_code.time_check(time.sleep)46 measured_sleep(args[0])47 sys.stdout = original_stdout48 with open('time_check_output.txt', 'r', encoding="utf-8") as f:49 decorated_output = f.read()50 assert (f'Время выполнения функции: {round(float(args[0]),1)} с.'51 in decorated_output), msg_err('method_correct', 'time_check')52 def test_has_method_cache_args(self, msg_err):53 assert hasattr(user_code, 'cache_args'), msg_err('method_exist', 'cache_args')54 def test_cache_args(self, input_time_cache, output_time_cache, msg_err):55 original_stdout = sys.stdout56 with open('cache_check_output.txt', 'w', encoding="utf-8") as f:57 sys.stdout = f58 cached_sleep = user_code.time_check(user_code.cache_args(time.sleep))59 for time_par in input_time_cache:60 cached_sleep(time_par)61 sys.stdout = original_stdout62 with open('cache_check_output.txt', 'r', encoding="utf-8") as f:63 cached_output = f.read()64 row_list = cached_output.split('\n')65 for i, time_par in enumerate(output_time_cache):66 assert (f'Время выполнения функции: {round(float(time_par),1)} с.' in67 row_list[i]), msg_err('method_correct', 'cache_args')68 assert (f'Время выполнения функции: {round(float(input_time_cache[2]),1)} с.'...

Full Screen

Full Screen

dataframe_schema.py

Source:dataframe_schema.py Github

copy

Full Screen

...63 def peakmem_check_input(self):64 @check_input(self.in_schema)65 def transform_first_arg(self):66 return Decorators.transformer(self.df)67 def time_check_output(self):68 @check_output(self.out_schema)69 def transform_first_arg(self):70 return Decorators.transformer(self.df)71 def mem_check_output(self):72 @check_output(self.out_schema)73 def transform_first_arg(self):74 return Decorators.transformer(self.df)75 def peakmem_check_output(self):76 @check_output(self.out_schema)77 def transform_first_arg(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pandera automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful