wrote simple mocking helper methods and classes
[wifi-assistant] / package / test / unit / test_pie.py
1 import unittest
2 from pie import *
3
4
5 class TestPie(unittest.TestCase):
6     
7     def test_never(self):
8         mock = Mock()
9         mock.replay()
10         verify(mock, never()).fakeMethod()
11         
12     def test_neverFail(self):
13         mock = Mock()
14         mock.replay()
15         mock.fakeMethod()
16         try:
17             verify(mock, never()).fakeMethod()
18             raise Exception("The fake method was called - the verify statement should fail")
19         except:
20             pass
21         
22     def test_onceSuccess(self):
23         mock = Mock()
24         given(mock).method().willReturn(True)
25         mock.replay()
26         result = mock.method()
27         assert result is True
28         verify(mock, once()).method()
29     
30     def test_onceFail(self):
31         mock = Mock()
32         given(mock).method().willReturn(True)
33         mock.replay()
34         try:
35             verify(mock, once()).method()
36             raise Exception("The method was never called - the verify step should fail")
37         except:
38             pass
39         
40     def test_implicitOnce_undefinedReturn_WithArguments(self):
41         mock = Mock()
42         mock.replay()
43         url = 'http://sample.argument'
44         mock.openUrl(url)
45         verify(mock).openUrl(url)
46     
47 if __name__ == '__main__':
48     unittest.main()