import time
import subprocess
import tempfile
import signal


from mock import patch, Mock

from withenv import cli


class TestMain(object):

    def parse_args():
        return Mock(actions=[], cmd='ls -la'.split())

    @patch.object(cli, 'parse_args', parse_args)
    @patch.object(cli.sys, 'exit')
    def test_main_calls_command(self, exit):
        cli.main()
        exit.assert_called_with(0)

    def test_we_return_code(self):
        assert subprocess.call('we echo'.split()) == 0
        assert subprocess.call('we eccho'.split()) == 127

    def test_we_catches_ctrl_c(self):
        fd, path = tempfile.mkstemp()
        with open(path, 'wb+') as fh:
            proc = subprocess.Popen(['we', 'sleep', '10'],
                                    stdout=fh,
                                    stderr=subprocess.STDOUT)
            time.sleep(.5)
            proc.send_signal(signal.SIGINT)
            proc.wait()

        assert open(path).read() == ''

@@ -59,313 +59,132 @@
 l%0A%0A%0A
-from mock import patch, Mock%0A%0Afrom withenv import cli%0A%0A%0Aclass TestMain(object):%0A%0A    def parse_args():%0A        return Mock(actions=%5B%5D, cmd='ls -la'.split())%0A%0A    @patch.object(cli, 'parse_args', parse_args)%0A    @patch.object(cli.sys, 'exit')%0A    def test_main_calls_command(self, exit):%0A        cli.main()
+class TestMain(object):%0A%0A    def test_we_return_code(self):%0A        assert subprocess.check_output('which we'.split()) != %22%22
 %0A   
@@ -192,70 +192,66 @@
     
-exit.
 assert
-_called_with(0)%0A%0A    def test_we_return_code(self):
+ subprocess.check_output('which echo'.split()) != %22%22
 %0A   

Drop a broken test