<s> from __future__ import with_statement <EOL> import datetime <EOL> import logging <EOL> import mock <EOL> import sys <EOL> import subprocess <EOL> import vcs <EOL> import vcs . cli <EOL> from contextlib import nested <EOL> from StringIO import StringIO <EOL> from vcs . cli import BaseCommand <EOL> from vcs . cli import ExecutionManager <EOL> from vcs . cli import make_option <EOL> from vcs . nodes import FileNode <EOL> from vcs . tests . base import BackendTestMixin <EOL> from vcs . tests . conf import SCM_TESTS <EOL> from vcs . utils . compat import unittest <EOL> class DummyExecutionManager ( ExecutionManager ) : <EOL> def get_vcsrc ( self ) : <EOL> return None <EOL> class TestExecutionManager ( unittest . TestCase ) : <EOL> def test_default_argv ( self ) : <EOL> with mock . patch . object ( sys , '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) : <EOL> manager = DummyExecutionManager ( ) <EOL> self . assertEqual ( manager . argv , [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) <EOL> def test_default_prog_name ( self ) : <EOL> with mock . patch . object ( sys , '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) : <EOL> manager = DummyExecutionManager ( ) <EOL> self . assertEqual ( manager . prog_name , '<STR_LIT>' ) <EOL> def test_default_stdout ( self ) : <EOL> stream = StringIO ( ) <EOL> with mock . patch . object ( sys , '<STR_LIT>' , stream ) : <EOL> manager = DummyExecutionManager ( ) <EOL> self . assertEqual ( manager . stdout , stream ) <EOL> def test_default_stderr ( self ) : <EOL> stream = StringIO ( ) <EOL> with mock . patch . object ( sys , '<STR_LIT>' , stream ) : <EOL> manager = DummyExecutionManager ( ) <EOL> self . assertEqual ( manager . stderr , stream ) <EOL> def test_get_vcsrc ( self ) : <EOL> with nested ( mock . patch ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> mock . patch ( '<STR_LIT>' ) ) as ( VP , m ) : <EOL> m . return_value = mock . Mock ( ) <EOL> manager = ExecutionManager ( ) <EOL> self . assertEqual ( manager . vimrc , m . return_value ) <EOL> m . assert_called_once_with ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_get_command_class ( self ) : <EOL> with mock . patch . object ( vcs . cli , '<STR_LIT>' , { <EOL> '<STR_LIT:foo>' : '<STR_LIT>' , <EOL> '<STR_LIT:bar>' : '<STR_LIT>' } ) : <EOL> manager = DummyExecutionManager ( ) <EOL> from decimal import Decimal <EOL> from socket import socket <EOL> self . assertEqual ( manager . get_command_class ( '<STR_LIT:foo>' ) , Decimal ) <EOL> self . assertEqual ( manager . get_command_class ( '<STR_LIT:bar>' ) , socket ) <EOL> def test_get_commands ( self ) : <EOL> with mock . patch . object ( vcs . cli , '<STR_LIT>' , { <EOL> '<STR_LIT>' : mock , <EOL> '<STR_LIT:foo>' : '<STR_LIT>' , <EOL> '<STR_LIT:bar>' : '<STR_LIT>' } ) : <EOL> manager = DummyExecutionManager ( ) <EOL> self . assertItemsEqual ( manager . get_commands ( ) , { <EOL> '<STR_LIT:foo>' : BaseCommand , <EOL> '<STR_LIT:bar>' : DummyExecutionManager , <EOL> '<STR_LIT>' : mock , <EOL> } ) <EOL> def test_run_command ( self ) : <EOL> manager = DummyExecutionManager ( stdout = StringIO ( ) , <EOL> stderr = StringIO ( ) ) <EOL> class Command ( BaseCommand ) : <EOL> def run_from_argv ( self , argv ) : <EOL> self . stdout . write ( u'<STR_LIT:foo>' ) <EOL> self . stderr . write ( u'<STR_LIT:bar>' ) <EOL> with mock . patch . object ( manager , '<STR_LIT>' ) as m : <EOL> m . return_value = Command <EOL> manager . run_command ( '<STR_LIT>' , manager . argv ) <EOL> self . assertEqual ( manager . stdout . getvalue ( ) , u'<STR_LIT:foo>' ) <EOL> self . assertEqual ( manager . stderr . getvalue ( ) , u'<STR_LIT:bar>' ) <EOL> def test_execute_calls_run_command_if_argv_given ( self ) : <EOL> manager = DummyExecutionManager ( argv = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> manager . run_command = mock . Mock ( ) <EOL> manager . execute ( ) <EOL> manager . run_command . assert_called_once_with ( '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_execute_calls_show_help_if_argv_not_given ( self ) : <EOL> manager = DummyExecutionManager ( argv = [ '<STR_LIT>' ] ) <EOL> manager . show_help = mock . Mock ( ) <EOL> manager . execute ( ) <EOL> manager . show_help . assert_called_once_with ( ) <EOL> def test_show_help_writes_to_stdout ( self ) : <EOL> manager = DummyExecutionManager ( stdout = StringIO ( ) , stderr = StringIO ( ) ) <EOL> manager . show_help ( ) <EOL> self . assertGreater ( len ( manager . stdout . getvalue ( ) ) , <NUM_LIT:0> ) <EOL> class TestBaseCommand ( unittest . TestCase ) : <EOL> def test_default_stdout ( self ) : <EOL> stream = StringIO ( ) <EOL> with mock . patch . object ( sys , '<STR_LIT>' , stream ) : <EOL> command = BaseCommand ( ) <EOL> command . stdout . write ( u'<STR_LIT>' ) <EOL> self . assertEqual ( sys . stdout . getvalue ( ) , u'<STR_LIT>' ) <EOL> def test_default_stderr ( self ) : <EOL> stream = StringIO ( ) <EOL> with mock . patch . object ( sys , '<STR_LIT>' , stream ) : <EOL> command = BaseCommand ( ) <EOL> command . stderr . write ( u'<STR_LIT>' ) <EOL> self . assertEqual ( sys . stderr . getvalue ( ) , u'<STR_LIT>' ) <EOL> def test_get_version ( self ) : <EOL> command = BaseCommand ( ) <EOL> self . assertEqual ( command . get_version ( ) , vcs . get_version ( ) ) <EOL> def test_usage ( self ) : <EOL> command = BaseCommand ( ) <EOL> command . args = '<STR_LIT:foo>' <EOL> self . assertEqual ( command . usage ( '<STR_LIT:bar>' ) , <EOL> '<STR_LIT>' ) <EOL> def test_get_parser ( self ) : <EOL> class Command ( BaseCommand ) : <EOL> option_list = ( <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store>' , dest = '<STR_LIT:foo>' , <EOL> default = '<STR_LIT:bar>' ) , <EOL> ) <EOL> command = Command ( ) <EOL> parser = command . get_parser ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> options , args = parser . parse_args ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( options . __dict__ [ '<STR_LIT:foo>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( args , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_execute ( self ) : <EOL> command = BaseCommand ( ) <EOL> command . handle = mock . Mock ( ) <EOL> args = [ '<STR_LIT:bar>' ] <EOL> kwargs = { '<STR_LIT>' : True } <EOL> command . execute ( * args , ** kwargs ) <EOL> command . handle . assert_called_once_with ( * args , ** kwargs ) <EOL> def test_run_from_argv ( self ) : <EOL> command = BaseCommand ( ) <EOL> argv = [ '<STR_LIT>' , '<STR_LIT:foo>' , '<STR_LIT>' , '<STR_LIT:bar>' , '<STR_LIT>' ] <EOL> command . handle = mock . Mock ( ) <EOL> command . run_from_argv ( argv ) <EOL> args = [ '<STR_LIT:bar>' ] <EOL> kwargs = { '<STR_LIT>' : True , '<STR_LIT>' : True } <EOL> command . handle . assert_called_once_with ( * args , ** kwargs ) <EOL> class RealCliMixin ( BackendTestMixin ) : <EOL> @ classmethod <EOL> def _get_commits ( cls ) : <EOL> commits = [ <EOL> { <EOL> '<STR_LIT:message>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT:date>' : datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:20> ) , <EOL> '<STR_LIT>' : [ FileNode ( '<STR_LIT>' , content = '<STR_LIT>' ) ] , <EOL> } , <EOL> { <EOL> '<STR_LIT:message>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT:date>' : datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:20> ) , <EOL> '<STR_LIT>' : [ FileNode ( '<STR_LIT>' , content = '<STR_LIT>' ) ] , <EOL> } , <EOL> ] <EOL> return commits <EOL> @ unittest . skip ( "<STR_LIT>" ) <EOL> def test_log_command ( self ) : <EOL> cmd = '<STR_LIT>' <EOL> process = subprocess . Popen ( cmd , cwd = self . repo . path , shell = True , <EOL> stdout = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> so , se = process . communicate ( ) <EOL> logging . info ( '<STR_LIT>' , so ) <EOL> logging . info ( '<STR_LIT>' , se ) <EOL> self . assertEqual ( process . returncode , <NUM_LIT:0> ) <EOL> self . assertEqual ( so . splitlines ( ) , [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] ) <EOL> for alias in SCM_TESTS : <EOL> attrs = { <EOL> '<STR_LIT>' : alias , <EOL> } <EOL> cls_name = '<STR_LIT>' . join ( ( '<STR_LIT>' % alias ) . title ( ) . split ( ) ) <EOL> bases = ( RealCliMixin , unittest . TestCase ) <EOL> globals ( ) [ cls_name ] = type ( cls_name , bases , attrs ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
