Best Python code snippet using avocado_python
unit_test.py
Source:unit_test.py
...26 self.non_required_field.validate_value(value)27 except:28 raised = True29 self.assertFalse(raised)30 def test_invalid_values(self, value=DEFAULT_TEST_FIELD_VALUE):31 if value != DEFAULT_TEST_FIELD_VALUE:32 with self.assertRaises(TypeError):33 self.required_field.validate_value(value)34 self.non_required_field.validate_value(value)35 @cases([None])36 def test_field_requirements(self, value):37 with self.assertRaises(TypeError):38 self.required_field.required_field_validation(value)39 self.non_required_field.required_field_validation(value)40 41class TestPhoneField(TestField):42 required_field = PhoneField(required=True, nullable=True)43 non_required_field = PhoneField(required=False, nullable=True)44 @cases([45 '79175002040', '79175002060', 7917500204046 ])47 def test_valid_values(self, phone_value):48 super().test_valid_values(phone_value)49 @cases([50 '89164104549', '+79175002040', '09164104549', '717500204',51 100, 'lorem ipsum'52 ])53 def test_invalid_field(self, phone_value):54 super().test_invalid_values(phone_value)55 56class TestEmailFiled(TestField):57 required_field = EmailField(required=True, nullable=True)58 non_required_field = EmailField(required=False, nullable=True)59 # valid cases60 @cases([61 'stupnikov@otus.ru', 'stupnikov@otus.com', 'ãã¾@otus.ru', 'ç·@otus.ru',62 'ÐÑÑеÑпомÑнÑÑÑй@otus.ru'63 ])64 def test_valid_values(self, email_value):65 super().test_valid_values(email_value)66 # invalid cases 67 @cases([68 100, 200, 'stupnikov', 'stupnikovotus'69 ])70 def test_invalid_values(self, email_value):71 super().test_invalid_values(email_value)72class TestGenderFieldFiled(TestField):73 required_field = GenderField(required=True, nullable=True)74 non_required_field = GenderField(required=False, nullable=True)75 # valid cases76 @cases([77 0,1,278 ])79 def test_valid_values(self, gender_value):80 super().test_valid_values(gender_value)81 # invalid cases 82 @cases([83 'M', 'F', '3', 5, '1', '01', -184 ])85 def test_invalid_values(self, gender_value):86 super().test_invalid_values(gender_value)87class TestDateField(TestField):88 required_field = DateField(required=True, nullable=True)89 non_required_field = DateField(required=False, nullable=True)90 # valid cases91 @cases([92 "01.01.1990", "01.01.2000", "01.02.1890"93 ])94 def test_valid_values(self, date_value):95 super().test_valid_values(date_value)96 # invalid cases 97 @cases([98 "01.01.18901", 'XXX'99 ])100 def test_invalid_values(self, date_value):101 super().test_invalid_values(date_value)102class TestBirthdayField(TestField):103 required_field = BirthDayField(required=True, nullable=True)104 non_required_field = BirthDayField(required=False, nullable=True)105 # valid cases106 @cases([107 "01.01.1990", "01.01.2000", 108 ])109 def test_valid_values(self, bdate_value):110 super().test_valid_values(bdate_value)111 # invalid cases 112 @cases([113 "01.01.1890", 'XXX'114 ])115 def test_invalid_values(self, bdate_value):116 super().test_invalid_values(bdate_value)117class TestClientIdsField(TestField):118 required_field = ClientIDsField(required=True, nullable=True)119 non_required_field = ClientIDsField(required=False, nullable=True)120 @cases([121 [1, 2, 3], [1,2], [0]122 ])123 def test_valid_values(self, clients_id_values):124 super().test_valid_values(clients_id_values)125 @cases([126 'client_id', ['0',1,2]127 ])128 def test_invalid_values(self, clients_id_values):129 super().test_invalid_values(clients_id_values)130if __name__ == "__main__":...
test_oop_luckytickets.py
Source:test_oop_luckytickets.py
...24 @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_methods.json')['is_simple_valid'])25 def test_valid_values(self, ticket):26 self.assertTrue(Ticket(ticket).is_simple_lucky)27 @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_methods.json')['is_simple_invalid'])28 def test_invalid_values(self, ticket):29 self.assertFalse(Ticket(ticket).is_simple_lucky)30class TestIsComplexLucky(TestCase):31 @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_methods.json')['is_complex_valid'])32 def test_valid_values(self, ticket):33 self.assertTrue(Ticket(ticket).is_complex_lucky)34 @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_methods.json')['is_complex_invalid'])35 def test_invalid_values(self, ticket):36 self.assertFalse(Ticket(ticket).is_complex_lucky)37class TestIsComplexLuckyAlternative(TestCase):38 @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_methods.json')['is_complex_alternative_valid'])39 def test_valid_values(self, ticket):40 self.assertTrue(Ticket(ticket).is_complex_lucky_alternative)41 @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_methods.json')['is_complex_alternative_invalid'])42 def test_invalid_values(self, ticket):43 self.assertFalse(Ticket(ticket).is_complex_lucky_alternative)44class TestTicketRange(TestCase):45 @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_range.json')['invalid_ticket_range'])46 def test_raises_error_if_max_number_greater_than_min(self, min_number, max_number):47 with self.assertRaises(InvalidTicketRangeError):48 TicketRange(Ticket(min_number), Ticket(max_number))49 @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_range.json')['simple_method_data'])50 def test_when_simple_method_is_winner(self, min_number, max_number, times):51 result = str(TicketRange(Ticket(min_number), Ticket(max_number)))52 self.assertIn('Simple method has won', result)53 self.assertIn(f'Simple method ran {times} times', result)54 @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_range.json')['complex_method_data'])55 def test_when_complex_method_is_winner_and_two_tickets_equal(self, min_number, max_number, times):56 result = str(TicketRange(Ticket(min_number), Ticket(max_number)))...
test_lmt8x.py
Source:test_lmt8x.py
...8 self.assertEqual(lmt84_v2t(183), 150)9 def test_linear_interpolation(self):10 self.assertGreater(lmt84_v2t(1298), -50)11 self.assertLess(lmt84_v2t(1298), -49)12 def test_invalid_values(self):13 with self.assertRaises(ValueError):14 lmt84_v2t(1500)15 with self.assertRaises(ValueError):16 lmt84_v2t(0)17class LMT85TestCase(unittest.TestCase):18 def test_exact_temp(self):19 self.assertEqual(lmt85_v2t(1955), -50)20 self.assertEqual(lmt85_v2t(1949), -49)21 self.assertEqual(lmt85_v2t(1567), 0)22 self.assertEqual(lmt85_v2t(301), 150)23 def test_linear_interpolation(self):24 self.assertGreater(lmt85_v2t(1954), -50)25 self.assertLess(lmt85_v2t(1954), -49)26 def test_invalid_values(self):27 with self.assertRaises(ValueError):28 lmt85_v2t(2000)29 with self.assertRaises(ValueError):30 lmt85_v2t(0)31class LMT86TestCase(unittest.TestCase):32 def test_exact_temp(self):33 self.assertEqual(lmt86_v2t(2616), -50)34 self.assertEqual(lmt86_v2t(2607), -49)35 self.assertEqual(lmt86_v2t(2100), 0)36 self.assertEqual(lmt86_v2t(420), 150)37 def test_linear_interpolation(self):38 self.assertGreater(lmt86_v2t(2615), -50)39 self.assertLess(lmt86_v2t(2615), -49)40 def test_invalid_values(self):41 with self.assertRaises(ValueError):42 lmt86_v2t(3000)43 with self.assertRaises(ValueError):44 lmt86_v2t(0)45class LMT87TestCase(unittest.TestCase):46 def test_exact_temp(self):47 self.assertEqual(lmt87_v2t(3277), -50)48 self.assertEqual(lmt87_v2t(3266), -49)49 self.assertEqual(lmt87_v2t(2633), 0)50 self.assertEqual(lmt87_v2t(538), 150)51 def test_linear_interpolation(self):52 self.assertGreater(lmt87_v2t(3276), -50)53 self.assertLess(lmt87_v2t(3276), -49)54 def test_invalid_values(self):55 with self.assertRaises(ValueError):56 lmt87_v2t(4000)57 with self.assertRaises(ValueError):...
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!!