<s> from __future__ import absolute_import , division , print_function <EOL> import pytest <EOL> from mock import patch <EOL> from glue . tests . helpers import requires_qt <EOL> from . . core import Data <EOL> from . . main import ( die_on_error , restore_session , load_data_files , <EOL> main , start_glue ) <EOL> @ requires_qt <EOL> def test_die_on_error_exception ( ) : <EOL> """<STR_LIT>""" <EOL> with pytest . raises ( SystemExit ) : <EOL> with patch ( '<STR_LIT>' ) as qmb : <EOL> @ die_on_error ( '<STR_LIT>' ) <EOL> def test ( ) : <EOL> raise Exception ( ) <EOL> test ( ) <EOL> assert qmb . call_count == <NUM_LIT:1> <EOL> def test_die_on_error_noexception ( ) : <EOL> """<STR_LIT>""" <EOL> @ die_on_error ( '<STR_LIT>' ) <EOL> def test ( ) : <EOL> return <NUM_LIT:0> <EOL> assert test ( ) == <NUM_LIT:0> <EOL> def test_load_data_files ( ) : <EOL> with patch ( '<STR_LIT>' ) as ld : <EOL> ld . return_value = Data ( ) <EOL> dc = load_data_files ( [ '<STR_LIT>' ] ) <EOL> assert len ( dc ) == <NUM_LIT:1> <EOL> def check_main ( cmd , glue , config , data ) : <EOL> """<STR_LIT>""" <EOL> with patch ( '<STR_LIT>' ) as sg : <EOL> main ( cmd . split ( ) ) <EOL> args , kwargs = sg . call_args <EOL> assert kwargs . get ( '<STR_LIT>' , None ) == data <EOL> assert kwargs . get ( '<STR_LIT>' , None ) == glue <EOL> assert kwargs . get ( '<STR_LIT>' , None ) == config <EOL> def check_exec ( cmd , pyfile ) : <EOL> """<STR_LIT>""" <EOL> with patch ( '<STR_LIT>' ) as es : <EOL> main ( cmd . split ( ) ) <EOL> args , kwargs = es . call_args <EOL> assert args [ <NUM_LIT:0> ] == pyfile <EOL> def test_main_single_data ( ) : <EOL> check_main ( '<STR_LIT>' , None , None , [ '<STR_LIT>' ] ) <EOL> def test_main_multi_data ( ) : <EOL> check_main ( '<STR_LIT>' , None , None , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_main_config ( ) : <EOL> check_main ( '<STR_LIT>' , None , '<STR_LIT>' , None ) <EOL> def test_main_glu_arg ( ) : <EOL> check_main ( '<STR_LIT>' , '<STR_LIT>' , None , None ) <EOL> def test_main_auto_glu ( ) : <EOL> check_main ( '<STR_LIT>' , '<STR_LIT>' , None , None ) <EOL> def test_main_many_args ( ) : <EOL> check_main ( '<STR_LIT>' , None , <EOL> '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_exec ( ) : <EOL> check_exec ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_auto_exec ( ) : <EOL> check_exec ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ pytest . mark . parametrize ( ( '<STR_LIT>' ) , [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> def test_invalid ( cmd ) : <EOL> with pytest . raises ( SystemExit ) : <EOL> main ( cmd . split ( ) ) <EOL> @ requires_qt <EOL> @ pytest . mark . parametrize ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:data>' ) , <EOL> [ ( '<STR_LIT>' , None , None ) , <EOL> ( None , '<STR_LIT>' , None ) , <EOL> ( None , None , [ '<STR_LIT>' ] ) , <EOL> ( None , None , [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> ( None , '<STR_LIT>' , [ '<STR_LIT>' ] ) ] ) <EOL> def test_start ( glue , config , data ) : <EOL> with patch ( '<STR_LIT>' ) as rs : <EOL> with patch ( '<STR_LIT>' ) as lc : <EOL> with patch ( '<STR_LIT>' ) as ldf : <EOL> with patch ( '<STR_LIT>' ) as ga : <EOL> with patch ( '<STR_LIT>' ) as qt : <EOL> rs . return_value = ga <EOL> ldf . return_value = Data ( ) <EOL> start_glue ( glue , config , data ) <EOL> if glue : <EOL> rs . assert_called_once_with ( glue ) <EOL> if config : <EOL> lc . assert_called_once_with ( search_path = [ config ] ) <EOL> if data : <EOL> ldf . assert_called_once_with ( data ) </s>
