def test_setting_attributes(self): options = Options() options.hello = "world" # pylint: disable=assigning-non-slot options.a = "b" # pylint: disable=assigning-non-slot self.assertEqual(options.get("hello"), "world") self.assertEqual(options.get("a"), "b") self.assertEqual(options.__dict__, {"hello": "world", "a": "b"})
def test_overriding_instance_attributes(self): """Test that setting instance attributes and methods does not interfere with previously defined attributes and methods. This produces an inconsistency where >>> options = Options() >>> options.validators = "hello" >>> options.validators {} >>> options.get("validators") "hello" """ options = Options(get="a string") options.validator = "another string" setattr(options, "update_options", "not a method") options.update_options(_fields="not a dict") options.__dict__ = "also not a dict" self.assertEqual( options.__dict__, { "get": "a string", "validator": "another string", "update_options": "not a method", "_fields": "not a dict", "__dict__": "also not a dict", }, ) self.assertEqual( options._fields, { "get": "a string", "validator": "another string", "update_options": "not a method", "_fields": "not a dict", "__dict__": "also not a dict", }, ) self.assertEqual(options.validator, {}) self.assertEqual(options.get("_fields"), "not a dict")