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

Profile: formalize what constitutes a test profile #5392

Merged
merged 2 commits into from
Feb 25, 2022

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Feb 24, 2022

Fixes #5390

Up till now, a profile was defined as a test profile if its name started
with test_. However, this is neither very robust nor very flexible as
it restricts naming for profiles.

Here we make it more explicit by adding the key test_profile to all
profiles through a configuration migration. Profiles whose name starts
with test_ have test_profile set to True.

Profiles that have test_profile = True are considered a test profile
and so are allowed to be used in running the test suite. For safety
reasons, the Profile.is_test_profile property returns True if and
only if test_profile is set to True. If it is missing or any other
value is set, it returns False. This prevents a profile accidentally
being used for tests.

CLI: add --test-profile flag to verdi setup/quicksetup

This new flag allows to designate a new profile that is created to be a
test profile, which means it can be used to run the test suite.

Copy link
Member

@ramirezfranciscof ramirezfranciscof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me in general, I just have a couple of questions and I noticed a docstring that needs updating.

aiida/manage/configuration/migrations/migrations.py Outdated Show resolved Hide resolved
tests/manage/configuration/test_profile.py Outdated Show resolved Hide resolved
def test_migrate_full(load_config_sample, monkeypatch):
"""Test the full config migration."""
config_initial = load_config_sample('input/0.json')
monkeypatch.setattr(uuid, 'uuid4', lambda: uuid.UUID(hex='0' * 32))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? I assume it targets these lines, but I'm not sure why it is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the migration will generate a random UUID, but we are checking against a static reference file that has 0 * 32 as UUID. If we don't force the same UUID, the comparison and so test will fail

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm I see, thanks. I'm wondering if it makes sense to add a comment for this since we are not technically monkeypatching to isolate the module or to verify that the uuid lib is called, but just as a side-effect of how we do the tests, i.e. wanting to do direct reference file comparison (since if we were doing it manually migration by migration we would only to check that the 'PROFILE_UUID' keyword was added and not its content). Not sure how important it is to clarify this distinction though, so up to you, I'll approve either way.

tests/manage/configuration/migrations/test_migrations.py Outdated Show resolved Hide resolved
@ramirezfranciscof
Copy link
Member

Another general comment to think about: in this case you didn't actually change much in the tests so it was easy to review, but I did notice that if you had added any new tests to these or modified the behavior of old ones, it would have been much more difficult to review. This is because it is quite mentally costly to be changing from "just making sure the prior test and new tests do the same despite the (probably) big change in structure" vs "the new features are being correctly tested".

I know this might be a bit idealistic on my part, but perhaps we could try taking your request of "try to update the old tests as you need to add more to that file" and make a small addendum of "try to do the update as a separate PR prior to the one that introduces the changes".

@sphuber
Copy link
Contributor Author

sphuber commented Feb 25, 2022

Think that makes sense, at least for the reviewing process. We could definitely suggest that a first commit is added that modifies existing tests from old to new style, and then actual changes/additions come in a following commit. After review, we can then squash merge. Care needs to be taken if there are more than 1 commit that needs to be kept after merging, in which case we should manually interactively rebase to squash certain commits, before merging.

assert config_migrated == config_reference


@pytest.mark.parametrize('initial, target', (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could auto-generate the migrations to test, from the MIGRATIONS list.
That would "guard" against people forgetting to update it when adding new migrations
(I do similar with the psql migrations)

Copy link
Member

@chrisjsewell chrisjsewell Feb 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(made this comment earlier, but always forget that the github ios app adds comments as pending)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@chrisjsewell
Copy link
Member

We could definitely suggest that a first commit is added that modifies existing tests from old to new style

didn't actually notice that there were still some hold out unittest.TestCase, when I replaced all the AiidaTestCase.
but only a few to go

@sphuber sphuber requested a review from chrisjsewell February 25, 2022 11:36
Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cheers

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah sorry, one more change: tests/storage/psql_dos/migrations/conftest.py: uninitialised_profile yields a Profile for the migration tests (currently named test_migrate)

@sphuber sphuber force-pushed the fix/5390/formalize-test-profile branch from 7c3f7a1 to 2ccb1fd Compare February 25, 2022 12:57
@sphuber sphuber requested a review from chrisjsewell February 25, 2022 12:57
Up till now, a profile was defined as a test profile if its name started
with `test_`. However, this is neither very robust nor very flexible as
it restricts naming for profiles.

Here we make it more explicit by adding the key `test_profile` to all
profiles through a configuration migration. Profiles whose name starts
with `test_` have `test_profile` set to `True`.

Profiles that have `test_profile = True` are considered a test profile
and so are allowed to be used in running the test suite. For safety
reasons, the `Profile.is_test_profile` property returns `True` if and
only if `test_profile` is set to `True`. If it is missing or any other
value is set, it returns `False`. This prevents a profile accidentally
being used for tests.
This new flag allows to designate a new profile that is created to be a
test profile, which means it can be used to run the test suite.
@sphuber sphuber force-pushed the fix/5390/formalize-test-profile branch from 2ccb1fd to c8104da Compare February 25, 2022 13:19
profile_names = list(profiles.keys())

# Iterate over the fixed list of the profile names, since we are mutating the profiles dictionary.
for profile_name in profile_names:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I see you are still pushing changes, so ping me when you want the final review.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am done. Everything is addressed and commits are rebased

Copy link
Member

@ramirezfranciscof ramirezfranciscof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@aiidateam aiidateam deleted a comment from ramirezfranciscof Feb 25, 2022
@sphuber
Copy link
Contributor Author

sphuber commented Feb 25, 2022

@chrisjsewell you happy with this?

@sphuber sphuber merged commit e36f350 into aiidateam:develop Feb 25, 2022
@sphuber sphuber deleted the fix/5390/formalize-test-profile branch February 25, 2022 14:56
@chrisjsewell
Copy link
Member

chrisjsewell commented Feb 25, 2022

@chrisjsewell you happy with this?

yeh, just mentally preparing for more merge conflict in #5375 lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formalize the definition of a "test" profile
3 participants