wrote simple mocking helper methods and classes
[wifi-assistant] / package / test / unit / test_pie.py
diff --git a/package/test/unit/test_pie.py b/package/test/unit/test_pie.py
new file mode 100644 (file)
index 0000000..dcb60a8
--- /dev/null
@@ -0,0 +1,48 @@
+import unittest
+from pie import *
+
+
+class TestPie(unittest.TestCase):
+    
+    def test_never(self):
+        mock = Mock()
+        mock.replay()
+        verify(mock, never()).fakeMethod()
+        
+    def test_neverFail(self):
+        mock = Mock()
+        mock.replay()
+        mock.fakeMethod()
+        try:
+            verify(mock, never()).fakeMethod()
+            raise Exception("The fake method was called - the verify statement should fail")
+        except:
+            pass
+        
+    def test_onceSuccess(self):
+        mock = Mock()
+        given(mock).method().willReturn(True)
+        mock.replay()
+        result = mock.method()
+        assert result is True
+        verify(mock, once()).method()
+    
+    def test_onceFail(self):
+        mock = Mock()
+        given(mock).method().willReturn(True)
+        mock.replay()
+        try:
+            verify(mock, once()).method()
+            raise Exception("The method was never called - the verify step should fail")
+        except:
+            pass
+        
+    def test_implicitOnce_undefinedReturn_WithArguments(self):
+        mock = Mock()
+        mock.replay()
+        url = 'http://sample.argument'
+        mock.openUrl(url)
+        verify(mock).openUrl(url)
+    
+if __name__ == '__main__':
+    unittest.main()