class TestSystem(unittest.TestCase): def setUp(self): self.authorizer = AuthorizerFake() self.system = System(self.authorizer) ... def test_schedule_appointment_for_bob(self): self.system.schedule_appointment(self.request) ...
def setUp(self): ... self.system = System(authorizer=None) ... self.system = System(authorizer=object()) ... from unittest.mock import sentinel self.system = System(authorizer=sentinel.authorizer) ...
class TestSystem2(unittest.TestCase): def setUp(self): self.authorizer = Mock(return_value=True) self.system = System(self.authorizer) self.request = Mock(username='******', password='******') def test_successful_schedule_appointment(self): self.system.schedule_appointment(self.request) self.assertTrue(self.authorizer.authorize.called) ...
class TestSystem(unittest.TestCase): def setUp(self): self.authorizer = AuthorizerSpy() self.system = System(self.authorizer) ... def test_schedule_appointment(self): self.system.schedule_appointment(self.request) self.assertTrue(self.authorizer.authorized_was_called) ...
class TestSystem(unittest.TestCase): def setUp(self): self.authorizer = Mock() self.system = System(self.authorizer) self.request = ... def test_schedule_appointment(self): self.authorizer.configure_mock(...) self.system.schedule_appointment(self.request) ...
class TestSystem2(unittest.TestCase): def setUp(self): self.authorizer = Mock() self.system = System(self.authorizer) self.request = Mock(username='******', password='******') def test_schedule_appointment_for_bob(self): self.authorizer.side_effect = \ lambda username, password: username == 'Bob' self.system.schedule_appointment(self.request) ...
def webhook(): system = System() try: text = request.data.decode('utf8') data = json.loads(text) system.main(data) except Exception: system.log(traceback.format_exc()) return 'OK'
def setUp(self): self.authorizer = Mock(return_value=True) self.system = System(self.authorizer) self.request = Mock(username='******', password='******')
def setUp(self): self.authorizer = AuthorizerSpy() self.system = System(self.authorizer) ...
] tst_file = NamedTemporaryFile() trn_file = NamedTemporaryFile() with open(tst_file.name, "w") as file: file.writelines([ "2 4 2 1 4 \n", "1 2 1 1 2 \n", "9 7 10 7 4 \n", "4 4 10 10 2 \n", ]) with open(trn_file.name, "w") as file: file.writelines([ "1 3 1 1 2 \n", "10 3 2 1 2 \n", "2 3 1 1 2 \n", "10 9 7 1 4 \n", "3 5 2 2 4 \n", "2 3 1 1 4 \n", ]) tst = System("tst", tst_file.name) trn = System("trn", trn_file.name) classifier = NaiveBayesClassifier(tst, trn) classifier.compute() print(tst.decision_classes) print(trn.decision_classes)
def setUp(self): self.authorizer = Mock() self.system = System(self.authorizer) self.request = ...