-
Notifications
You must be signed in to change notification settings - Fork 48
/
test_first_working_reporter.py
49 lines (41 loc) · 1.54 KB
/
test_first_working_reporter.py
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
import unittest
from approvaltests.core.reporter import Reporter
from approvaltests.reporters.first_working_reporter import FirstWorkingReporter
class ReporterForTesting(Reporter):
def __init__(self, success, additional=None):
if additional is None:
additional = lambda : None
self.additional = additional
self.called = False
self.success = success
def report(self, received_path, approved_path):
self.called = True
self.additional()
return self.success
class TestFirstWorkingReporter(unittest.TestCase):
def test_first_one(self):
r1 = ReporterForTesting(True)
r2 = ReporterForTesting(False)
first = FirstWorkingReporter(r1, r2)
success = first.report('a.txt', 'b.txt')
self.assertTrue(r1.called)
self.assertTrue(success)
self.assertFalse(r2.called)
def test_second_one(self):
r1 = ReporterForTesting(False)
r2 = ReporterForTesting(False)
first = FirstWorkingReporter(r1, r2)
success = first.report('a.txt', 'b.txt')
self.assertTrue(r1.called)
self.assertTrue(r2.called)
self.assertFalse(success)
def test_exception(self):
def exception():
raise Exception()
r1 = ReporterForTesting(False, exception)
r2 = ReporterForTesting(False)
first = FirstWorkingReporter(r1, r2)
success = first.report('a.txt', 'b.txt')
self.assertTrue(r1.called)
self.assertTrue(r2.called)
self.assertFalse(success)