def test_construction_and_basic_access() -> None: # pylint: disable=unidiomatic-typecheck the_shared_settings = {"somenumber": 10, "somestring": "abc"} the_theme = WebvizConfigTheme("dummyThemeName") settings_obj = WebvizSettings(the_shared_settings, the_theme) copy_of_shared_settings = settings_obj.shared_settings assert copy_of_shared_settings is not the_shared_settings assert type(copy_of_shared_settings) == type(the_shared_settings) assert copy_of_shared_settings == the_shared_settings the_shared_settings["somestring"] = "MODIFIED" assert copy_of_shared_settings != the_shared_settings copy_of_theme = settings_obj.theme assert copy_of_theme is not the_theme assert type(copy_of_theme) == type(the_theme) assert copy_of_theme.__dict__ == the_theme.__dict__ the_theme.theme_name = "MODIFIED" assert copy_of_theme.__dict__ != the_theme.__dict__
def test_immutability() -> None: my_dash_app = Dash("dummyAppName") my_run_mode = WebvizRunMode.NON_PORTABLE my_theme = WebvizConfigTheme("dummyThemeName") my_storage_folder = Path("dummyPath") instance_info = WebvizInstanceInfo() instance_info.initialize( dash_app=my_dash_app, run_mode=my_run_mode, theme=my_theme, storage_folder=my_storage_folder, ) # Ony allowed to initialize once with pytest.raises(RuntimeError): instance_info.initialize( dash_app=my_dash_app, run_mode=my_run_mode, theme=my_theme, storage_folder=my_storage_folder, ) # This is ok and necessary since we want to share the actual dash app assert instance_info.dash_app is my_dash_app # This two are also ok since integer enums and Path themselves is immutable assert instance_info.run_mode is my_run_mode assert instance_info.storage_folder is my_storage_folder returned_theme = instance_info.theme assert returned_theme is not my_theme assert isinstance(returned_theme, WebvizConfigTheme) assert returned_theme.__dict__ == my_theme.__dict__ my_theme.theme_name = "MODIFIED" assert returned_theme.__dict__ != my_theme.__dict__ with pytest.raises(AttributeError): # pylint: disable=assigning-non-slot instance_info.some_new_attribute = "myAttributeValue" # type: ignore[attr-defined]