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

#8478 Document testing deprecated modules. #11971

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from

Conversation

adiroiban
Copy link
Member

@adiroiban adiroiban commented Sep 8, 2023

Scope and purpose

Fixes #8478

This document how to test deprecated modules.

it also contains a few changes from a very old branch 7 years old - https://github.com/twisted/twisted/tree/8478-deprecated-class-test

docs at https://twisted--11971.org.readthedocs.build/en/11971/development/compatibility-policy.html#testing-deprecation-code

@adiroiban
Copy link
Member Author

needs-review

Copy link
Contributor

@twm twm left a comment

Choose a reason for hiding this comment

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

Please at least fix the syntax error, but the rest is at your discretion. Thanks!

docs/development/compatibility-policy.rst Show resolved Hide resolved
docs/development/compatibility-policy.rst Outdated Show resolved Hide resolved
docs/development/compatibility-policy.rst Outdated Show resolved Hide resolved
docs/development/compatibility-policy.rst Outdated Show resolved Hide resolved
docs/development/compatibility-policy.rst Outdated Show resolved Hide resolved
docs/development/compatibility-policy.rst Outdated Show resolved Hide resolved
adiroiban and others added 2 commits September 24, 2023 10:20
Co-authored-by: Tom Most <twm@freecog.net>
Co-authored-by: Tom Most <twm@freecog.net>
@adiroiban
Copy link
Member Author

Many thanks Tom for your review. Excellent suggestions.
I have applied all your suggestions.

This is ready for another review

needs-review

Copy link
Member

@glyph glyph left a comment

Choose a reason for hiding this comment

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

I really want to make sure that if we add docs explaining a new option, we explain what the new option is, and clearly lead with why it's preferred. IF we need to still document the old option, then it should be described second, along with a clear explanation of why it's documented.

a warning is raised for `from twisted import old_code`,
but is not raised from `from twisted.old_code.sub.module import SomeClass`.

This is why it's recommended to just use `warnings.warn()` at the top level of the module.
Copy link
Member

Choose a reason for hiding this comment

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

This should be translated from passive to active voice and put at the top of the documentation. If we're going to document multiple ways to do something, it should be clear why multiple approaches exist and which one is appropriate in what circumstances.

@@ -551,6 +572,20 @@ Making calls to the deprecated code without raising these warnings can be done u

self.assertEqual('some-value', user.homePath)

def test_getUserNonexistentDatabase(self):
"""
The nesting of callDeprecated with assertRaises can result in ugly code.
Copy link
Member

Choose a reason for hiding this comment

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

Per https://jml.io/test-docstrings/ this should say what is being tested, not how ugly we consider the aesthetics of the result

Comment on lines +462 to +467
"""
The normal docstring of the top-level package.

This package was deprecated in Twisted NEXT
"""
import warnings
Copy link
Member

Choose a reason for hiding this comment

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

This module should have an introduction that explains what the code sample is meant to illustrate before launching into it.


Deprecation for whole packages or modules can be tested using the `importlib.reload` helper.

.. code-block:: python
Copy link
Member

Choose a reason for hiding this comment

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

For new code blocks, we should prefer literalinclude directives so that the Python code lives in Python files which can be loaded and tested.

@adiroiban
Copy link
Member Author

Thanks @glyph for the review.

My goal was to get something better than the current documentation ... we can make it perfect in follow up PRs :)

I don't think I will have time to look into this soon... maybe next time I will need to deprecated tests for a PR.

If anyone wants to continue working on this. No problem. The branch was pushed to the main repo so anyone from the team can write to it.

Cheers

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.

Document how to test a deprecated class
4 participants