import unittest

from mock import Mock, patch

from captainhook import pre_commit


class TestMain(unittest.TestCase):

    @patch('captainhook.pre_commit.get_files')
    @patch('captainhook.pre_commit.HookConfig')
    @patch('captainhook.pre_commit.checks')
    def test_calling_run_without_args(self, checks, HookConfig, get_files):
        get_files.return_value = ['file_one']
        HookConfig().is_enabled.return_value = True
        HookConfig().arguments.return_value = ''
        testmod = Mock()
        testmod.run.return_value = None

        checks.return_value = [("testmod", testmod)]

        result = pre_commit.main()

        self.assertEquals(result, 0)
        testmod.run.assert_called_with(['file_one'])

    @patch('captainhook.pre_commit.get_files')
    @patch('captainhook.pre_commit.HookConfig')
    @patch('captainhook.pre_commit.checks')
    def test_calling_run_with_args(self, checks, HookConfig, get_files):
        get_files.return_value = ['file_one']
        HookConfig().is_enabled.return_value = True
        HookConfig().arguments.return_value = 'yep'

        testmod = Mock()
        testmod.run.return_value = None

        checks.return_value = [("testmod", testmod)]

        result = pre_commit.main()

        self.assertEquals(result, 0)
        testmod.run.assert_called_with(['file_one'], 'yep')

@@ -121,104 +121,227 @@
     
-@patch('captainhook.pre_commit.get_files')%0A    @patch('captainhook.pre_commit.HookC
+def setUp(self):%0A        self.get_files_patch = patch('captainhook.pre_commit.get_files')%0A        get_files = self.get_files_patch.start()%0A        get_files.return_value = %5B'file_one'%5D%0A%0A        self.hook_c
 onfig
-')%0A    @
+_patch = 
 patc
@@ -370,147 +370,91 @@
 mit.
-checks')%0A    def test_calling_run_without_args(self, checks, HookC
+HookConfig')%0A        self.HookConfig = self.hook_c
 onfig
-, get_files):%0A        get_files.return_value = %5B'file_one'%5D%0A        
+_patch.start()%0A        self.
 Hook
@@ -493,32 +493,37 @@
  = True%0A        
+self.
 HookConfig().arg
@@ -547,24 +547,25 @@
 ue = ''%0A
+%0A
         
 testmod 
@@ -548,32 +548,37 @@
 e = ''%0A%0A        
+self.
 testmod = Mock()
@@ -578,32 +578,37 @@
  Mock()%0A        
+self.
 testmod.run.retu
@@ -619,33 +619,32 @@
 alue = None%0A
-%0A
         
 checks.retur
@@ -635,98 +635,118 @@
     
+self.
 checks
-.return_value = %5B(%22testmod%22, testmod)%5D%0A%0A        result = pre_commit.main
+_patch = patch('captainhook.pre_commit.checks')%0A        checks = self.checks_patch.start
 ()%0A
-%0A
         
 self
@@ -745,229 +745,190 @@
     
-self.assertEquals(result, 0)%0A        testmod.run.assert_called_with(%5B'file_one'%5D)%0A%0A    @patch('captainhook.pre_commit.get_files')%0A    @patch('captainhook.pre_commit.HookC
+checks.return_value = %5B(%22testmod%22, self.testmod)%5D%0A%0A    def tearDown(self):%0A        self.checks_patch.stop()%0A        self.hook_c
 onfig
-')%0A    @patch('captainhook.pre_commit.checks')
+_patch.stop()%0A        self.get_files_patch.stop()%0A
 %0A   
@@ -953,16 +953,19 @@
 run_with
+out
 _args(se
@@ -970,139 +970,184 @@
 self
-, checks, HookConfig, get_files):%0A        get_files.return_value = %5B'file_one'%5D%0A        HookConfig().is_enabled.return_value = True
+):%0A        result = pre_commit.main()%0A%0A        self.assertEquals(result, 0)%0A        self.testmod.run.assert_called_with(%5B'file_one'%5D)%0A%0A    def test_calling_run_with_args(self):
 %0A   
@@ -1151,16 +1151,21 @@
         
+self.
 HookConf
@@ -1205,128 +1205,8 @@
 p'%0A%0A
-        testmod = Mock()%0A        testmod.run.return_value = None%0A%0A        checks.return_value = %5B(%22testmod%22, testmod)%5D%0A%0A
     
@@ -1282,16 +1282,21 @@
         
+self.
 testmod.

Replace pre-commit test patch decorators with setUp/tearDown patching.