Line | |
---|
1 | """ |
---|
2 | Tests for allmydata.monitor. |
---|
3 | """ |
---|
4 | |
---|
5 | from twisted.trial import unittest |
---|
6 | |
---|
7 | from allmydata.monitor import Monitor, OperationCancelledError |
---|
8 | |
---|
9 | |
---|
10 | class MonitorTests(unittest.TestCase): |
---|
11 | """Tests for the Monitor class.""" |
---|
12 | |
---|
13 | def test_cancellation(self): |
---|
14 | """The monitor can be cancelled.""" |
---|
15 | m = Monitor() |
---|
16 | self.assertFalse(m.is_cancelled()) |
---|
17 | m.raise_if_cancelled() |
---|
18 | m.cancel() |
---|
19 | self.assertTrue(m.is_cancelled()) |
---|
20 | with self.assertRaises(OperationCancelledError): |
---|
21 | m.raise_if_cancelled() |
---|
22 | |
---|
23 | def test_status(self): |
---|
24 | """The monitor can have its status set.""" |
---|
25 | m = Monitor() |
---|
26 | self.assertEqual(m.get_status(), None) |
---|
27 | m.set_status("discombobulated") |
---|
28 | self.assertEqual(m.get_status(), "discombobulated") |
---|
29 | |
---|
30 | def test_finish(self): |
---|
31 | """The monitor can finish.""" |
---|
32 | m = Monitor() |
---|
33 | self.assertFalse(m.is_finished()) |
---|
34 | d = m.when_done() |
---|
35 | self.assertNoResult(d) |
---|
36 | |
---|
37 | result = m.finish(300) |
---|
38 | self.assertEqual(result, 300) |
---|
39 | self.assertEqual(m.get_status(), 300) |
---|
40 | self.assertTrue(m.is_finished()) |
---|
41 | |
---|
42 | d.addBoth(self.assertEqual, 300) |
---|
43 | return d |
---|
Note: See
TracBrowser
for help on using the repository browser.