<s> import os <EOL> import sys <EOL> import unittest <EOL> from iktomi . cli . lazy import LazyCli <EOL> from iktomi . cli . base import Cli , manage <EOL> from cStringIO import StringIO <EOL> try : <EOL> from unittest . mock import patch <EOL> except ImportError : <EOL> from mock import patch <EOL> class MyCli ( Cli ) : <EOL> '<STR_LIT>' <EOL> called = False <EOL> def command_run ( self , arg ) : <EOL> self . called = arg <EOL> class LazyTests ( unittest . TestCase ) : <EOL> def test_lazy_call ( self ) : <EOL> @ LazyCli <EOL> def cli ( ) : <EOL> return MyCli ( ) <EOL> self . assertIsInstance ( cli . digest , MyCli ) <EOL> print cli . description ( ) <EOL> self . assertEqual ( cli . description ( ) . splitlines ( ) [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( cli . description ( ) . splitlines ( ) [ <NUM_LIT:1> ] , <EOL> '<STR_LIT>' ) <EOL> cli ( '<STR_LIT>' , True ) <EOL> self . assertTrue ( cli . digest . called ) <EOL> def test_lazyness ( self ) : <EOL> @ LazyCli <EOL> def cli ( ) : <EOL> raise ValueError <EOL> self . assertRaises ( ValueError , lambda : cli . digest ) <EOL> def test_lazy_autocomplete ( self ) : <EOL> @ LazyCli <EOL> def cli ( ) : <EOL> return MyCli ( ) <EOL> argv = '<STR_LIT>' <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 = cli ) , argv . split ( ) ) <EOL> self . assertEqual ( '<STR_LIT>' , out . getvalue ( ) ) </s>
