Skip to content

[changes requested] Refactor cli_test.py and main_test.py#3828

Merged
ohemorange merged 25 commits intocertbot:masterfrom
cowlicks:gh-2716
Dec 5, 2016
Merged

[changes requested] Refactor cli_test.py and main_test.py#3828
ohemorange merged 25 commits intocertbot:masterfrom
cowlicks:gh-2716

Conversation

@cowlicks
Copy link
Contributor

This moves the tests in cli_test.py that used the certbot.main.main entrypoint to main_test.py. It also moves a lot of the other extraneous tests out of there.

It does not fully close #2716 because many of the tests now in main_test.py still use the same monolithic entrypoint, but it is a good step toward that.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 98.852% when pulling db406dd on cowlicks:gh-2716 into 7951ba7 on certbot:master.

@pde
Copy link
Member

pde commented Nov 29, 2016

This looks like heroic work!

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 98.85% when pulling edd26b0 on cowlicks:gh-2716 into 7951ba7 on certbot:master.

Copy link
Contributor

@ohemorange ohemorange left a comment

Choose a reason for hiding this comment

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

This PR is fantastic, great work!

There's a new file not_cli_test.py that's probably not supposed to be there.

self.assertFalse(self.init_func.called)

@mock.patch('certbot.main.sys')
def test_handle_exception(self, mock_sys):
Copy link
Contributor

Choose a reason for hiding this comment

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

It's confusing to me to have _handle_exception() defined in main.py but tested in error_handler_test.py. I don't know the history of why it's in main, but could we move it to error_handler.py to match the test?

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 looks like the purpose of error_handler.ErrorHandler is to handle clean up of stateful operations when there is an exception. But main._handle_exception is for logging tracebacks and displaying them to the user properly. So they are separate but sound similar.

I think it would be better to move this test into its own class in main_test.py.

Copy link
Contributor

Choose a reason for hiding this comment

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

Either way works for me, as long as they match.

self.assertEqual(result, (None, None))


class MainTest(unittest.TestCase): # pylint: disable=too-many-public-methods
Copy link
Contributor

Choose a reason for hiding this comment

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

How would you feel about having a BaseMainTest class that the different verb testers inherit from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds like a good strategy. But I think I will save breaking this into separate verb tests for another PR. This PR just gets the low hanging fruit, like the parsing tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good! I'll make you an issue for it.

import tempfile

from certbot import configuration
from certbot import renewal
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this into the method, just before calling _restore_webroot_config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it

return lambda cls: None


def make_lineage(self, testfile):
Copy link
Contributor

Choose a reason for hiding this comment

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

With this method in test_util, does DuplicativeCertsTest have to inherit from BaseRenewableCertTest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it looks like make_lineage can be used instead of inheriting from BaseRenewableCertTest. I'll try that this afternoon.

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 didn't finish this today, I'll take another look tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ohemorange, a few things for posterity, make_lineage creates as lineage based on any of the configuration files in certbot/tests/testdata/*.conf. While BaseRenewableCertTest makes a lineage (correct word?) on the fly, based on some parameters in its class definition. It would be nice to remove the dependency of BaseRenewableCertTest since it is imported from another test file.

After a few attempts I could not get the DuplicativeCertsTest tests to work using make_lineage. So I'll punt for now and make another issue.

@ohemorange
Copy link
Contributor

Oh also this is going to conflict with #3785, so let's try to get this one in.

@cowlicks
Copy link
Contributor Author

@pde @ohemorange I think I should rename test_util.py to util.py to avoid confusing with util_test.py. And the name information is already there in the import path certbot.tests.test_util. Any objections?

@ohemorange
Copy link
Contributor

Only reason I see to keep it is that we might then get some import certbot.tests.util as test_util to avoid conflicts with the other util. No strong opinion either way.

@cowlicks
Copy link
Contributor Author

@ohemorange cool, I'll probably have time to address your comments tomorrow morningish CST.

@pde pde assigned cowlicks and unassigned ohemorange Nov 30, 2016
@pde pde changed the title Refactor cli_test.py and main_test.py [changes requested] Refactor cli_test.py and main_test.py Nov 30, 2016
@pde
Copy link
Member

pde commented Dec 1, 2016

Kicking Travis

return functools.partial(cli.prepare_and_parse_args, plugins)

# why can't I remove this?
def test_option_was_set(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A lot of this refactoring expects that prepare_and_parse_args is stateless, but it actually has some global side effects which are tested here. Is there a better way to handle this state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. I just manually reset the state of set_by_cli in each test. This is way cheaper and faster than loading all the plugins and rebuilding the parser for each test.

@cowlicks cowlicks force-pushed the gh-2716 branch 2 times, most recently from 1b32cc1 to 47a78e5 Compare December 3, 2016 01:49
@cowlicks
Copy link
Contributor Author

cowlicks commented Dec 3, 2016

Rebased

@coveralls
Copy link

Coverage Status

Coverage increased (+0.001%) to 98.854% when pulling 47a78e5 on cowlicks:gh-2716 into da3332c on certbot:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.001%) to 98.854% when pulling 47a78e5 on cowlicks:gh-2716 into da3332c on certbot:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 98.842% when pulling f985cd8 on cowlicks:gh-2716 into da3332c on certbot:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.001%) to 98.854% when pulling f985cd8 on cowlicks:gh-2716 into da3332c on certbot:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.001%) to 98.854% when pulling 5d72e1a on cowlicks:gh-2716 into da3332c on certbot:master.

@cowlicks
Copy link
Contributor Author

cowlicks commented Dec 4, 2016

@ohemorange Anything else?

@ohemorange ohemorange merged commit 65d9e99 into certbot:master Dec 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split cli_tst.py?

4 participants