GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — code_snippets/Python-Unit-Testing/snippets.txt at master · Roopa28/code_snippets Expand file tree/ Copy pathsnippets.txtMore file actions 115 lines (78 loc) · 2.96 KB / Copy pathsnippets.txtFile metadata and controls115 lines (78 loc) · 2.96 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 import unittest from employee import Employee class TestEmployee(unittest.TestCase): def test_email(self): emp_1 = Employee('Corey', 'Schafer', 50000) emp_2 = Employee('Sue', 'Smith', 60000) self.assertEqual(emp_1.email, '[email protected]') self.assertEqual(emp_2.email, '[email protected]') emp_1.first = 'John' emp_2.first = 'Jane' self.assertEqual(emp_1.email, '[email protected]') self.assertEqual(emp_2.email, '[email protected]') def test_fullname(self): emp_1 = Employee('Corey', 'Schafer', 50000) emp_2 = Employee('Sue', 'Smith', 60000) self.assertEqual(emp_1.fullname, 'Corey Schafer') self.assertEqual(emp_2.fullname, 'Sue Smith') emp_1.first = 'John' emp_2.first = 'Jane' self.assertEqual(emp_1.fullname, 'John Schafer') self.assertEqual(emp_2.fullname, 'Jane Smith') def test_apply_raise(self): emp_1 = Employee('Corey', 'Schafer', 50000) emp_2 = Employee('Sue', 'Smith', 60000) emp_1.apply_raise() emp_2.apply_raise() self.assertEqual(emp_1.pay, 52500) self.assertEqual(emp_2.pay, 63000) if __name__ == '__main__': unittest.main() ###### With Prints ###### import unittest from employee import Employee class TestEmployee(unittest.TestCase): def setUp(self): print('setUp') self.emp_1 = Employee('Corey', 'Schafer', 50000) self.emp_2 = Employee('Sue', 'Smith', 60000) def tearDown(self): print('tearDown\n') def test_email(self): print('test_email') self.assertEqual(self.emp_1.email, '[email protected]') self.assertEqual(self.emp_2.email, '[email protected]') self.emp_1.first = 'John' self.emp_2.first = 'Jane' self.assertEqual(self.emp_1.email, '[email protected]') self.assertEqual(self.emp_2.email, '[email protected]') def test_fullname(self): print('test_fullname') self.assertEqual(self.emp_1.fullname, 'Corey Schafer') self.assertEqual(self.emp_2.fullname, 'Sue Smith') self.emp_1.first = 'John' self.emp_2.first = 'Jane' self.assertEqual(self.emp_1.fullname, 'John Schafer') self.assertEqual(self.emp_2.fullname, 'Jane Smith') def test_apply_raise(self): print('test_apply_raise') self.emp_1.apply_raise() self.emp_2.apply_raise() self.assertEqual(self.emp_1.pay, 52500) self.assertEqual(self.emp_2.pay, 63000) if __name__ == '__main__': unittest.main() ###### setUpClass and tearDownClass ###### @classmethod def setUpClass(cls): print('setupClass') @classmethod def tearDownClass(cls): print('teardownClass') ##### Mocking ##### def monthly_schedule(self, month): response = requests.get(f'http://company.com/{self.last}/{month}') if response.ok: return response.text else: return 'Bad Response!' |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |