-
Notifications
You must be signed in to change notification settings - Fork 117
[feat] Improve access to the namespaces of both parameter and variable built-ins #1819
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
[feat] Improve access to the namespaces of both parameter and variable built-ins #1819
Conversation
|
Hello @jjotero, Thank you for updating! Cheers! There are no PEP8 issues in this Pull Request!Do see the ReFrame Coding Style Guide Comment last updated at 2021-03-16 20:26:19 UTC |
Codecov Report
@@ Coverage Diff @@
## master #1819 +/- ##
==========================================
- Coverage 87.61% 86.08% -1.53%
==========================================
Files 49 49
Lines 8136 8378 +242
==========================================
+ Hits 7128 7212 +84
- Misses 1008 1166 +158
Continue to review full report at Codecov.
|
|
Variables now behave like regular python class attributes and multiple modifications within the same class body are now allowed. For example: class Foo:
pass
class MyTest(rfm.RegressionTest):
v = variable(Foo, value=Foo())
v.var_attribute = 'my attribute'
# Override a regular attribute with a variable
a = 4
a = variable(int, value=40)
print(a+1) # Prints 41
# Modify an existing var
a *= 10 # variable a is now 400
# Initialize a variable as a function of another variable
b = variable(float, value=a/3.141592)
def __init__(self):
print(self.v.var_attribute) # This prints 'my attribute'
|
|
Also coverage is a bit unhappy with the fact that none of the special functions are tested. I would add a small test test exercising all operators. |
vkarak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One problem that I see, which would help a lot in eliminating the need for a defining a constructor is that currently you can't use in an expression a built-in that was defined in a base class. Look at this?
class Base(rfm.RegressionTest):
foo = variable(str, value='hello')
@rfm.simple_test
class HelloTest2(Base):
descr = 'C Hello World test ' + foo
valid_systems = ['*']
valid_prog_environs = ['*']
sourcepath = 'hello.c'
tags = {'foo', 'bar'}
sanity_patterns = sn.assert_found(r'Hello, World\!', 'foo.txt')
maintainers = ['VK']This will complain about foo in the HelloTest2 definition. I am wondering whether this ca be fixed or not?
jjotero
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a few more unit tests covering the variable operators and the other issues mentioned in the PR review.
jjotero
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One problem that I see, which would help a lot in eliminating the need for a defining a constructor is that currently you can't use in an expression a built-in that was defined in a base class.
This is standard Python behaviour, isn't it? I have a few ideas to extend this behaviour. Let me do some "exploring" :)
Yes, looks like that. It seems that a |
vkarak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm, I have only a couple of minor style comments.
vkarak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Rather than customising the test attribute access using the
__getattribute__method, this PR moves this customisation into the__getattr__method instead, which is called when the default__getattribute__raises anAttributeError.This PR also makes the variable and parameter spaces behave as proper namespaces, which makes operations such as testing if a variable has been declared and so on more intuitive:
instead of
However, adding new items into the variable or parameter spaces is disallowed:
The corresponding unit tests have been added.
Closes #1841.