-
Notifications
You must be signed in to change notification settings - Fork 203
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
allow to directly import constants from easybuild.framework.easyconfig.constants #4144
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1278,6 +1278,17 @@ def test_constant_doc(self): | |
] | ||
self.assertEqual(len(doc.split('\n')), sum([len(temps)] + [len(x) for x in temps])) | ||
|
||
def test_constants_import(self): | ||
"""Test importing constants works""" | ||
# Sanity check that importing an EC constant works as-if using EASYCONFIG_CONSTANTS | ||
from easybuild.framework.easyconfig.constants import SYSTEM | ||
self.assertEqual(SYSTEM, easyconfig.constants.EASYCONFIG_CONSTANTS['SYSTEM'][0]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For self.assertEqual(SYSTEM, {'name': 'system', 'version': 'system'}) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But that is not what is tested here. Only importing the constants should be tested here and that means that doing such an explicit import is the same as accessing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not saying you should not do the explicit import, you should. I'm saying you should compare the value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Erm, This is exactly what you want, don't you?
So I don't understand why the test shouldn't pass when Additionally I really dislike using hardcoded values as this results in unrelated tests failing. This was e.g. the case where a spelling fix to a doc caused another test to fail: #3219 -> #4158 So if some previously run other test for any reason changed the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I consider a change to the value of a constant a breaking change, so tests should fail because of it. Although no code should be relying on the value of the constant, it's not unlikely that some stuff does, and hence the value of the constant should never be changed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ok understood. But I wouldn't do that here as that is not the purpose of the test: "importing an EC constant works as-if using EASYCONFIG_CONSTANTS". I split the test into 2 where the 2nd ensures exactly that and the first is more like what a user would do and uses the hard-coded value. I'm still not a fan of doing that for the mentioned reason and would rather have dedicated tests to catch constant changes that shouldn't change or just say that the purpose of the constant is that the value does not matter so anything relying on it is a bug anyway. |
||
# Check each individual constant | ||
constants = __import__('easybuild.framework.easyconfig.constants', fromlist=[None]) | ||
for name, (value, _doc) in easyconfig.constants.EASYCONFIG_CONSTANTS.items(): | ||
self.assertTrue(hasattr(constants, name), 'Missing ' + name) | ||
self.assertEqual(getattr(constants, name), value) | ||
|
||
def test_build_options(self): | ||
"""Test configure/build/install options, both strings and lists.""" | ||
orig_contents = '\n'.join([ | ||
|
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.
Hmm, does
__all__.extend(list(EASYCONFIG_CONSTANTS.keys())
work too?Just to make sure we don't overlooked adding stuff to
all
if additional (real) constants are added toconstants.py
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 tested that and no.
__all__
has a default value if it is not set (only), so at that point it is an undefined variable.It actually isn't really required because (almost) nobody does
from easyconfig.constants import *
which is the only use case of__all__
, everything else works without it.