From b0af872a40eb3a51ab42780a5d6fac7951b0999e Mon Sep 17 00:00:00 2001 From: Evaline Ju <69598118+evaline-ju@users.noreply.github.com> Date: Tue, 25 Apr 2023 10:38:07 -0600 Subject: [PATCH] :goal_net::white_check_mark: Type error for setitem Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com> --- aconfig/aconfig.py | 2 +- test/test_attribute_access_dict.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/aconfig/aconfig.py b/aconfig/aconfig.py index 68b02d9..ae021da 100644 --- a/aconfig/aconfig.py +++ b/aconfig/aconfig.py @@ -110,7 +110,7 @@ def __init__(self, input_map, *_): super().__init__(input_map) def __setitem__(self, key, value): - raise AttributeError("ImmutableAttributeAccessDict does not support attribute assignment") + raise TypeError("ImmutableAttributeAccessDict does not support item assignment") def __setattr__(self, key, value): raise AttributeError("ImmutableAttributeAccessDict does not support attribute assignment") diff --git a/test/test_attribute_access_dict.py b/test/test_attribute_access_dict.py index 3a5b100..1d95500 100644 --- a/test/test_attribute_access_dict.py +++ b/test/test_attribute_access_dict.py @@ -220,7 +220,7 @@ def test_immutable_flat_access_dict(self): flat_dict = aconfig.ImmutableAttributeAccessDict(fixtures.GOOD_FLAT_DICT) self.assertIsInstance(flat_dict, aconfig.AttributeAccessDict) - with self.assertRaises(AttributeError): + with self.assertRaises(TypeError): flat_dict['str_key'] = 'new_key' def test_immutable_nested_access_dict(self): @@ -229,5 +229,14 @@ def test_immutable_nested_access_dict(self): flat_dict = aconfig.ImmutableAttributeAccessDict(fixtures.GOOD_NESTED_DICT) self.assertIsInstance(flat_dict, aconfig.AttributeAccessDict) - with self.assertRaises(AttributeError): + with self.assertRaises(TypeError): flat_dict['key2']['key4'] = 'new_key' + + def test_immutable_dict_attr(self): + '''Test that immutable dict cannot be changed via attribute + ''' + flat_dict = aconfig.ImmutableAttributeAccessDict(fixtures.GOOD_FLAT_DICT) + self.assertIsInstance(flat_dict, aconfig.AttributeAccessDict) + + with self.assertRaises(AttributeError): + flat_dict.str_key = 'new_key'