You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# TODO: Revisit test_mimic_object_member_not_in_class_known_issue() is mimicking of __setattr__ is
assertmodel.func.calledisFalse# TODO: Revisit test_mimic_object_member_not_in_class_known_issue() is mimicking of __setattr__ is# implemented. Libraries like Pandas might also graft methods onto instances such as# DataFrames, which will not currently work with Omnipy. Dynamically added member variables# that are not bound methods do work, however.@pytest.mark.skipif(os.getenv('OMNIPY_FORCE_SKIPPED_TEST') !='1',reason="""Known issue due to validation of the model contents before the calling of the method wheninteractive_mode is set to True. Since the method is grafted onto the specific model instance, itis bound to that instance only. However, validation shallow-copies the instance, including themethod, but does not rebind the method to the new instance. The result is that the method iscalled on the old instance, and not the new one.Conclusion: avoid grafting methods onto models instances. Dynamically grafting methods is in anycase an advanced operation and does not follow Python best practices. Grafting instance variablesor unbound methods should work as expected, see test_mimic_dynamically_bound_instance_variable.""")deftest_mimic_dynamically_bound_instance_method_known_issue(
runtime: Annotated[IsRuntime, pytest.fixture]) ->None:
classMyClass:
def__init__(self) ->None:
self.called=Falsemy_obj=MyClass()
my_obj.method=MethodType( # type: ignore[attr-defined]lambdaself: setattr(self, 'called', True), my_obj)
model=Model[MyClass](my_obj)
assertmodel.calledisFalsemodel.method()
ifruntime.config.data.interactive_mode:
assert (my_obj.called, model.called) == (False, True)
else:
assert (my_obj.called, model.called) == (True, True)
deftest_mimic_dynamically_bound_instance_variable(
runtime: Annotated[IsRuntime, pytest.fixture]) ->None:
classMyClass:
deftoggle_if_available(self) ->None:
ifhasattr(self, 'toggle'):
self.toggle=notself.toggle# type: ignore[has-type]my_obj=MyClass()
my_obj.toggle=Falsemodel=Model[MyClass](my_obj)
assertmodel.toggleisFalsemodel.toggle_if_available()
ifruntime.config.data.interactive_mode:
assert (my_obj.toggle, model.toggle) == (False, True)
else:
assert (my_obj.toggle, model.toggle) == (True, True)
deftest_literal_model_defaults() ->None:
assertLiteralFiveModel().to_data() ==5assertLiteralFiveModel().outer_type(with_args=True) isLiteral[5]
The text was updated successfully, but these errors were encountered:
implemented. Libraries like Pandas might also graft methods onto instances such as
DataFrames, which will not currently work with Omnipy. Dynamically added member variables
that are not bound methods do work, however.
omnipy/tests/data/test_model.py
Line 3788 in 86e1ee9
The text was updated successfully, but these errors were encountered: