<s> from client import exceptions as ex <EOL> from client . sources import ok_test <EOL> from client . sources . ok_test import models <EOL> import mock <EOL> import unittest <EOL> class LoadTest ( unittest . TestCase ) : <EOL> NAME = '<STR_LIT>' <EOL> VALID_FILE = '<STR_LIT>' + NAME + '<STR_LIT>' <EOL> INVALID_FILE = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> self . patcherIsFile = mock . patch ( '<STR_LIT>' ) <EOL> self . addCleanup ( self . patcherIsFile . stop ) <EOL> self . mockIsFile = self . patcherIsFile . start ( ) <EOL> self . mockIsFile . return_value = True <EOL> self . patcherLoadModule = mock . patch ( '<STR_LIT>' ) <EOL> self . addCleanup ( self . patcherLoadModule . stop ) <EOL> self . mockLoadModule = self . patcherLoadModule . start ( ) <EOL> self . mockModule = self . mockLoadModule . return_value <EOL> self . cmd_args = mock . Mock ( ) <EOL> def call_load ( self , file = VALID_FILE ) : <EOL> return ok_test . load ( file , '<STR_LIT>' , self . cmd_args ) <EOL> def testInvalidFileType ( self ) : <EOL> self . assertRaises ( ex . LoadingException , self . call_load , <EOL> file = self . INVALID_FILE ) <EOL> def testNoSuchFile ( self ) : <EOL> self . mockIsFile . return_value = False <EOL> self . assertRaises ( ex . LoadingException , self . call_load ) <EOL> def testImportError ( self ) : <EOL> self . mockLoadModule . side_effect = Exception <EOL> self . assertRaises ( ex . LoadingException , self . call_load ) <EOL> def testSerializeError ( self ) : <EOL> self . mockModule . test = { '<STR_LIT>' : '<STR_LIT:test>' } <EOL> self . assertRaises ( ex . LoadingException , self . call_load ) <EOL> def testUsesBasenameAsName ( self ) : <EOL> self . mockModule . test = { <EOL> '<STR_LIT:name>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : [ ] <EOL> } <EOL> result = self . call_load ( ) <EOL> self . assertIsInstance ( result , dict ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( result ) ) <EOL> self . assertIn ( self . NAME , result ) <EOL> self . assertIsInstance ( result [ self . NAME ] , models . OkTest ) </s>
