We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
def test_mimic_property():
class MyMetadata:
def __init__(self) -> None:
self._metadata: str | None = 'metadata'
@Property
def metadata(self):
return self._metadata
@metadata.setter
def metadata(self, value: str | None):
self._metadata = value
if value is None:
raise ValueError('Not allowed to reset to None')
@metadata.deleter
self._metadata = None
raise ValueError('Not allowed to delete metadata')
model = Model[MyMetadata]()
assert model.metadata == 'metadata'
model.metadata = 'my metadata'
assert model.metadata == 'my metadata'
with pytest.raises(ValueError):
model.metadata = None
del model.metadata
omnipy/tests/data/test_model.py
Line 1384 in b64d59c
assert float(model) == 10 # float(), int(), etc always converts # TODO: Add support in Model for mimicking the setting and deletion of properties # def test_mimic_property(): # class MyMetadata: # def __init__(self) -> None: # self._metadata: str | None = 'metadata' # # @property # def metadata(self): # return self._metadata # # @metadata.setter # def metadata(self, value: str | None): # self._metadata = value # # if value is None: # raise ValueError('Not allowed to reset to None') # # @metadata.deleter # def metadata(self): # self._metadata = None # raise ValueError('Not allowed to delete metadata') # # # model = Model[MyMetadata]() # assert model.metadata == 'metadata' # # model.metadata = 'my metadata' # assert model.metadata == 'my metadata' # # with pytest.raises(ValueError): # model.metadata = None # # assert model.metadata == 'my metadata' # # with pytest.raises(ValueError): # del model.metadata # assert model.metadata == 'my metadata' def test_mimic_callable_property(): # Example of previously failing callable property is pandas.DataFrame.loc class MyCallable: def __init__(self): self.called = False def __call__(self): self.called = True class MyCallableHolder: def __init__(self) -> None: self._func: Callable = MyCallable() @property def func(self) -> Callable: return self._func model = Model[MyCallableHolder]() assert model.func.called is False def test_model_copy(): ...
The text was updated successfully, but these errors were encountered:
No branches or pull requests
def test_mimic_property():
class MyMetadata:
def __init__(self) -> None:
self._metadata: str | None = 'metadata'
@Property
def metadata(self):
return self._metadata
@metadata.setter
def metadata(self, value: str | None):
self._metadata = value
if value is None:
raise ValueError('Not allowed to reset to None')
@metadata.deleter
def metadata(self):
self._metadata = None
raise ValueError('Not allowed to delete metadata')
model = Model[MyMetadata]()
assert model.metadata == 'metadata'
model.metadata = 'my metadata'
assert model.metadata == 'my metadata'
with pytest.raises(ValueError):
model.metadata = None
assert model.metadata == 'my metadata'
with pytest.raises(ValueError):
del model.metadata
assert model.metadata == 'my metadata'
omnipy/tests/data/test_model.py
Line 1384 in b64d59c
The text was updated successfully, but these errors were encountered: