How to use test_get_data method in localstack

Best Python code snippet using localstack_python

test_mycalc.py

Source:test_mycalc.py Github

copy

Full Screen

...35def setup_function():36 print("开始读取数据...")37def teardown_function():38 print("数据读取结束...")39def test_get_data(t='add'):40 with open(yaml_path, 'r', encoding='utf-8') as f:41 data = yaml.safe_load(f)42 value = data[t]["value"]43 ids = data[t]["id"]44 return [value, ids]45 # return [value],[ids]46#47# print(type(test_get_data()))48# print(test_get_data())49# 计算加法50class Test_mycalc_Add:51 def setup_class(self):52 self.calc = myCalc()53 self.calc = myCalc()54 print("I'm setup_class")55 def teardown_class(self):56 print("I'm teardown_class")57 def setup(self):58 print("开始加法计算")59 def teardown(self):60 print("结束加法计算")61 # 参数直接赋值62 @pytest.mark.add163 @pytest.mark.parametrize(64 'a,b,expect',65 [(1, 2, 3), (0.1, 0.8, 0.9), (0, 8, 8), pytest.param(7, 8, 50, marks=pytest.mark.xfail)],66 ids=['int', 'float', 'zero', 'xfail']67 )68 def test_add(self, a, b, expect):69 calc_result = self.calc.add(a, b)70 if type(a) == float and type(b) == float:71 a = round(a, 3)72 b = round(b, 3)73 calc_result = round(calc_result, 3)74 assert calc_result == expect75 # 参数从yaml中读取76 @pytest.mark.add277 @pytest.mark.parametrize(78 'a,b,expect',79 test_get_data()[0],80 ids=test_get_data()[1]81 )82 def test_add_yaml(self, a, b, expect):83 calc_result = self.calc.add(a, b)84 assert calc_result == expect85 def test_a(self):86 result = self.calc.add(1, 2)87 assert 3 == result88 print("测试用例test_a")89 t = map(lambda x: x + 1, range(1, 6))90 print(list(t))91# 计算除法92# 用了两种方法捕获异常:1.python自带try except机制 2.pytest.raises机制93class Test_mycalc_Divide:94 def setup_class(self):95 self.calc = myCalc()96 print("I'm setup class from Test_mycalc_Divide")97 def teardown_class(self):98 print("I'm teardown class from Test_mycalc_Divide")99 def setup(self):100 print("开始除法计算")101 def teardown(self):102 print("结束除法计算")103 # 参数直接赋值104 @pytest.mark.divide1105 @pytest.mark.parametrize('a,b,expect', [106 (100, 2, 50),107 (0.8, 4, 0.2),108 (7, 0, 7),109 ('test', 'hello', 1)], ids=['int', 'float', 'zero', 'str'])110 def test_divide(self, a, b, expect):111 if b == 0:112 with pytest.raises(ZeroDivisionError) as exc_info: # pytest.raise是报错才通过。不抛异常, 它就会报错了113 calc_result = self.calc.divide(a, b)114 # raise ZeroDivisionError("division by zero")115 # if exc_info.type == ZeroDivisionError:116 # assert exc_info.type is ZeroDivisionError117 # assert exc_info.value.args[0] == "division by zero"118 elif type(a) == str or type(b) == str:119 with pytest.raises(TypeError) as exc_info:120 calc_result = self.calc.divide(a, b)121 else:122 calc_result = self.calc.divide(a, b)123 assert calc_result == expect124 # 参数从yaml中读取125 @pytest.mark.divide2126 @pytest.mark.parametrize('a,b,expect',127 test_get_data("divide")[0],128 ids=test_get_data("divide")[1])129 def test_divide_yaml(self, a, b, expect):130 try:131 if b == 0:132 raise ZeroDivisionError133 elif type(a) == str or type(b) == str:134 raise TypeError # 注意,用python自带的try except机制捕捉异常的时候,如果引发异常,try结构里剩下的代码将不能执行135 calc_result = self.calc.divide(a, b) # 如果引发ZeroDivisionError,TypeError异常,这两句不会执行,但是后面的except还是会走到136 assert calc_result == expect137 except ZeroDivisionError as e:138 print("引发异常:", repr(e))139 except TypeError as e:140 print("引发异常:", repr(e))141 except Exception as e:142 print("引发异常:", repr(e))...

Full Screen

Full Screen

test_program.py

Source:test_program.py Github

copy

Full Screen

