<s> import os . path <EOL> import platform <EOL> from cursesmenu import CursesMenu <EOL> try : <EOL> from unittest . mock import patch <EOL> except ImportError : <EOL> from mock import patch <EOL> from cursesmenu . items import CommandItem <EOL> from test_external_item import TestExternalItem <EOL> class TestCommandItem ( TestExternalItem ) : <EOL> def setUp ( self ) : <EOL> super ( TestCommandItem , self ) . setUp ( ) <EOL> self . menu = CursesMenu ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def test_init ( self ) : <EOL> command_item_1 = CommandItem ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> command_item_2 = CommandItem ( "<STR_LIT>" , "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , self . menu , True ) <EOL> command_item_3 = CommandItem ( text = "<STR_LIT>" , command = "<STR_LIT>" , menu = self . menu , <EOL> arguments = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , should_exit = False ) <EOL> self . assertEqual ( command_item_1 . text , "<STR_LIT>" ) <EOL> self . assertEqual ( command_item_2 . text , "<STR_LIT>" ) <EOL> self . assertEqual ( command_item_3 . text , "<STR_LIT>" ) <EOL> self . assertEqual ( command_item_1 . menu , None ) <EOL> self . assertEqual ( command_item_2 . menu , self . menu ) <EOL> self . assertEqual ( command_item_3 . menu , self . menu ) <EOL> self . assertFalse ( command_item_1 . should_exit ) <EOL> self . assertTrue ( command_item_2 . should_exit ) <EOL> self . assertFalse ( command_item_3 . should_exit ) <EOL> self . assertEqual ( command_item_1 . command , "<STR_LIT>" ) <EOL> self . assertEqual ( command_item_2 . command , "<STR_LIT>" ) <EOL> self . assertEqual ( command_item_3 . command , "<STR_LIT>" ) <EOL> self . assertEqual ( command_item_1 . arguments , [ ] ) <EOL> self . assertEqual ( command_item_2 . arguments , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertEqual ( command_item_3 . arguments , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def test_return ( self ) : <EOL> if platform . system ( ) . lower ( ) == "<STR_LIT>" : <EOL> return_command_item = CommandItem ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> else : <EOL> return_command_item = CommandItem ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> return_command_item . action ( ) <EOL> self . assertEqual ( return_command_item . get_return ( ) , <NUM_LIT:1> ) <EOL> def test_run ( self ) : <EOL> create_item = CommandItem ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> if platform . system ( ) . lower ( ) == "<STR_LIT>" : <EOL> delete_item = CommandItem ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> expected_contents = "<STR_LIT>" <EOL> else : <EOL> delete_item = CommandItem ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> expected_contents = "<STR_LIT>" <EOL> create_item . action ( ) <EOL> self . assertEqual ( create_item . get_return ( ) , <NUM_LIT:0> ) <EOL> self . assertTrue ( os . path . isfile ( "<STR_LIT>" ) ) <EOL> with open ( "<STR_LIT>" , '<STR_LIT:r>' ) as text : <EOL> self . assertEqual ( text . read ( ) , expected_contents ) <EOL> delete_item . action ( ) <EOL> self . assertEqual ( delete_item . get_return ( ) , <NUM_LIT:0> ) <EOL> self . assertFalse ( os . path . isfile ( "<STR_LIT>" ) ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_call ( self , mock_class ) : <EOL> command_item = CommandItem ( "<STR_LIT>" , "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> command_item . action ( ) <EOL> mock_class . run . assert_called_with ( "<STR_LIT>" , shell = True ) </s>
