From 93c8bd64382aba6372a91c64c081b66782214f62 Mon Sep 17 00:00:00 2001 From: Roman Mogilatov Date: Thu, 10 Nov 2016 21:00:23 +0200 Subject: [PATCH] Add tests for injections --- tests/unit/providers/test_injections.py | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/unit/providers/test_injections.py b/tests/unit/providers/test_injections.py index 8b557371..c1514abe 100644 --- a/tests/unit/providers/test_injections.py +++ b/tests/unit/providers/test_injections.py @@ -30,6 +30,28 @@ class PositionalInjectionTests(unittest.TestCase): injection = providers.PositionalInjection(provider) self.assertIs(injection.get_original_value(), provider) + def test_deepcopy(self): + provider = providers.Factory(object) + injection = providers.PositionalInjection(provider) + + injection_copy = providers.deepcopy(injection) + + self.assertIsNot(injection_copy, injection) + self.assertIsNot(injection_copy.get_original_value(), + injection.get_original_value()) + + def test_deepcopy_memo(self): + provider = providers.Factory(object) + injection = providers.PositionalInjection(provider) + injection_copy_orig = providers.PositionalInjection(provider) + + injection_copy = providers.deepcopy( + injection, {id(injection): injection_copy_orig}) + + self.assertIs(injection_copy, injection_copy_orig) + self.assertIs(injection_copy.get_original_value(), + injection.get_original_value()) + class NamedInjectionTests(unittest.TestCase): @@ -60,3 +82,25 @@ class NamedInjectionTests(unittest.TestCase): provider = providers.Factory(object) injection = providers.NamedInjection('name', provider) self.assertIs(injection.get_original_value(), provider) + + def test_deepcopy(self): + provider = providers.Factory(object) + injection = providers.NamedInjection('name', provider) + + injection_copy = providers.deepcopy(injection) + + self.assertIsNot(injection_copy, injection) + self.assertIsNot(injection_copy.get_original_value(), + injection.get_original_value()) + + def test_deepcopy_memo(self): + provider = providers.Factory(object) + injection = providers.NamedInjection('name', provider) + injection_copy_orig = providers.NamedInjection('name', provider) + + injection_copy = providers.deepcopy( + injection, {id(injection): injection_copy_orig}) + + self.assertIs(injection_copy, injection_copy_orig) + self.assertIs(injection_copy.get_original_value(), + injection.get_original_value())