示例#1
0
    def test_register_with_returned_function(self):
        def load_text(filename):
            return 'Loading {}...'.format(filename)

        core.register('text', load_text, returned=lambda text: text.upper())
        text = load.text('foo.txt')
        self.assertEqual(text, 'LOADING FOO.TXT...')
示例#2
0
    def test_load_existing_asset(self):
        with define_test_loader('text'):
            # write a test file.
            text_path = get_config().search_paths('text', 'test.txt')[0]
            with open(text_path, 'w') as textfile:
                textfile.write('TEST!')

            # load the asset using the pygame_assets.load API.
            text = load.text('test.txt')
            self.assertEqual('TEST!', text)
示例#3
0
 def test_load_non_existing_asset_fails(self):
     with define_test_loader('text'):
         with self.assertRaises(AssetNotFoundError):
             load.text('does_not_exist.txt')