def test_deepcopy_overridden(self): provider = self.singleton_cls(Example) object_provider = providers.Object(object()) provider.override(object_provider) provider_copy = providers.deepcopy(provider) object_provider_copy = provider_copy.overridden[0] self.assertIsNot(provider, provider_copy) self.assertIs(provider.cls, provider_copy.cls) self.assertIsInstance(provider, self.singleton_cls) self.assertIsNot(object_provider, object_provider_copy) self.assertIsInstance(object_provider_copy, providers.Object)
def test_deepcopy_overridden(self): provider = providers.Coroutine(_example) object_provider = providers.Object(object()) provider.override(object_provider) provider_copy = providers.deepcopy(provider) object_provider_copy = provider_copy.overridden[0] self.assertIsNot(provider, provider_copy) self.assertIs(provider.provides, provider_copy.provides) self.assertIsInstance(provider, providers.Callable) self.assertIsNot(object_provider, object_provider_copy) self.assertIsInstance(object_provider_copy, providers.Object)
def test_deepcopy(self): def call_bar(container): return container.bar() class Container(containers.DeclarativeContainer): __self__ = providers.Self() foo = providers.Callable(call_bar, __self__) bar = providers.Object('hello') container1 = Container() container2 = providers.deepcopy(container1) container1.bar.override('bye') self.assertIs(container1.foo(), 'bye') self.assertIs(container2.foo(), 'hello')
def test_deepcopy_overridden(): provider = providers.List() object_provider = providers.Object(object()) provider.override(object_provider) provider_copy = providers.deepcopy(provider) object_provider_copy = provider_copy.overridden[0] assert provider is not provider_copy assert provider.args == provider_copy.args assert isinstance(provider, providers.List) assert object_provider is not object_provider_copy assert isinstance(object_provider_copy, providers.Object)
def test_deepcopy_args(): provider = providers.Coroutine(example) dependent_provider1 = providers.Callable(list) dependent_provider2 = providers.Callable(dict) provider.add_args(dependent_provider1, dependent_provider2) provider_copy = providers.deepcopy(provider) dependent_provider_copy1 = provider_copy.args[0] dependent_provider_copy2 = provider_copy.args[1] assert dependent_provider1.provides is dependent_provider_copy1.provides assert dependent_provider1 is not dependent_provider_copy1 assert dependent_provider2.provides is dependent_provider_copy2.provides assert dependent_provider2 is not dependent_provider_copy2
def test_deepcopy_kwargs(): provider = providers.Coroutine(example) dependent_provider1 = providers.Callable(list) dependent_provider2 = providers.Callable(dict) provider.add_kwargs(a1=dependent_provider1, a2=dependent_provider2) provider_copy = providers.deepcopy(provider) dependent_provider_copy1 = provider_copy.kwargs["a1"] dependent_provider_copy2 = provider_copy.kwargs["a2"] assert dependent_provider1.provides is dependent_provider_copy1.provides assert dependent_provider1 is not dependent_provider_copy1 assert dependent_provider2.provides is dependent_provider_copy2.provides assert dependent_provider2 is not dependent_provider_copy2
def test_deepcopy(selector): provider_copy = providers.deepcopy(selector) assert provider_copy is not selector assert isinstance(selector, providers.Selector) assert provider_copy.selector is not selector.selector assert isinstance(provider_copy.selector, providers.Configuration) assert provider_copy.one is not selector.one assert isinstance(provider_copy.one, providers.Object) assert provider_copy.one.provides == 1 assert provider_copy.two is not selector.two assert isinstance(provider_copy.two, providers.Object) assert provider_copy.two.provides == 2
def test_deepcopy_args(singleton_cls): provider = singleton_cls(Example) dependent_provider1 = singleton_cls(list) dependent_provider2 = singleton_cls(dict) provider.add_args(dependent_provider1, dependent_provider2) provider_copy = providers.deepcopy(provider) dependent_provider_copy1 = provider_copy.args[0] dependent_provider_copy2 = provider_copy.args[1] assert provider.args != provider_copy.args assert dependent_provider1.cls is dependent_provider_copy1.cls assert dependent_provider1 is not dependent_provider_copy1 assert dependent_provider2.cls is dependent_provider_copy2.cls assert dependent_provider2 is not dependent_provider_copy2
def test_deepcopy_args(): provider = providers.List() dependent_provider1 = providers.Factory(list) dependent_provider2 = providers.Factory(dict) provider.add_args(dependent_provider1, dependent_provider2) provider_copy = providers.deepcopy(provider) dependent_provider_copy1 = provider_copy.args[0] dependent_provider_copy2 = provider_copy.args[1] assert provider.args != provider_copy.args assert dependent_provider1.cls is dependent_provider_copy1.cls assert dependent_provider1 is not dependent_provider_copy1 assert dependent_provider2.cls is dependent_provider_copy2.cls assert dependent_provider2 is not dependent_provider_copy2
def test_deepcopy_kwargs(): provider = providers.Factory(Example) dependent_provider1 = providers.Factory(list) dependent_provider2 = providers.Factory(dict) provider.add_kwargs(a1=dependent_provider1, a2=dependent_provider2) provider_copy = providers.deepcopy(provider) dependent_provider_copy1 = provider_copy.kwargs["a1"] dependent_provider_copy2 = provider_copy.kwargs["a2"] assert provider.kwargs != provider_copy.kwargs assert dependent_provider1.cls is dependent_provider_copy1.cls assert dependent_provider1 is not dependent_provider_copy1 assert dependent_provider2.cls is dependent_provider_copy2.cls assert dependent_provider2 is not dependent_provider_copy2
def test_deepcopy_attributes(self): provider = providers.Factory(Example) dependent_provider1 = providers.Factory(list) dependent_provider2 = providers.Factory(dict) provider.add_attributes(a1=dependent_provider1, a2=dependent_provider2) provider_copy = providers.deepcopy(provider) dependent_provider_copy1 = provider_copy.attributes['a1'] dependent_provider_copy2 = provider_copy.attributes['a2'] self.assertNotEqual(provider.attributes, provider_copy.attributes) self.assertIs(dependent_provider1.cls, dependent_provider_copy1.cls) self.assertIsNot(dependent_provider1, dependent_provider_copy1) self.assertIs(dependent_provider2.cls, dependent_provider_copy2.cls) self.assertIsNot(dependent_provider2, dependent_provider_copy2)
def test_deepcopy_kwargs(self): provider = self.singleton_cls(Example) dependent_provider1 = self.singleton_cls(list) dependent_provider2 = self.singleton_cls(dict) provider.add_kwargs(a1=dependent_provider1, a2=dependent_provider2) provider_copy = providers.deepcopy(provider) dependent_provider_copy1 = provider_copy.kwargs['a1'] dependent_provider_copy2 = provider_copy.kwargs['a2'] self.assertNotEqual(provider.kwargs, provider_copy.kwargs) self.assertIs(dependent_provider1.cls, dependent_provider_copy1.cls) self.assertIsNot(dependent_provider1, dependent_provider_copy1) self.assertIs(dependent_provider2.cls, dependent_provider_copy2.cls) self.assertIsNot(dependent_provider2, dependent_provider_copy2)
def test_deepcopy_kwargs(): provider = providers.Resource(init_fn) dependent_provider1 = providers.Factory(list) dependent_provider2 = providers.Factory(dict) provider.add_kwargs(d1=dependent_provider1, d2=dependent_provider2) provider_copy = providers.deepcopy(provider) dependent_provider_copy1 = provider_copy.kwargs["d1"] dependent_provider_copy2 = provider_copy.kwargs["d2"] assert provider.kwargs != provider_copy.kwargs assert dependent_provider1.cls is dependent_provider_copy1.cls assert dependent_provider1 is not dependent_provider_copy1 assert dependent_provider2.cls is dependent_provider_copy2.cls assert dependent_provider2 is not dependent_provider_copy2
def test_deepcopy_kwargs(self): provider = providers.Resource(init_fn) dependent_provider1 = providers.Factory(list) dependent_provider2 = providers.Factory(dict) provider.add_kwargs(d1=dependent_provider1, d2=dependent_provider2) provider_copy = providers.deepcopy(provider) dependent_provider_copy1 = provider_copy.kwargs['d1'] dependent_provider_copy2 = provider_copy.kwargs['d2'] self.assertNotEqual(provider.kwargs, provider_copy.kwargs) self.assertIs(dependent_provider1.cls, dependent_provider_copy1.cls) self.assertIsNot(dependent_provider1, dependent_provider_copy1) self.assertIs(dependent_provider2.cls, dependent_provider_copy2.cls) self.assertIsNot(dependent_provider2, dependent_provider_copy2)
def test_deepcopy_attributes(singleton_cls): provider = singleton_cls(Example) dependent_provider1 = singleton_cls(list) dependent_provider2 = singleton_cls(dict) provider.add_attributes(a1=dependent_provider1, a2=dependent_provider2) provider_copy = providers.deepcopy(provider) dependent_provider_copy1 = provider_copy.attributes["a1"] dependent_provider_copy2 = provider_copy.attributes["a2"] assert provider.attributes != provider_copy.attributes assert dependent_provider1.cls is dependent_provider_copy1.cls assert dependent_provider1 is not dependent_provider_copy1 assert dependent_provider2.cls is dependent_provider_copy2.cls assert dependent_provider2 is not dependent_provider_copy2
def test_deepcopy_args(self): provider = providers.Factory(Example) dependent_provider1 = providers.Factory(list) dependent_provider2 = providers.Factory(dict) provider.add_args(dependent_provider1, dependent_provider2) provider_copy = providers.deepcopy(provider) dependent_provider_copy1 = provider_copy.args[0] dependent_provider_copy2 = provider_copy.args[1] self.assertNotEqual(provider.args, provider_copy.args) self.assertIs(dependent_provider1.cls, dependent_provider_copy1.cls) self.assertIsNot(dependent_provider1, dependent_provider_copy1) self.assertIs(dependent_provider2.cls, dependent_provider_copy2.cls) self.assertIsNot(dependent_provider2, dependent_provider_copy2)
def test_deepcopy(self): provider_copy = providers.deepcopy(self.factory_aggregate) self.assertIsNot(self.factory_aggregate, provider_copy) self.assertIsInstance(provider_copy, type(self.factory_aggregate)) self.assertIsNot(self.factory_aggregate.example_a, provider_copy.example_a) self.assertIsInstance(self.factory_aggregate.example_a, type(provider_copy.example_a)) self.assertIs(self.factory_aggregate.example_a.cls, provider_copy.example_a.cls) self.assertIsNot(self.factory_aggregate.example_b, provider_copy.example_b) self.assertIsInstance(self.factory_aggregate.example_b, type(provider_copy.example_b)) self.assertIs(self.factory_aggregate.example_b.cls, provider_copy.example_b.cls)
def test_deepcopy_with_non_string_keys(factory_aggregate): provider_copy = providers.deepcopy(factory_aggregate) assert factory_aggregate is not provider_copy assert isinstance(provider_copy, type(factory_aggregate)) assert factory_aggregate.factories[ ExampleA] is not provider_copy.factories[ExampleA] assert isinstance(factory_aggregate.factories[ExampleA], type(provider_copy.factories[ExampleA])) assert factory_aggregate.factories[ ExampleA].cls is provider_copy.factories[ExampleA].cls assert factory_aggregate.factories[ ExampleB] is not provider_copy.factories[ExampleB] assert isinstance(factory_aggregate.factories[ExampleB], type(provider_copy.factories[ExampleB])) assert factory_aggregate.factories[ ExampleB].cls is provider_copy.factories[ExampleB].cls
def test_deepcopy_kwargs_non_string_keys(self): a1 = object() a2 = object() dependent_provider1 = providers.Factory(list) dependent_provider2 = providers.Factory(dict) provider = providers.Dict({a1: dependent_provider1, a2: dependent_provider2}) provider_copy = providers.deepcopy(provider) dependent_provider_copy1 = provider_copy.kwargs[a1] dependent_provider_copy2 = provider_copy.kwargs[a2] self.assertNotEqual(provider.kwargs, provider_copy.kwargs) self.assertIs(dependent_provider1.cls, dependent_provider_copy1.cls) self.assertIsNot(dependent_provider1, dependent_provider_copy1) self.assertIs(dependent_provider2.cls, dependent_provider_copy2.cls) self.assertIsNot(dependent_provider2, dependent_provider_copy2)
def test_deepcopy_kwargs_non_string_keys(): a1 = object() a2 = object() dependent_provider1 = providers.Factory(list) dependent_provider2 = providers.Factory(dict) provider = providers.Dict({a1: dependent_provider1, a2: dependent_provider2}) provider_copy = providers.deepcopy(provider) dependent_provider_copy1 = provider_copy.kwargs[a1] dependent_provider_copy2 = provider_copy.kwargs[a2] assert provider.kwargs != provider_copy.kwargs assert dependent_provider1.cls is dependent_provider_copy1.cls assert dependent_provider1 is not dependent_provider_copy1 assert dependent_provider2.cls is dependent_provider_copy2.cls assert dependent_provider2 is not dependent_provider_copy2
def test_deepcopy_args(self): provider = providers.Callable(_example) dependent_provider1 = providers.Callable(list) dependent_provider2 = providers.Callable(dict) provider.add_args(dependent_provider1, dependent_provider2) provider_copy = providers.deepcopy(provider) dependent_provider_copy1 = provider_copy.args[0] dependent_provider_copy2 = provider_copy.args[1] self.assertNotEqual(provider.args, provider_copy.args) self.assertIs(dependent_provider1.provides, dependent_provider_copy1.provides) self.assertIsNot(dependent_provider1, dependent_provider_copy1) self.assertIs(dependent_provider2.provides, dependent_provider_copy2.provides) self.assertIsNot(dependent_provider2, dependent_provider_copy2)
def test_deepcopy_kwargs(self): provider = providers.Coroutine(_example) dependent_provider1 = providers.Callable(list) dependent_provider2 = providers.Callable(dict) provider.add_kwargs(a1=dependent_provider1, a2=dependent_provider2) provider_copy = providers.deepcopy(provider) dependent_provider_copy1 = provider_copy.kwargs['a1'] dependent_provider_copy2 = provider_copy.kwargs['a2'] self.assertNotEqual(provider.kwargs, provider_copy.kwargs) self.assertIs(dependent_provider1.provides, dependent_provider_copy1.provides) self.assertIsNot(dependent_provider1, dependent_provider_copy1) self.assertIs(dependent_provider2.provides, dependent_provider_copy2.provides) self.assertIsNot(dependent_provider2, dependent_provider_copy2)
def test_deepcopy_with_sys_streams(self): provider = providers.Selector( self.selector, stdin=providers.Object(sys.stdin), stdout=providers.Object(sys.stdout), stderr=providers.Object(sys.stderr), ) provider_copy = providers.deepcopy(provider) self.assertIsNot(provider, provider_copy) self.assertIsInstance(provider_copy, providers.Selector) with self.selector.override('stdin'): self.assertIs(provider(), sys.stdin) with self.selector.override('stdout'): self.assertIs(provider(), sys.stdout) with self.selector.override('stderr'): self.assertIs(provider(), sys.stderr)
def test_deepcopy(provider): provider_copy = providers.deepcopy(provider) assert provider is not provider_copy assert isinstance(provider, providers.Dependency)
def test_deepcopy_initialized(self): provider = providers.Resource(init_fn) provider.init() with self.assertRaises(errors.Error): providers.deepcopy(provider)
def test_deepcopy_from_memo(provider): provider_copy_memo = providers.Provider() provider_copy = providers.deepcopy(provider, memo={id(provider): provider_copy_memo}) assert provider_copy is provider_copy_memo
def test_deepcopy_initialized(): provider = providers.Resource(init_fn) provider.init() with raises(errors.Error): providers.deepcopy(provider)
def test_deepcopy_from_memo(config): config_copy_memo = providers.Configuration() provider_copy = providers.deepcopy(config, memo={id(config): config_copy_memo}) assert provider_copy is config_copy_memo
def test_deepcopy(self): provider = providers.Configuration('config') provider_copy = providers.deepcopy(provider) self.assertIsNot(provider, provider_copy) self.assertIsInstance(provider, providers.Configuration)
def test_deepcopy(config): config_copy = providers.deepcopy(config) assert isinstance(config_copy, providers.Configuration) assert config is not config_copy