Beispiel #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...')
Beispiel #2
0
    def test_unregister_dummy_loader(self):
        def load_text(filename):
            return 'Loading {}...'.format(filename)

        core.register('text', load_text)
        self.assertIn('text', core.loaders)
        core.unregister('text', in_config=False)
        self.assertNotIn('text', core.loaders)
Beispiel #3
0
    def test_register_dummy_loader(self):
        with self.assertRaises(AttributeError):
            core.load.text

        def load_text(filename):
            return 'Loading {}...'.format(filename)

        # normally you'd register a real @loader() function.
        core.register('text', load_text)

        self.assertEqual(core.loaders['text'], load_text)
        self.assertEqual('Loading foo.txt...', core.load.text('foo.txt'))

        # cleanup
        core.unregister('text', in_config=False)