Пример #1
0
    def test_register_valid_class(self):
        """Test backend registration for a custom valid backend."""
        backend_name = register_backend(ValidBackend)

        # Check that it has been added to the list of backends.
        self.assertIn(backend_name, _REGISTERED_BACKENDS.keys())
        self.assertEqual(_REGISTERED_BACKENDS[backend_name].cls, ValidBackend)

        # Second registration should fail as it is already registered.
        with self.assertRaises(QISKitError):
            register_backend(ValidBackend)
    def test_register_valid_class(self):
        """Test backend registration for a custom valid backend."""
        backend_name = register_backend(ValidBackend)

        # Check that it has been added to the list of backends.
        self.assertIn(backend_name, _REGISTERED_BACKENDS.keys())
        self.assertEqual(_REGISTERED_BACKENDS[backend_name].cls, ValidBackend)

        # Second registration should fail as it is already registered.
        with self.assertRaises(QISKitError):
            register_backend(ValidBackend)
Пример #3
0
    def test_register_invalid_class(self):
        """Test backend registration for invalid backends."""
        initial_backends_len = len(_REGISTERED_BACKENDS)

        for backend_cls in [
                NotSubclassBackend, NoConfigurationBackend,
                UninstantiableBackend
        ]:
            with self.subTest(backend_cls=backend_cls):
                with self.assertRaises(QISKitError):
                    register_backend(backend_cls)

        self.assertEqual(initial_backends_len, len(_REGISTERED_BACKENDS))
    def test_register_invalid_class(self):
        """Test backend registration for invalid backends."""
        initial_backends_len = len(_REGISTERED_BACKENDS)

        with self.assertRaises(QISKitError):
            register_backend(NotSubclassBackend)

        with self.assertRaises(QISKitError):
            register_backend(NoConfigurationBackend)

        with self.assertRaises(QISKitError):
            register_backend(UninstantiableBackend)

        self.assertEqual(initial_backends_len, len(_REGISTERED_BACKENDS))