Support for mutable and immutable configurations
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from src.config_parser import Configuration
|
||||
from src.config_parser import Configuration, set_mutability, is_mutable
|
||||
|
||||
def test_crud_configuration_attrs():
|
||||
config = Configuration()
|
||||
@@ -76,4 +76,37 @@ def test_crud_configuration_config_items():
|
||||
config.key1
|
||||
assert False, "AttributeError was not raised"
|
||||
except AttributeError:
|
||||
pass
|
||||
pass
|
||||
|
||||
def test_mutability():
|
||||
config = Configuration(mutable=False)
|
||||
try:
|
||||
config.key = 'value'
|
||||
assert False, 'Expected TypeError'
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
set_mutability(config, True)
|
||||
assert config._mutable == True
|
||||
|
||||
config.key = 'value'
|
||||
|
||||
set_mutability(config, False)
|
||||
assert config._mutable == False
|
||||
assert is_mutable(config) == False
|
||||
|
||||
try:
|
||||
del config.key
|
||||
assert False, 'Expected TypeError'
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
|
||||
# Test operate_on_original_object parameter of set_mutability
|
||||
config = Configuration(mutable = True)
|
||||
set_mutability(config, False, operate_on_original_object = True)
|
||||
assert is_mutable(config) == False
|
||||
|
||||
new_config = set_mutability(config, True, operate_on_original_object = False)
|
||||
assert is_mutable(new_config) == True
|
||||
assert is_mutable(config) == False
|
||||
Reference in New Issue
Block a user