Пример #1
0
class CollectorTest(TestCase):

    def setUp(self):
        path = abspath('tests/test_env')
        self.collector = ClassCollector(path, BaseCommand)

    def test_path_not_found(self):
        self.assertRaises(ValueError, ClassCollector, 'notfoundpath',
                          BaseCommand)

    def test_iscommand(self):
        self.assertTrue(self.collector.iscommand(Authorization))

    def test_inmodule(self):
        self.assertTrue(self.collector.inmodule(Authorization, auth))
        self.assertFalse(self.collector.inmodule(Authorization, test_env))

    def test_python_files(self):
        self.assertEqual(filenames(self.collector.python_files()),
                         ['__init__.py', 'auth.py', '__init__.py',
                          'base_command.py'])

    def test_classes(self):
        classes = list(self.collector.classes())
        self.assertEqual(names(classes), ['Authorization', 'BaseCommand'])

    def test_commands_gen(self):
        commands = self.collector.commands_gen()
        self.assertEqual(names(commands), ['Authorization'])

    def test_commands(self):
        self.assertEqual(names(self.collector.commands()),
                         names(self.collector.commands_gen()))

    def test_mapper(self):
        mapper = self.collector.mapper()
        self.assertEqual(mapper['user.authorization'].__name__,
                         'Authorization')

    def test_mapper_custom_key(self):
        mapper = self.collector.mapper(lambda cls: cls.__name__)
        self.assertEqual(mapper['Authorization'].__name__, 'Authorization')