Skip to content
New issue

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

test/attr_tests: fix tests with setattr #482

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/attr_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def attribute_single_value_boolean(uri, classname, attr, value):
Value to write and read back from attribute
"""
bi = eval(classname + "(uri='" + uri + "')")

if not hasattr(bi, attr):
raise AttributeError(f"no attribute named: {attr}")

setattr(bi, attr, value)
rval = getattr(bi, attr)
del bi
Expand Down Expand Up @@ -258,6 +262,10 @@ def attribute_write_only_str(uri, classname, attr, value):
Value to write into attr property
"""
sdr = eval(classname + "(uri='" + uri + "')")

if not hasattr(sdr, attr):
raise AttributeError(f"no attribute named: {attr}")

try:
setattr(sdr, attr, value)
del sdr
Expand All @@ -284,6 +292,14 @@ def attribute_write_only_str_with_depends(uri, classname, attr, value, depends):
are properties and values are values to be written
"""
sdr = eval(classname + "(uri='" + uri + "')")

for p in depends:
if not hasattr(sdr, p):
raise AttributeError(f"no attribute named: {p}")

if not hasattr(sdr, attr):
raise AttributeError(f"no attribute named: {attr}")

for p in depends:
setattr(sdr, p, depends[p])
try:
Expand Down