Best Python code snippet using lemoncheesecake
test_db_objects.py
Source:test_db_objects.py
...51 run_tests.compare_answer(getattr(obj, name), value, "Sees if the correct attribute " + name + " is set")52 else:53 run_tests.compare_answer(None, value, "Could not find the attribute in object " + str(obj))54DBCC = db_connections.DBConnectionCollection("Test db_objects")55def setup_object():56 return TestObject.new(DBCC, DOUBLE1, TEXT1, INT1, TIME1, DATE1, UNIX1)57def setup_object_2():58 return TestObject.new(DBCC, DOUBLE2, TEXT2, INT2, TIME2, DATE2, UNIX2)59def setup_table():60 return TestObject.create_table(DBCC)61def delete_table():62 return TestObject.delete_table(DBCC)63def init():64 DBCC.create_multiple_connections([config.TESTDB])65 DBCC.start_all_connections()66def test_create_object():67 obj = setup_object()68 _check_object_attributes(obj, list(DATA1))69def test_create_and_delete_object_table():70 run_tests.compare_answer(TestObject.create_table(DBCC), True, "Was able to create the table")71 run_tests.compare_answer(TestObject.delete_table(DBCC), True, "Was able to delete the table")72def test_save_and_delete_object():73 setup_table()74 obj = setup_object()75 #delete before saving and an ID is given76 run_tests.compare_answer(obj.delete(), False, "Try to delete before saving an object")77 #save78 save_result = obj.save()79 run_tests.compare_answer(save_result, True, "See if the save of the object succeeded")80 #retrieve181 retrieve1 = DBCC.retrieve_connection(config.TESTDB).retrieve_data("*", config.TEST_TABLE, [])82 run_tests.compare_answer(len(retrieve1), 1, "Sees if only one row has been inserted")83 retrieve1_ = db_connections.DatabaseType.format_mysql_row_from_db(retrieve1[0], TestObject.layout)84 values1 = _dict_values_only(retrieve1_)85 _check_object_attributes(obj, values1)86 #delete87 result = obj.delete()88 run_tests.compare_answer(result, True, "Sees if the delete has succeeded")89 #retrieve290 retrieve2 = DBCC.retrieve_connection(config.TESTDB).retrieve_data("*", config.TEST_TABLE, [])91 run_tests.compare_answer(len(retrieve2), 0, "Checks to see if the table is empty")92 delete_table()93def test_update():94 setup_table()95 obj = setup_object()96 obj.save()97 id_1 = obj.oid98 obj.double_c = DOUBLE299 obj.text_c = TEXT2100 obj.int_c = INT2101 obj.time_c = TIME2102 obj.date_c = DATE2103 obj.unix_c = UNIX2104 #Update105 update_result = obj.save()106 run_tests.compare_answer(update_result, True, "Check to see if update succeeded")107 #Retrieve1108 retrieve1 = DBCC.retrieve_connection(config.TESTDB).retrieve_data("*", config.TEST_TABLE, [])109 run_tests.compare_answer(len(retrieve1), 1, "Sees if only one row has been inserted")110 retrieve1_ = db_connections.DatabaseType.format_mysql_row_from_db(retrieve1[0], TestObject.layout)111 values2 = _dict_values_only(retrieve1_)112 _check_object_attributes(obj, values2)113 run_tests.compare_answer(retrieve1_["oid"], id_1, "Check to see if the id still matches")114 obj.delete()115 delete_table()116def test_multiple_objects():117 setup_table()118 obj_1 = setup_object()119 obj_2 = setup_object()120 obj_1.save()121 obj_2.save()122 #Check to see if id matches123 run_tests.compare_answer(obj_1.oid, 0, "Check to see if first id = 0")124 run_tests.compare_answer(obj_2.oid, 1, "Check to see if second id = 1")125 #Check to see if both are in the table126 retrieve1 = DBCC.retrieve_connection(config.TESTDB).retrieve_data("*", config.TEST_TABLE, [])127 run_tests.compare_answer(len(retrieve1), 2, "Sees if both rows have been inserted")128 #Check first object values129 retrieve1_ = db_connections.DatabaseType.format_mysql_row_from_db(retrieve1[0], TestObject.layout)130 values1 = _dict_values_only(retrieve1_)131 _check_object_attributes(obj_1, values1)132 #check second object values133 retrieve2_ = db_connections.DatabaseType.format_mysql_row_from_db(retrieve1[1], TestObject.layout)134 values2 = _dict_values_only(retrieve2_)135 _check_object_attributes(obj_2, values2)136 #Check if one can be deleted and one still exists137 obj_1.delete()138 retrieve2 = DBCC.retrieve_connection(config.TESTDB).retrieve_data("*", config.TEST_TABLE, [])139 run_tests.compare_answer(len(retrieve2), 1, "Sees if one row still exists")140 retrieve3_ = db_connections.DatabaseType.format_mysql_row_from_db(retrieve2[0], TestObject.layout)141 values3 = _dict_values_only(retrieve3_)142 _check_object_attributes(obj_2, values3)143 #delete last one144 obj_2.delete()145 retrieve3 = DBCC.retrieve_connection(config.TESTDB).retrieve_data("*", config.TEST_TABLE, [])146 run_tests.compare_answer(len(retrieve3), 0, "Sees if no rows still exists")147 delete_table()148def test_object_from_row():149 setup_table()150 obj_1 = setup_object()151 obj_1.save()152 #Retrieve from table and build object153 retrieve1 = DBCC.retrieve_connection(config.TESTDB).retrieve_data("*", config.TEST_TABLE, [])154 obj_1_ = TestObject.object_from_mysql_row(DBCC, retrieve1[0])155 run_tests.compare_answer(obj_1 == obj_1_, True, "Compare if both objects are the same")156 obj_1.delete()157 delete_table()158def test_equals():159 obj_1 = setup_object()160 obj_2 = setup_object()161 run_tests.compare_answer(obj_1 == obj_2, True, "Testing two same objects")162def test_retrieve_objects():163 setup_table()164 obj_1 = setup_object()165 obj_2 = setup_object_2()166 obj_2.double_c = DOUBLE1167 obj_1.save()168 obj_2.save()169 objects = TestObject.retrieve_objects(DBCC, [("double_c", "=", DOUBLE1)])170 obj_1_ = [obj for obj in objects if obj.oid == 0][0]171 obj_2_ = [obj for obj in objects if obj.oid == 1][0]172 run_tests.compare_answer(obj_1 == obj_1_, True, "Test to see if first object matches")173 run_tests.compare_answer(obj_2 == obj_2_, True, "Test to see if second object matches")174 run_tests.compare_answer(len(objects), 2, "Test to see if only 2 objects are created")175 delete_table()176def shutdown():...
test_case_executor.py
Source:test_case_executor.py
1# -*- coding: utf-8 -*-2import numpy as np3from thermal_building_model.low_order_VDI import reducedOrderModelVDI4def run_validation_case(setup_object):5 """6 This function shall use a setup_validation_case object to run a test case and 7 return hourly averaged temperature and heating power series8 """9 10 temperature_initial = setup_object.get_initial_temperatures()11 12 T_air, Q_hc, Q_iw, Q_ow = reducedOrderModelVDI(13 setup_object.get_building_parameters(), 14 setup_object.get_weather_temperature(), 15 setup_object.get_solar_radiation(),16 setup_object.get_equal_air_temperature(), 17 setup_object.get_alpha_radiative(), 18 setup_object.get_ventilation_rate(), 19 setup_object.get_internal_gains_convective(), 20 setup_object.get_internal_gains_radiative(), 21 setup_object.get_k_radiative(),22 setup_object.get_set_temperature_heating(), 23 setup_object.get_set_temperature_cooling(), 24 setup_object.get_maximum_heater_output(), 25 setup_object.get_maximum_chiller_output(),26 setup_object.get_heater_order(), 27 setup_object.get_chiller_order(), 28 setup_object.get_time_discretization(),29 temperature_initial["T_air_init"],30 temperature_initial["T_iw_init"],31 temperature_initial["T_ow_init"]32 )33 T_air_celsius = T_air - 273.1534 Q_total = Q_hc + Q_iw + Q_ow35 36 times_per_hours = setup_object.times_per_hour37 total_hours = setup_object.total_hours38 39 return (40 _get_hourly_results(T_air_celsius, times_per_hours, total_hours),41 _get_hourly_results(Q_hc, times_per_hours, total_hours),42 _get_hourly_results(Q_total, times_per_hours, total_hours)43 )44 45def _get_hourly_results(array, times_per_hour, total_hours):...
test_barista.py
Source:test_barista.py
1import pytest2from barista import Barista3@pytest.fixture4def setup_object():5 barista = Barista()6 return barista7def test_coffee(setup_object):8 barista = setup_object9 assert barista.make_coffee(withmilk=True) == "Here is your coffee with milk"10 assert barista.make_coffee() == "Here is your regular coffee"11def test_tea(setup_object):12 barista = setup_object13 assert barista.make_tea() == "Your tea is ready"14 assert barista.make_tea(withsugar=True) == "Your sweet tea is ready"15def test_payment(setup_object):16 barista = setup_object17 assert barista.get_payment(cash=False) == "Let me get the POS terminal"18 assert barista.get_payment() == "Thank you for the tip!"...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!