Esempio n. 1
0
    def test_manager_instances_not_found(self):
        """
        Tests response when requesting the instance of a source class
        that isn't loaded
        """
        source_name = 'no_metadata'
        path = 'test/sample_proxysources/' + source_name
        os.environ['PROXY_PATH'] = path
        expected_stdout = 'The source doesn\'t exist'

        m = ProxySourceManager()
        with self.assertRaises(InvalidProxySource) as err:
            m.instance(source_name)
        self.assertEqual(expected_stdout, str(err.exception))
Esempio n. 2
0
    def test_several_folders(self):
        """
        Searches for sources in several folders with
        valid and invalid proxy source classes
        """
        source_path = 'test/sample_proxysources/'
        test_data = [
            ('valid_metadata', 1, 3),
            ('no_metadata', 0, 0),
            ('incomplete_metadata', 0, 0),
            ('two_classes_one_file', 0, 0),
            ('no_inheritance', 0, 0),
        ]

        for name, valid_classes, valid_types in test_data:
            path = source_path + name
            os.environ['PROXY_PATH'] = path

            m = ProxySourceManager()
            if valid_classes:
                inst = m.instance(name)
                types = inst.metadata['type']
                for t in types:
                    self.assertEqual(len(m.proxies_per_type[t]), valid_classes)

            self.assertEqual(type(m.proxies_per_type), dict)
            self.assertEqual(len(m.proxies_per_type), valid_types)
Esempio n. 3
0
    def test_manager_instances_success(self):
        """
        Tests return of instance method when requesting a loaded source classes
        """
        source_name = 'valid_metadata'
        path = 'test/sample_proxysources/' + source_name
        os.environ['PROXY_PATH'] = path

        m = ProxySourceManager()
        inst = m.instance(source_name)
        self.assertEqual(inst.__class__.__name__, ValidMetadataSource.__name__)