| 1 |  |  | import pytest | 
            
                                                        
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 4 |  |  | @pytest.fixture | 
            
                                                        
            
                                    
            
            
                | 5 |  |  | def registry_infra(): | 
            
                                                        
            
                                    
            
            
                | 6 |  |  |     from so_magic.utils import ObjectRegistry, ObjectRegistryError | 
            
                                                        
            
                                    
            
            
                | 7 |  |  |     return type('DummyClass', (object,), {'object': ObjectRegistry({'key1': 1}), 'error': ObjectRegistryError, | 
            
                                                        
            
                                    
            
            
                | 8 |  |  |                                           'existing_key': 'key1', 'non_existing_key': 'key2'}) | 
            
                                                        
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 11 |  |  | def test_registry_remove_method(registry_infra): | 
            
                                                        
            
                                    
            
            
                | 12 |  |  |     assert registry_infra.existing_key in registry_infra.object | 
            
                                                        
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 14 |  |  |     registry_infra.object.remove(registry_infra.existing_key) | 
            
                                                        
            
                                    
            
            
                | 15 |  |  |     assert registry_infra.object.objects == {} | 
            
                                                        
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 17 |  |  |     with pytest.raises(registry_infra.error, | 
            
                                                        
            
                                    
            
            
                | 18 |  |  |                        match=f'Requested to remove item with key {registry_infra.existing_key}, which does not exist.'): | 
            
                                                        
            
                                    
            
            
                | 19 |  |  |         registry_infra.object.remove(registry_infra.existing_key) | 
            
                                                        
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 22 |  |  | def test_registry_pop_method(registry_infra): | 
            
                                                        
            
                                    
            
            
                | 23 |  |  |     assert registry_infra.existing_key in registry_infra.object | 
            
                                                        
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 25 |  |  |     value = registry_infra.object.pop(registry_infra.existing_key) | 
            
                                                        
            
                                    
            
            
                | 26 |  |  |     assert value == 1 | 
            
                                                        
            
                                    
            
            
                | 27 |  |  |     assert registry_infra.object.objects == {} | 
            
                                                        
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 29 |  |  |     with pytest.raises(registry_infra.error, | 
            
                                                        
            
                                    
            
            
                | 30 |  |  |                        match=f'Requested to pop item with key {registry_infra.existing_key}, which does not exist.'): | 
            
                                                        
            
                                    
            
            
                | 31 |  |  |         registry_infra.object.pop(registry_infra.existing_key) | 
            
                                                        
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 34 |  |  | def test_registry_get_method(registry_infra): | 
            
                                                        
            
                                    
            
            
                | 35 |  |  |     assert registry_infra.existing_key in registry_infra.object | 
            
                                                        
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 37 |  |  |     value = registry_infra.object.get(registry_infra.existing_key) | 
            
                                                        
            
                                    
            
            
                | 38 |  |  |     assert value == 1 | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |     assert registry_infra.object.objects == {registry_infra.existing_key: 1} | 
            
                                                        
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |     with pytest.raises(registry_infra.error, match=f'Requested to get item with key {registry_infra.non_existing_key}, ' | 
            
                                                        
            
                                    
            
            
                | 42 |  |  |                                                    f'which does not exist.'): | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |         _ = registry_infra.object.get(registry_infra.non_existing_key) | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |  |