-
-
Notifications
You must be signed in to change notification settings - Fork 62
Test the Version
class
#287
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from build_docs import Version | ||
|
||
|
||
def test_equality() -> None: | ||
# Arrange | ||
version1 = Version(name="3.13", status="stable", branch_or_tag="3.13") | ||
version2 = Version(name="3.13", status="stable", branch_or_tag="3.13") | ||
|
||
# Act / Assert | ||
assert version1 == version2 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("name", "expected"), | ||
[ | ||
("3.13", "-rrequirements.txt"), | ||
ezio-melotti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
("3.10", "standard-imghdr"), | ||
("3.7", "sphinx==2.3.1"), | ||
("3.5", "sphinx==1.8.4"), | ||
], | ||
) | ||
def test_requirements(name: str, expected: str) -> None: | ||
# Arrange | ||
version = Version(name=name, status="stable", branch_or_tag="") | ||
|
||
# Act / Assert | ||
assert expected in version.requirements | ||
|
||
|
||
def test_requirements_error() -> None: | ||
# Arrange | ||
version = Version(name="2.8", status="ex-release", branch_or_tag="") | ||
|
||
# Act / Assert | ||
with pytest.raises(ValueError, match="unreachable"): | ||
_ = version.requirements | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("status", "expected"), | ||
[ | ||
("EOL", "never"), | ||
("security-fixes", "yearly"), | ||
("stable", "daily"), | ||
], | ||
) | ||
def test_changefreq(status: str, expected: str) -> None: | ||
# Arrange | ||
version = Version(name="3.13", status=status, branch_or_tag="") | ||
|
||
# Act / Assert | ||
assert version.changefreq == expected | ||
|
||
|
||
def test_url() -> None: | ||
# Arrange | ||
version = Version(name="3.13", status="stable", branch_or_tag="") | ||
|
||
# Act / Assert | ||
assert version.url == "https://docs.python.org/3.13/" | ||
|
||
|
||
def test_title() -> None: | ||
# Arrange | ||
version = Version(name="3.14", status="in development", branch_or_tag="") | ||
|
||
# Act / Assert | ||
assert version.title == "Python 3.14 (in development)" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("name", "status", "expected"), | ||
[ | ||
("3.15", "in development", "dev (3.15)"), | ||
("3.14", "pre-release", "pre (3.14)"), | ||
("3.13", "stable", "3.13"), | ||
], | ||
) | ||
def test_picker_label(name: str, status: str, expected: str) -> None: | ||
# Arrange | ||
version = Version(name=name, status=status, branch_or_tag="") | ||
|
||
# Act / Assert | ||
assert version.picker_label == expected |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are all the
-> None
necessary?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.
Nope, type annotations are completely optional in Python :)
More seriously, they could be omitted, as we're not running mypy on this repo (yet).
And generally, it is a good idea to also type hints to tests (for example, see https://sethmlarson.dev/tests-arent-enough-case-study-after-adding-types-to-urllib3#type-your-tests) and that could cover these returns too.
It can be useful in tests to help immediately differentiate from fixtures and helper methods which do return something, for example in #288.
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 was referring specifically to the tests (not fixtures or other helper functions), since they (always?) return
None
, making the-> None
superfluous.I guess it makes sense to add it for consistency, both with other functions/methods that have the return type, or for tests that have types for the their args?
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.
Yeah, we can remove them if you prefer, I don't mind too much either way. But when we add mypy, let's add them back if it complains about it.
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.
Adding them opt-in the function to be checked by mypy, so it will be usefull if we use mypy on this repo sometime.