Skip to content

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 2 commits into from
Apr 15, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions tests/test_build_docs_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from __future__ import annotations

import pytest

from build_docs import Version


def test_equality() -> None:
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

# 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"),
("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
requirements = version.requirements

# Assert
assert expected in 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