Best Python code snippet using responses
test_registry.py
Source:test_registry.py  
...18    def get_registries(self):19        return get_registries()20    def add_registry(self, name=None):21        return add_registry(name or self.registry_name)22    def get_registry(self, name=None):23        return get_registry(name or self.registry_name)24class TestRegistries(RegistryTestCase):25    def test_get_registry_creates_registry(self):26        self.assertNotIn(self.registry_name, self.get_registries())27        registry = self.get_registry()28        self.assertIn(self.registry_name, self.get_registries())29        self.assertIsInstance(registry, Registry)30    def test_getting_the_same_registry_multiple_times_returns_the_same_registry(self):31        registries = get_registries()32        self.assertNotIn(self.registry_name, registries)33        registry = self.get_registry()34        self.assertIs(self.get_registry(), registry)35    def test_adding_a_registry_with_the_name_of_an_existing_registry_replaces_the_original(self):36        registries = get_registries()37        self.assertNotIn(self.registry_name, registries)38        registry = self.add_registry(self.registry_name)39        self.assertIsNot(self.add_registry(self.registry_name), registry)40class TestRegistry(RegistryTestCase):41    def test_components_must_be_registered_as_types(self):42        registry = self.get_registry()43        component = object()44        self.assertRaises(TypeError, registry.add_component, component, 'key')45    def test_adding_a_component_returns_the_component(self):46        registry = self.get_registry()47        Base = type('Base', (), {})48        Type = type('Type', (Base,), {})49        instance = Type()50        component = registry.add_component(instance, Type)51        self.assertIs(component, instance)52    def test_replacing_a_component_removes_it_and_adds_and_returns_the_new_component(self):53        registry = self.get_registry()54        instance_1 = object()55        registry[object] = instance_156        self.assertIs(registry[object], instance_1)57        instance_2 = object()58        registry.add_component(instance_2, object, replace=True)59        self.assertIs(registry[object], instance_2)60    def test_adding_the_same_component_twice_with_same_key_causes_an_error(self):61        registry = self.get_registry()62        Type = type('Type', (), {})63        instance = Type()64        registry.add_component(instance, Type)65        self.assertRaises(ComponentExistsError, registry.add_component, instance, Type)66    def test_removing_a_component_removes_and_returns_the_component(self):67        registry = self.get_registry()68        components = registry._components69        Type = type('Type', (), {})70        component = Type()71        self.assertNotIn(RegistryKey(Type), components)72        self.assertNotIn(Type, registry)73        registry[Type] = component74        self.assertIn(RegistryKey(Type), components)75        self.assertIn(Type, registry)76        obj = registry.remove_component(Type)77        self.assertIs(obj, component)78        self.assertNotIn(RegistryKey(Type), components)79        self.assertNotIn(Type, registry)80    def test_removing_a_nonexistent_component_raises_an_error(self):81        registry = self.get_registry()82        self.assertRaises(ComponentDoesNotExistError, registry.remove_component, object)83    def test_removing_a_nonexistent_component_returns_passed_default(self):84        registry = self.get_registry()85        default = object()86        component = registry.remove_component(object, default=default)87        self.assertIs(component, default)88    def test_removing_a_component_using_dict_syntax(self):89        registry = self.get_registry()90        self.assertNotIn(object, registry)91        registry[object] = object()92        self.assertIn(object, registry)93        del registry[object]94        self.assertNotIn(object, registry)95    def test_register_under_subclass(self):96        registry = self.get_registry()97        Base = type('Base', (), {})98        Type = type('Type', (Base,), {})99        instance = Type()100        # Register under subclass101        added = registry.add_component(instance, Type)102        self.assertTrue(added)103        # Fetch using subclass104        component = registry.get_component(Type)105        self.assertIs(component, instance)106        # Fetch using base class107        component = registry.get_component(Base)108        self.assertIs(component, instance)109    def test_register_under_subclass_with_name(self):110        registry = self.get_registry()111        Base = type('Base', (), {})112        Type = type('Type', (Base,), {})113        instance = Type()114        # Register under subclass with name115        added = registry.add_component(instance, Type, 'name')116        self.assertTrue(added)117        # Fetch using subclass118        component = registry.get_component(Type, 'name')119        self.assertIs(component, instance)120        # Fetch using base class121        component = registry.get_component(Base, 'name')122        self.assertIs(component, instance)123        # Name is required124        component = registry.get_component(Base)125        self.assertIsNone(component)126    def test_dict_style_access(self):127        registry = get_registry()128        Type = type('Type', (), {})129        instance = Type()130        registry[Type] = instance131        self.assertIn(Type, registry)132        self.assertIs(registry[Type], instance)133        registry[(Type, 'alt')] = instance134        self.assertIn((Type, 'alt'), registry)135        self.assertIs(registry[(Type, 'alt')], instance)136    def test_add_factory(self):137        registry = get_registry()138        Type = type('Type', (), {})139        component = Type()140        factory = lambda: component141        registry.add_factory(factory, Type)142        component_factory = registry._components[RegistryKey(Type)]143        self.assertIsInstance(component_factory, ComponentFactory)144        self.assertIs(component_factory.factory, factory)145        retrieved_component = registry.get_component(Type)...load.py
Source:load.py  
...13    # create database14    db.query('CREATE DATABASE IF NOT EXISTS trin_report;')15    load_registry()16    # set character set of database17    r.get_registry()['MY_SQL'].query(18        'ALTER DATABASE trin_report CHARACTER SET '19        'utf8 COLLATE utf8_general_ci;'20    )21    # create all database tables22    r.get_registry()['USER'].create_table()23    r.get_registry()['EMERGENCY'].create_table()24    r.get_registry()['ADMIN'].create_table()25    r.get_registry()['REPORT'].create_table()26    r.get_registry()['MESSAGE_ADMIN'].create_table()27    r.get_registry()['MESSAGE_USER'].create_table()28    r.get_registry()['IMAGE'].create_table()29if __name__ == "__main__":...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