1import pytest2from tests import test_get_data3import random4# pd.set_option('display.max_columns', None)5# pd.set_option('display.max_rows', None)6@pytest.fixture(autouse=True)7def set_up():8 yield9 print("\n测试结束")10def test_object_class_avg():11 print('\n正在执行测试模块-----班级平均分')12 lst_average, class_avg, name_sheet = test_get_data.get_class_avg()13 # 随机取一个表14 sheet = random.choice(range(len(lst_average)))15 # 计算的数据16 class_average = class_avg[sheet].dropna(axis=1, how='all')17 # excel数据18 class_avg_data = lst_average[sheet]19 class_avg_data.columns = class_average.columns20 class_avg_data = class_avg_data.applymap("{0:.03f}".format)21 class_avg_data = class_avg_data.astype(float)22 print("随机选择的页帧:", name_sheet[sheet])23 print(class_average)24 print(class_avg_data)25 result = class_average == class_avg_data26 if False in result.values:27 print(result)28 print("数据不一致的索引:", result[result == 'False'].index.tolist())29 assert class_average.equals(class_avg_data)30def test_object_class_ach():31 print('\n正在执行测试模块-----班级达成度')32 lst_achieve, class_ach, name_sheet = test_get_data.get_class_avg()33 # 随机取一个表34 sheet = random.choice(range(len(lst_achieve)))35 # 计算的数据36 class_achieve = class_ach[sheet].dropna(axis=1, how='all')37 # excel数据38 class_ach_data = lst_achieve[sheet]39 class_ach_data.columns = class_achieve.columns40 class_ach_data = class_ach_data.applymap("{0:.03f}".format)41 class_ach_data = class_ach_data.astype(float)42 print("随机选择的页帧:", name_sheet[sheet])43 result = class_achieve == class_ach_data44 if False in result.values:45 print(result)46 print("数据不一致的索引:", result[result == 'False'].index.tolist())47 assert class_achieve.equals(class_ach_data)48def test_target_scores():49 print('\n正在执行测试模块-----各目标得分和达成度')50 lst_scores, lst_excel_scores, name_sheet = test_get_data.get_scores()51 # 随机取一个表52 sheet = random.choice(range(len(lst_scores)))53 print("随机选择的页帧:", name_sheet[sheet])54 # 计算的各目标得分55 test_score = lst_scores[sheet]56 test_score = test_score.loc[:, (test_score != 0).any(axis=0)]57 test_score = test_score.loc[:, (test_score != 'nan').all(axis=0)]58 test_score = test_score.astype(float)59 test_score = test_score.applymap("{0:.02f}".format)60 # excel数据61 df_excel_data = lst_excel_scores[sheet].dropna(axis=0, how='all')62 df_excel_data = df_excel_data.dropna(axis=1, how='all')63 df_excel_data.columns = test_score.columns64 df_excel_data = df_excel_data.applymap("{0:.02f}".format)65 result = test_score == df_excel_data66 if False in result.values:67 print(result)68 print("数据不一致的索引:", result[result == 'False'].index.tolist())69 assert test_score.equals(df_excel_data)70def test_final_achieve():71 print('\n正在执行测试模块-----最终达成度')72 count_achieve, excel_achieve = test_get_data.get_final_achieve()73 excel_achieve = excel_achieve.applymap("{0:.03f}".format)74 excel_achieve = excel_achieve.astype(float)75 result = count_achieve == excel_achieve76 if False in result.values:77 print(result)78 print("数据不一致的索引:", result[result == 'False'].index.tolist())79 assert count_achieve.equals(excel_achieve)80def test_static():81 print('\n正在执行测试模块-----统计部分')82 static_count_data, static_excel_data = test_get_data.static_data()83 static_count_data = static_count_data.fillna(value=0)84 static_excel_data = static_excel_data.fillna(value=0)85 result = static_count_data == static_excel_data86 if False in result.values:87 print(result)88 print("数据不一致的索引:", result[result == 'False'].index.tolist())89 assert static_count_data.equals(static_excel_data)90def test_all_data():91 print('\n正在执行测试模块-----达成度散点图页帧对比')92 count_data, excel_data = test_get_data.all_data_contrast()93 result = count_data == excel_data94 if False in result.values:95 print(result)96 print('数据不一致的索引:', result[result == 'False'].index.tolist())97 assert count_data.equals(excel_data)98# if __name__ == '__main__':...

Full Screen

Full Screen

test_scraper.py

Source:test_scraper.py Github

copy

Full Screen

...7"""The following tests make sure all classes are returning dictionaries. """8class AirlinersTestCase(unittest.TestCase):9 def setUp(self):10 self.scraper = Airliners()11 def test_get_data(self):12 test_dict = self.scraper.get_data()13 self.assertTrue(type(test_dict)==dict)14 def tearDown(self):15 self.scraper.housekeeping()16class AircraftbluebookTestCase(unittest.TestCase):17 def setUp(self):18 self.scraper = Aircraftbluebook()19 def test_get_data(self):20 test_dict = self.scraper.get_data()21 self.assertTrue(type(test_dict)==dict)22 def tearDown(self):23 self.scraper.housekeeping()24class ContentzoneTestCase(unittest.TestCase):25 def setUp(self):26 self.scraper = Contentzone()27 def test_get_data(self):28 test_dict = self.scraper.get_data()29 self.assertTrue(type(test_dict)==dict)30 def tearDown(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 localstack 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