Beispiel #1
0
    def test_get_default(self):
        target = conf_factory.ThreadLocalNamedSingletonPluginFactory(
            "TEST_NAMED_FACTORY")

        actual1 = target.create()
        actual2 = target.create()

        assert actual1 is actual2
Beispiel #2
0
    def test_get_specific(self):
        """
        Get a specific item and ensure it's not falling back to default.
        """
        target = conf_factory.ThreadLocalNamedSingletonPluginFactory(
            "TEST_NAMED_FACTORY_NO_DEFAULT")

        actual1 = target.create("iron")
        actual2 = target.create("iron")

        assert actual1 is actual2
Beispiel #3
0
    def test_get_type_definition_is_cached(self, monkeypatch):
        mock_import = mock.Mock()
        mock_import.return_value = factory.Bar
        monkeypatch.setattr(conf_factory, "import_type", mock_import)

        target = conf_factory.ThreadLocalNamedSingletonPluginFactory(
            "TEST_NAMED_FACTORY")

        actual1 = target.create()
        actual2 = target.create()

        assert isinstance(actual1, factory.Bar)
        assert isinstance(actual2, factory.Bar)
        assert actual1 is actual2
        mock_import.assert_called_once_with("tests.factory.Bar")