#! /usr/bin/env pythoon
from mock import Mock, mocksignature, patch
import unittest

def  pop_last_call(mock):
    if not mock.call_count:
        raise AssertionError('Cannot pop last call: call_count is 0')
    mock.call_args_list.pop()
    try:
        mock.call_args = mock.call_args_list[-1]
    except IndexError:
        mock.call_args = None
        mock.called = False
    mock.call_count -= 1

class PyonUnitTestCase(unittest.TestCase):
    def _create_patch(self, name):
        patcher = patch(name)
        thing = patcher.start()
        self.addCleanup(patcher.stop)
        return thing

    def _create_service_mock(self, service_name, interface_base_class,
            func_name_list):
        try:
            self.mock_clients
        except AttributeError:
            self.mock_clients = Mock(name='self.clients')
        mock_service = self.mock_clients. __getattr__(service_name)
        for func_name in func_name_list:
            mock_func = mocksignature(interface_base_class.__dict__[func_name],
                    mock=Mock(name='mock_' + func_name),
                    skipfirst=True)
            self.__setattr__('mock_' + func_name, mock_func)
            mock_service.__setattr__(func_name, mock_func)

@@ -723,29 +723,24 @@
        self.
-mock_
 clients%0A    
@@ -779,29 +779,24 @@
        self.
-mock_
 clients = Mo
@@ -851,21 +851,16 @@
 elf.
-mock_
 clients.
  __g
@@ -855,17 +855,16 @@
 clients.
- 
 __getatt
@@ -877,24 +877,109 @@
 rvice_name)%0A
+        # set self.service_name%0A        self.__setattr__(service_name, mock_service)%0A
         for 
@@ -1127,27 +1127,43 @@
 me='
-mock_' + func
+self.clients.%25s.%25s' %25 (service
 _name
-)
 ,%0A  
@@ -1184,83 +1184,59 @@
     
-skipfirst=True)%0A            self.__setattr__('mock_' + func_name, mock_func
+    func_name)),%0A                    skipfirst=True
 )%0A  

Refactor PyonUnitTestCase