<s> """<STR_LIT>""" <EOL> import unittest <EOL> from mock import patch <EOL> from mayavi . core . null_engine import NullEngine <EOL> from mayavi . plugins . envisage_engine import EnvisageEngine <EOL> from mayavi . api import OffScreenEngine , Engine <EOL> from mayavi . tools . engine_manager import get_engine <EOL> def patch_registry_engines ( engines ) : <EOL> return patch ( "<STR_LIT>" , engines ) <EOL> def patch_backend ( backend ) : <EOL> return patch ( "<STR_LIT>" , backend ) <EOL> def patch_offscreen ( switch_on ) : <EOL> return patch ( "<STR_LIT>" , switch_on ) <EOL> class TestEngineManager ( unittest . TestCase ) : <EOL> @ patch_backend ( "<STR_LIT:test>" ) <EOL> def test_get_engine_backend_test ( self ) : <EOL> self . assertIsInstance ( get_engine ( ) , NullEngine ) <EOL> @ patch_backend ( "<STR_LIT>" ) <EOL> @ patch_registry_engines ( { "<STR_LIT>" : EnvisageEngine ( ) } ) <EOL> def test_get_engine_backend_envisage ( self ) : <EOL> self . assertIs ( type ( get_engine ( ) ) , EnvisageEngine ) <EOL> @ patch_backend ( "<STR_LIT>" ) <EOL> @ patch_registry_engines ( { "<STR_LIT>" : NullEngine ( ) } ) <EOL> def test_get_engine_backend_simple_with_existing_engine ( self ) : <EOL> self . assertIs ( type ( get_engine ( ) ) , Engine ) <EOL> @ patch_backend ( "<STR_LIT>" ) <EOL> @ patch_registry_engines ( { "<STR_LIT>" : EnvisageEngine ( ) } ) <EOL> def test_get_engine_backend_auto_with_existing_engine ( self ) : <EOL> self . assertIs ( type ( get_engine ( ) ) , EnvisageEngine ) <EOL> @ patch_backend ( "<STR_LIT>" ) <EOL> @ patch_registry_engines ( { "<STR_LIT>" : EnvisageEngine ( ) } ) <EOL> @ patch_offscreen ( True ) <EOL> def test_get_engine_offscreen_backend_envisage ( self ) : <EOL> self . assertIs ( type ( get_engine ( ) ) , EnvisageEngine ) <EOL> @ patch_backend ( "<STR_LIT:test>" ) <EOL> @ patch_offscreen ( True ) <EOL> def test_get_engine_offscreen_backend_test ( self ) : <EOL> self . assertIs ( type ( get_engine ( ) ) , NullEngine ) <EOL> @ patch_backend ( "<STR_LIT>" ) <EOL> @ patch_offscreen ( True ) <EOL> @ patch_registry_engines ( { "<STR_LIT>" : Engine ( ) } ) <EOL> def test_get_engine_offscreen_backend_auto_with_existing_engine ( self ) : <EOL> self . assertIs ( type ( get_engine ( ) ) , OffScreenEngine ) <EOL> @ patch_backend ( "<STR_LIT>" ) <EOL> @ patch_offscreen ( True ) <EOL> @ patch_registry_engines ( { "<STR_LIT>" : Engine ( ) } ) <EOL> def test_get_engine_offscreen_backend_auto_switched_twice ( self ) : <EOL> self . assertIs ( type ( get_engine ( ) ) , OffScreenEngine ) <EOL> from mayavi . tools . engine_manager import options <EOL> options . offscreen = False <EOL> self . assertIs ( type ( get_engine ( ) ) , Engine ) <EOL> @ patch_backend ( "<STR_LIT>" ) <EOL> @ patch_offscreen ( True ) <EOL> @ patch_registry_engines ( { "<STR_LIT>" : Engine ( ) } ) <EOL> def test_get_engine_offscreen_backend_simple_with_started_engine ( self ) : <EOL> self . assertIs ( type ( get_engine ( ) ) , OffScreenEngine ) </s>
