<s> import os <EOL> import sys <EOL> import unittest <EOL> import datetime <EOL> from iktomi . cli . base import Cli , manage , argument <EOL> from cStringIO import StringIO <EOL> __all__ = [ '<STR_LIT>' ] <EOL> try : <EOL> from unittest . mock import patch <EOL> except ImportError : <EOL> from mock import patch <EOL> class CliTest ( unittest . TestCase ) : <EOL> def test_manage ( self ) : <EOL> '<STR_LIT>' <EOL> assrt = self . assertEquals <EOL> class TestCommand ( Cli ) : <EOL> def command_avocado ( self , arg , kwarg = None , kwarg2 = False ) : <EOL> assrt ( arg , '<STR_LIT>' ) <EOL> assrt ( kwarg , '<STR_LIT>' ) <EOL> assrt ( kwarg2 , False ) <EOL> print ( "<STR_LIT>" ) <EOL> test_cmd = TestCommand ( ) <EOL> argv = '<STR_LIT>' <EOL> out = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , out ) : <EOL> manage ( dict ( fruit = test_cmd ) , argv . split ( ) ) <EOL> self . assertEqual ( "<STR_LIT>" , out . getvalue ( ) ) <EOL> def test_function_as_command ( self ) : <EOL> '<STR_LIT>' <EOL> def cmd ( arg , kwarg = None , kwarg2 = False , kwarg3 = False ) : <EOL> self . assertEquals ( arg , '<STR_LIT>' ) <EOL> self . assertEquals ( kwarg , '<STR_LIT>' ) <EOL> self . assertEquals ( kwarg2 , True ) <EOL> self . assertEquals ( kwarg3 , '<STR_LIT>' ) <EOL> print ( "<STR_LIT>" ) <EOL> argv = '<STR_LIT>' <EOL> out = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , out ) : <EOL> manage ( dict ( fruit = cmd ) , argv . split ( ) ) <EOL> self . assertEqual ( "<STR_LIT>" , out . getvalue ( ) ) <EOL> def test_function_with_convs_as_command ( self ) : <EOL> '<STR_LIT>' <EOL> @ argument ( <NUM_LIT:0> , argument . to_int ) <EOL> @ argument ( '<STR_LIT>' , argument . to_date ) <EOL> def cmd ( arg , kwarg = None , kwarg2 = False ) : <EOL> self . assertEquals ( arg , <NUM_LIT:1> ) <EOL> self . assertEquals ( kwarg , datetime . date ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:9> ) ) <EOL> self . assertEquals ( kwarg2 , True ) <EOL> print ( "<STR_LIT>" ) <EOL> argv = '<STR_LIT>' <EOL> out = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , out ) : <EOL> manage ( dict ( fruit = cmd ) , argv . split ( ) ) <EOL> self . assertEqual ( "<STR_LIT>" , out . getvalue ( ) ) <EOL> def test_convs ( self ) : <EOL> '<STR_LIT>' <EOL> assrt = self . assertEquals <EOL> class TestCommand ( Cli ) : <EOL> @ argument ( <NUM_LIT:1> , argument . to_int ) <EOL> @ argument ( '<STR_LIT>' , argument . to_date ) <EOL> def command_avocado ( self , arg , kwarg = None , kwarg2 = False ) : <EOL> assrt ( arg , <NUM_LIT:1> ) <EOL> assrt ( kwarg , datetime . date ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:9> ) ) <EOL> assrt ( kwarg2 , True ) <EOL> print ( "<STR_LIT>" ) <EOL> test_cmd = TestCommand ( ) <EOL> argv = '<STR_LIT>' <EOL> out = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , out ) : <EOL> manage ( dict ( fruit = test_cmd ) , argv . split ( ) ) <EOL> self . assertEqual ( "<STR_LIT>" , out . getvalue ( ) ) <EOL> def test_convs_errors ( self ) : <EOL> '<STR_LIT>' <EOL> def init_cmd ( ) : <EOL> class TestCommand ( Cli ) : <EOL> @ argument ( <NUM_LIT:1> , argument . to_int ) <EOL> @ argument ( u'<STR_LIT>' , argument . to_date ) <EOL> def command_avocado ( self , arg , kwarg = None , kwarg2 = False ) : <EOL> pass <EOL> return TestCommand <EOL> self . assertRaises ( AssertionError , init_cmd ) <EOL> def test_incorrect_call ( self ) : <EOL> '<STR_LIT>' <EOL> assrt = self . assertEquals <EOL> class TestCommand ( Cli ) : <EOL> def command_avocado ( self , arg , kwarg = None , kwarg2 = False ) : <EOL> pass <EOL> argv = '<STR_LIT>' <EOL> out = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , out ) : <EOL> with self . assertRaises ( SystemExit ) as exc : <EOL> manage ( dict ( fruit = TestCommand ( ) ) , argv . split ( ) ) <EOL> self . assertEqual ( exc . exception . code , <EOL> '<STR_LIT>' ) <EOL> self . assertIn ( "<STR_LIT>" , out . getvalue ( ) ) <EOL> self . assertIn ( "<STR_LIT>" , out . getvalue ( ) ) <EOL> self . assertNotIn ( "<STR_LIT>" , out . getvalue ( ) ) <EOL> def test_digest_not_found ( self ) : <EOL> class TestCommand ( Cli ) : <EOL> def command_avocado ( self , kwarg = None , kwarg2 = False ) : <EOL> pass <EOL> argv = '<STR_LIT>' <EOL> out = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , out ) : <EOL> with self . assertRaises ( SystemExit ) : <EOL> manage ( dict ( fruit = TestCommand ( ) ) , argv . split ( ) ) <EOL> self . assertEqual ( '<STR_LIT>' , out . getvalue ( ) ) <EOL> def test_no_command_provided ( self ) : <EOL> class TestCommand ( Cli ) : <EOL> def command_avocado ( self , kwarg = None , kwarg2 = False ) : <EOL> pass <EOL> argv = '<STR_LIT>' <EOL> out = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , out ) : <EOL> with self . assertRaises ( SystemExit ) as exc : <EOL> manage ( dict ( fruit = TestCommand ( ) ) , argv . split ( ) ) <EOL> self . assertEqual ( '<STR_LIT>' , out . getvalue ( ) ) <EOL> def test_command_not_found ( self ) : <EOL> class TestCommand ( Cli ) : <EOL> def command_avocado ( self , kwarg = None , kwarg2 = False ) : <EOL> pass <EOL> argv = '<STR_LIT>' <EOL> out = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , out ) : <EOL> with self . assertRaises ( SystemExit ) as exc : <EOL> manage ( dict ( fruit = TestCommand ( ) ) , argv . split ( ) ) <EOL> self . assertEqual ( exc . exception . code , <EOL> '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , out . getvalue ( ) ) <EOL> self . assertIn ( '<STR_LIT>' , out . getvalue ( ) ) <EOL> def test_documented_function_description ( self ) : <EOL> class TestCommand ( Cli ) : <EOL> def command_avocado ( self , kwarg = None , kwarg2 = False ) : <EOL> "<STR_LIT>" <EOL> pass <EOL> cli_command = TestCommand ( ) <EOL> out = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , out ) : <EOL> cli_command ( '<STR_LIT>' ) <EOL> self . assertIn ( "<STR_LIT>" , out . getvalue ( ) ) <EOL> self . assertNotIn ( "<STR_LIT>" , out . getvalue ( ) ) <EOL> self . assertIn ( "<STR_LIT>" , out . getvalue ( ) ) <EOL> self . assertIn ( "<STR_LIT>" , out . getvalue ( ) ) <EOL> def test_converter_int_error ( self ) : <EOL> class TestCommand ( Cli ) : <EOL> @ argument ( '<STR_LIT>' , argument . to_int ) <EOL> def command_avocado ( self , kwarg ) : <EOL> pass <EOL> test_cmd = TestCommand ( ) <EOL> argv = '<STR_LIT>' <EOL> err = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , err ) : <EOL> with self . assertRaises ( SystemExit ) as exc : <EOL> manage ( dict ( fruit = test_cmd ) , argv . split ( ) ) <EOL> self . assertIn ( '<STR_LIT>' , <EOL> err . getvalue ( ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> exc . exception . code . message ) <EOL> def test_converter_date_error ( self ) : <EOL> class TestCommand ( Cli ) : <EOL> @ argument ( '<STR_LIT>' , argument . to_date ) <EOL> def command_avocado ( self , kwarg ) : <EOL> pass <EOL> test_cmd = TestCommand ( ) <EOL> argv = '<STR_LIT>' <EOL> err = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , err ) : <EOL> with self . assertRaises ( SystemExit ) as exc : <EOL> manage ( dict ( fruit = test_cmd ) , argv . split ( ) ) <EOL> self . assertIn ( '<STR_LIT>' , <EOL> err . getvalue ( ) ) <EOL> self . assertIn ( '<STR_LIT>' , <EOL> exc . exception . code . message ) <EOL> self . assertIn ( '<STR_LIT>' , exc . exception . code . message ) <EOL> def test_argument_call_error ( self ) : <EOL> class TestCommand ( Cli ) : <EOL> @ argument ( <NUM_LIT:2> , argument . to_int ) <EOL> def command_avocado ( self , arg , kwarg = None ) : <EOL> pass <EOL> argv = '<STR_LIT>' <EOL> test_cmd = TestCommand ( ) <EOL> err = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , err ) : <EOL> with self . assertRaises ( SystemExit ) as exc : <EOL> manage ( dict ( fruit = test_cmd ) , argv . split ( ) ) <EOL> self . assertIn ( '<STR_LIT>' , <EOL> err . getvalue ( ) ) <EOL> self . assertEqual ( '<STR_LIT>' + '<STR_LIT>' , <EOL> exc . exception . code . message ) <EOL> def test_argument_required ( self ) : <EOL> class TestCommand ( Cli ) : <EOL> @ argument ( '<STR_LIT>' , argument . to_int , required = True ) <EOL> def command_avocado ( self , kwarg = <NUM_LIT:1> , kwarg2 = None ) : <EOL> pass <EOL> argv = '<STR_LIT>' <EOL> test_cmd = TestCommand ( ) <EOL> err = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , err ) : <EOL> with self . assertRaises ( SystemExit ) as exc : <EOL> manage ( dict ( fruit = test_cmd ) , argv . split ( ) ) <EOL> self . assertIn ( '<STR_LIT>' , <EOL> err . getvalue ( ) ) <EOL> self . assertIn ( '<STR_LIT>' , <EOL> exc . exception . code . message ) <EOL> def test_autocomplete ( self ) : <EOL> class TestCommand ( Cli ) : <EOL> def command_avocado ( self , kwarg ) : <EOL> pass <EOL> argv = '<STR_LIT>' <EOL> test_cmd = TestCommand ( ) <EOL> with patch . dict ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : argv , <EOL> '<STR_LIT>' : '<STR_LIT:1>' } ) : <EOL> out = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , out ) : <EOL> with self . assertRaises ( SystemExit ) : <EOL> manage ( dict ( fruit = test_cmd ) , argv . split ( ) ) <EOL> self . assertEqual ( '<STR_LIT>' , out . getvalue ( ) ) <EOL> argv = '<STR_LIT>' <EOL> test_cmd = TestCommand ( ) <EOL> with patch . dict ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : argv , <EOL> '<STR_LIT>' : '<STR_LIT:1>' } ) : <EOL> out = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , out ) : <EOL> with self . assertRaises ( SystemExit ) : <EOL> manage ( dict ( fruit = test_cmd ) , argv . split ( ) ) <EOL> self . assertEqual ( '<STR_LIT>' , out . getvalue ( ) ) <EOL> argv = '<STR_LIT>' <EOL> test_cmd = TestCommand ( ) <EOL> with patch . dict ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : argv . replace ( "<STR_LIT::>" , "<STR_LIT>" ) , <EOL> '<STR_LIT>' : '<STR_LIT:2>' } ) : <EOL> out = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , out ) : <EOL> with self . assertRaises ( SystemExit ) : <EOL> manage ( dict ( fruit = test_cmd ) , argv . split ( ) ) <EOL> self . assertEqual ( '<STR_LIT>' , out . getvalue ( ) ) <EOL> argv = '<STR_LIT>' <EOL> test_cmd = TestCommand ( ) <EOL> with patch . dict ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : argv . replace ( "<STR_LIT::>" , "<STR_LIT>" ) , <EOL> '<STR_LIT>' : '<STR_LIT:3>' } ) : <EOL> out = StringIO ( ) <EOL> with patch . object ( sys , '<STR_LIT>' , out ) : <EOL> with self . assertRaises ( SystemExit ) : <EOL> manage ( dict ( fruit = test_cmd ) , argv . split ( ) ) <EOL> self . assertEqual ( '<STR_LIT>' , out . getvalue ( ) ) </s>
