Commits

Attila Magyar committed 48d68a5

addes test to context

Comments (0)

Files changed (4)

src/macaque/core/context.py

+'''
+Created on Dec 26, 2011
+
+@author: zeroflag
+'''
+
+class GlobalContextManager(object):
+    def __init__(self):
+        self._should_verify = False
+        
+    def is_test(self):
+        return self._should_verify
+    
+    def set_verify(self, b):
+        self._should_verify = b
+
+class Given(object):
+    def __init__(self, text=""): 
+        self.text=text    
+    def __enter__(self): 
+        global_context_manager.set_verify(True)
+        
+    def __exit__(self, atype, value, traceback): 
+        global_context_manager.set_verify(False)
+        
+    def __call__(self, description):
+        print("\t- Given: %s" % (description))
+        return self
+
+class Expectation(object):
+    def __init__(self): pass
+    
+    def __enter__(self): 
+        global_context_manager.set_verify(True)
+        
+    def __exit__(self, atype, value, traceback): 
+        global_context_manager.set_verify(False)
+        
+    def __call__(self, description):
+        print("\t- Expect: %s" % (description))
+        return self
+
+if __name__ != '__main__':
+    global_context_manager = GlobalContextManager()

src/macaque/core/mocks.py

                 
     def program(self, command, *args, **kargs):
         if not self.arg_map.has_matched(*args, **kargs):
-            self.arg_map.store(BatchCommand(command), *args, **kargs)
+            self.store_new_batch(command, args, kargs)
         else:
             self.append_to_existing(command, args, kargs)
 
+    def store_new_batch(self, command, args, kargs):
+        return self.arg_map.store(BatchCommand(command), *args, **kargs)
+
     def append_to_existing(self, command, args, kargs):
         existing_commands = self.arg_map.find_matched(*args, **kargs)
         existing_commands[0].add_command(command)

src/macaque/test/__init__.py

Empty file added.

src/macaque/test/contexttest.py

+'''
+Created on Dec 26, 2011
+
+@author: zeroflag
+'''
+import unittest
+
+from macaque import * #@UnusedWildImport
+from macaque.core.context import global_context_manager
+
+class ContextTest(unittest.TestCase):
+    def testInsideExpectation(self):
+        with expectation:
+            self.assertTrue(global_context_manager.is_test())
+            
+    def testInsideGiven(self):
+        with given:
+            self.assertTrue(global_context_manager.is_test())
+            
+    def testOutsideTest(self):
+        self.assertFalse(global_context_manager.is_test())
+
+if __name__ == "__main__":
+    unittest.main()