<s> import os <EOL> import mock <EOL> import pytest <EOL> from headlessvim import Vim , open <EOL> @ pytest . fixture <EOL> def env ( request ) : <EOL> return dict ( os . environ , LANG = '<STR_LIT:C>' ) <EOL> @ pytest . fixture <EOL> def unterminated_vim ( request , env ) : <EOL> return open ( env = env ) <EOL> @ pytest . yield_fixture <EOL> def vim ( request , unterminated_vim ) : <EOL> vim = unterminated_vim <EOL> yield vim <EOL> vim . close ( ) <EOL> @ pytest . fixture <EOL> def fixtures ( request ) : <EOL> here = os . path . dirname ( __file__ ) <EOL> return os . path . join ( here , '<STR_LIT>' ) <EOL> @ pytest . fixture <EOL> def plugin_dir ( request , fixtures ) : <EOL> return os . path . join ( fixtures , '<STR_LIT>' ) <EOL> @ pytest . fixture <EOL> def plugin_entry_script ( request ) : <EOL> return '<STR_LIT>' <EOL> @ pytest . fixture <EOL> def zombie_vim ( request , unterminated_vim ) : <EOL> vim = unterminated_vim <EOL> vim . close ( ) <EOL> vim . _process = mock . MagicMock ( ) <EOL> vim . _process . is_alive . return_value = True <EOL> return vim <EOL> def test_open ( vim ) : <EOL> assert isinstance ( vim , Vim ) <EOL> def test_close_zombie ( zombie_vim ) : <EOL> vim = zombie_vim <EOL> vim . close ( ) <EOL> vim . _process . terminate . assert_called_once_with ( ) <EOL> vim . _process . kill . assert_called_once_with ( ) <EOL> def test_del ( zombie_vim ) : <EOL> vim = zombie_vim <EOL> vim . __del__ ( ) <EOL> vim . _process . terminate . assert_called_once_with ( ) <EOL> vim . _process . kill . assert_called_once_with ( ) <EOL> def test_context_manager ( ) : <EOL> with open ( ) as vim : <EOL> assert isinstance ( vim , Vim ) <EOL> assert vim . is_alive ( ) <EOL> assert not vim . is_alive ( ) <EOL> def test_is_alive ( unterminated_vim ) : <EOL> vim = unterminated_vim <EOL> assert vim . is_alive ( ) <EOL> vim . close ( ) <EOL> assert not vim . is_alive ( ) <EOL> def test_display ( vim ) : <EOL> display = vim . display ( ) <EOL> assert '<STR_LIT>' in display <EOL> assert '<STR_LIT>' in display <EOL> assert '<STR_LIT>' in display <EOL> assert '<STR_LIT>' in display <EOL> def test_display_lines ( vim ) : <EOL> lines = vim . display_lines ( ) <EOL> assert all ( len ( line ) == <NUM_LIT> for line in lines ) <EOL> assert any ( '<STR_LIT>' in line for line in lines ) <EOL> assert lines [ - <NUM_LIT:1> ] . strip ( ) == '<STR_LIT>' <EOL> def test_send_keys ( vim ) : <EOL> vim . send_keys ( '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in vim . display_lines ( ) [ <NUM_LIT:0> ] <EOL> def test_install_plugin ( vim , plugin_dir , plugin_entry_script ) : <EOL> vim . install_plugin ( plugin_dir , plugin_entry_script ) <EOL> assert plugin_dir in vim . runtimepath <EOL> assert vim . command ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> def test_command ( vim ) : <EOL> message = '<STR_LIT>' <EOL> assert vim . command ( '<STR_LIT>' . format ( message ) ) == message <EOL> def test_echo ( vim ) : <EOL> message = '<STR_LIT>' <EOL> assert vim . echo ( '<STR_LIT>' . format ( message ) ) == message <EOL> def test_set_mode ( vim ) : <EOL> vim . set_mode ( '<STR_LIT>' ) <EOL> vim . send_keys ( '<STR_LIT>' ) <EOL> vim . set_mode ( '<STR_LIT>' ) <EOL> assert vim . display_lines ( ) [ <NUM_LIT:0> ] . strip ( ) == '<STR_LIT>' <EOL> vim . set_mode ( '<STR_LIT>' ) <EOL> vim . send_keys ( '<STR_LIT>' ) <EOL> assert vim . display_lines ( ) [ <NUM_LIT:0> ] . strip ( ) == '<STR_LIT>' <EOL> vim . send_keys ( '<STR_LIT>' ) <EOL> vim . set_mode ( '<STR_LIT>' ) <EOL> vim . send_keys ( '<STR_LIT>' ) <EOL> assert vim . display_lines ( ) [ <NUM_LIT:0> ] . strip ( ) == '<STR_LIT>' <EOL> def test_set_mode_invalid ( vim ) : <EOL> with pytest . raises ( ValueError ) : <EOL> vim . set_mode ( '<STR_LIT>' ) <EOL> def test_set_mode_setter ( vim ) : <EOL> vim . mode = '<STR_LIT>' <EOL> vim . send_keys ( '<STR_LIT>' ) <EOL> vim . mode = '<STR_LIT>' <EOL> assert vim . display_lines ( ) [ <NUM_LIT:0> ] . strip ( ) == '<STR_LIT>' <EOL> def test_executable ( vim ) : <EOL> assert '<STR_LIT>' in vim . executable <EOL> assert os . path . isabs ( vim . executable ) <EOL> def test_args ( vim ) : <EOL> assert '<STR_LIT>' in vim . args <EOL> def test_encoding ( vim ) : <EOL> assert vim . encoding . lower ( ) == '<STR_LIT:utf-8>' <EOL> def test_screen_size ( vim ) : <EOL> assert vim . screen_size == ( <NUM_LIT> , <NUM_LIT> ) <EOL> def test_screen_size_setter ( vim ) : <EOL> screen_size = ( <NUM_LIT> , <NUM_LIT:32> ) <EOL> vim . screen_size = screen_size <EOL> assert vim . screen_size == screen_size <EOL> assert all ( len ( line ) == screen_size [ <NUM_LIT:0> ] for line in vim . display_lines ( ) ) <EOL> def test_timeout ( vim ) : <EOL> assert <NUM_LIT:0> < vim . timeout < <NUM_LIT:1> <EOL> def test_timeout_setter ( vim ) : <EOL> vim . timeout = <NUM_LIT:10> <EOL> assert vim . timeout == <NUM_LIT:10> </s>
