-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add ability to define DLRN driver in INI config file #32
base: master
Are you sure you want to change the base?
Conversation
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.
Thank you for the patch. Could you clarify a little bit the background for the change, maybe in the commit message?
Additionally, it would be good to add a unit test or two to show that the new driver value gets picked up where expected, and that the changes are transparent/backwards-compatible otherwise. Some of the unit tests data fixtures need to be updated with the new config value, although it would be good to also have a test where it's still missing anyway to prove that the patch_rebaser.py will be backward compatible. Thanks!
(I think some of the Python versions that failed with "Cancelled" are no longer maintained, I'll see about cleaning up the test matrix, although if you happen to have a few spare cycles to do it in a separate PR (updating tox, github actions should cover it I think), that would be super helpful!)
Moving to actions/checkout v4 to clean warning message due to [1]. We also add coverage of py3.12, and remove py3.7 and 3.8 coverage. [1] https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/
Currently, the patch_rebaser script only gets parameter from 'downstream_driver' section of the DLRN projects.ini file, which is hardcoded [1]. This patch aims to add support of defining the driver, thus the INI section, where we want to get the 'downstream_distro_branch' value. We set 'downstream_driver' as default value for 'dlrn_driver' key. [1] https://github.com/release-depot/patch_rebaser/blob/d81ca9a64acb6c0b8638373c3aea2ca15e796a77/patch_rebaser/patch_rebaser.py#L76
I updated the check jobs in first commit. |
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.
Sorry for the delay and thank you for the updated commit message. This is really helpful and now I understand better what we are trying to do (so hopefully reviews won't take as long!)
This needs a rebase, as someone fixed the CI issues in all of our repos so the .github/workflows stuff was fixed separately.
I would like to see a couple of new unit tests proving the new behaviour and to help us avoid regressions in the future. I made a couple of suggestions inline and hope the examples are helpful!
@@ -319,7 +321,9 @@ def test_get_rebaser_config_defaults_dont_override_ini_values(mock_config): | |||
AND an option exists both in the ini config and the defaults dictionary | |||
THEN the value from the ini config is returned | |||
""" | |||
defaults = {'git_name': 'TEST', 'remote_name': 'Wrong_name'} | |||
defaults = {'git_name': 'TEST', | |||
'dlrn_driver': 'downstream_driver', |
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 don't think we need this change here since we're only testing a subset of defaults anyway.
defaults = {'git_name': 'TEST', 'remote_name': 'Wrong_name'} | ||
defaults = {'git_name': 'TEST', | ||
'dlrn_driver': 'downstream_driver', | ||
'remote_name': 'Wrong_name'} | ||
config = get_rebaser_config(defaults) | ||
|
||
assert config.remote_name == "test_remote_name" |
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.
GitHub won't let me comment directly below, but you can see test_main_function just under here. I think it could be modified slightly to prove we still get the driver we expect, something like this:
repo = MagicMock()
+ mock_get_patches_branch = Mock(return_value=branch_name)
with monkeypatch.context() as m:
m.setattr(patch_rebaser.patch_rebaser, 'GitRepo',
Mock(return_value=repo))
m.setattr(patch_rebaser.patch_rebaser, 'get_patches_repo', Mock())
m.setattr(patch_rebaser.patch_rebaser, 'get_patches_branch',
- Mock(return_value=branch_name))
+ mock_get_patches_branch)
main()
+ mock_get_patches_branch.assert_called_with(mock.ANY, mock.ANY, mock.ANY, "downstream_driver")
then you could have a separate test to show what happens with the custom configuration, using a new test config file that has a custom dlrn_driver set. This would help us make sure we don't accidentally add regressions related to using custom drivers in the future. conftest.py has a couple of examples of custom test config already. It might look something like this:
def test_main_with_custom_driver(monkeypatch, mock_env, mock_custom_driver_config):
"""
GIVEN ...
WHEN ...
THEN ...
"""
mock_get_patches_branch = Mock()
monkeypatch.setattr(patch_rebaser.patch_rebaser, 'get_patches_branch', mock_get_patches_branch)
# Set up
monkeypatch.setattr(patch_rebaser.patch_rebaser, 'GitRepo', Mock(return_value=MagicMock()))
monkeypatch.setattr(patch_rebaser.patch_rebaser, 'get_patches_repo', Mock())
monkeypatch.setattr(patch_rebaser.patch_rebaser, 'get_release_from_branch_name', Mock())
monkeypatch.setattr(patch_rebaser.patch_rebaser, 'Rebaser', Mock())
# Test
main()
# Check
mock_get_patches_branch.assert_called_with(mock.ANY, mock.ANY, mock.ANY, "my_custom_driver")
If you prefer, you could also test for the default driver this way (using mock_config instead of your new mock_custom_driver_config) instead of modifying the other test for the main function.
We set 'downstream_driver' as default value for 'driver' key.