-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Permissive version string matching x 2.
This commit is the last in a commit chain relaxing version string matching internally performed by @beartype's test suite to permissively match version strings suffixed by supplementary software-specific version metadata (e.g., release candidates, alpha releases, beta releases), en-route to resolving test-time issue #283 kindly submitted by Gentoo Linux lead @mgorny (Michał Górny), who is also a cat, which is fairly impressive, considering that even the smartest cat only has a firm grasp on about 40 human words. Specifically, this commit tests our new private `beartype._util.text.utiltextversion.convert_str_version_to_tuple()` utility function with a new unit test exhaustively exercising all possible edge cases. Testing: it is exhausting. (*Indigo indignation in an indigestible nation!*)
- Loading branch information
Showing
3 changed files
with
85 additions
and
2 deletions.
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
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
84 changes: 84 additions & 0 deletions
84
beartype_test/a00_unit/a20_util/text/test_utiltextversion.py
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,84 @@ | ||
#!/usr/bin/env python3 | ||
# --------------------( LICENSE )-------------------- | ||
# Copyright (c) 2014-2023 Beartype authors. | ||
# See "LICENSE" for further details. | ||
|
||
''' | ||
Project-wide **version string utility** unit tests. | ||
This submodule unit tests the public API of the private | ||
:mod:`beartype._util.text.utiltextversion` submodule. | ||
''' | ||
|
||
# ....................{ IMPORTS }.................... | ||
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
# WARNING: To raise human-readable test errors, avoid importing from | ||
# package-specific submodules at module scope. | ||
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
||
# ....................{ TESTS }.................... | ||
def test_convert_str_version_to_tuple() -> None: | ||
''' | ||
Test the | ||
:func:`beartype._util.text.utiltextversion.convert_str_version_to_tuple` | ||
exception-raiser. | ||
''' | ||
|
||
# ....................{ IMPORTS }.................... | ||
# Defer test-specific imports. | ||
from beartype.roar._roarexc import _BeartypeUtilTextVersionException | ||
from beartype._util.text.utiltextversion import convert_str_version_to_tuple | ||
from pytest import raises | ||
|
||
# ....................{ PASS ~ undelimited }.................... | ||
# Assert that this converter converts a valid version string containing *NO* | ||
# "." delimiter comprising zero to the expected tuple. | ||
assert convert_str_version_to_tuple('0') == (0,) | ||
|
||
# Assert that this converter converts a valid version string containing *NO* | ||
# "." delimiter comprising a single positive integer to the expected tuple. | ||
assert convert_str_version_to_tuple('26') == (26,) | ||
|
||
# Assert that this converter converts a valid version string containing *NO* | ||
# "." delimiter comprising a single positive integer suffixed by a non-empty | ||
# substring that is *NOT* a non-negative integer to the expected tuple. | ||
assert convert_str_version_to_tuple('26rc1') == (26,) | ||
|
||
# ....................{ PASS ~ delimited }.................... | ||
# Assert that this converter converts a valid version string comprising one | ||
# or more "."-delimited non-negative integers to the expected tuple. | ||
assert convert_str_version_to_tuple('0.26.05') == (0, 26, 5,) | ||
|
||
# Assert that this converter converts a valid version string comprising one | ||
# or more "."-delimited non-negative integers suffixed by a non-empty | ||
# substring that is *NOT* a non-negative integer to the expected tuple. | ||
assert convert_str_version_to_tuple('0.26.05rc1') == (0, 26, 5,) | ||
|
||
# ....................{ FAIL }.................... | ||
# Assert that this converter raises the expected exception when passed an | ||
# invalid version string containing *NO* "." delimiter comprising a single | ||
# non-empty substring that is *NOT* a non-negative integer. | ||
with raises(_BeartypeUtilTextVersionException): | ||
convert_str_version_to_tuple('rc1') | ||
|
||
# Assert that this converter raises the expected exception when passed an | ||
# invalid version string containing *NO* "." delimiter comprising a single | ||
# negative integer. | ||
with raises(_BeartypeUtilTextVersionException): | ||
convert_str_version_to_tuple('-15') | ||
|
||
# Assert that this converter raises the expected exception when passed an | ||
# invalid version string comprising (in order): | ||
# 1. One or more "."-delimited non-negative integers followed by... | ||
# 2. A "."-delimited negative integer. | ||
with raises(_BeartypeUtilTextVersionException): | ||
convert_str_version_to_tuple('0.-15') | ||
|
||
# Assert that this converter raises the expected exception when passed an | ||
# invalid version string comprising (in order): | ||
# 1. One or more "."-delimited non-negative integers followed by... | ||
# 2. A "."-delimited substring that is *NOT* a non-negative integer followed | ||
# by... | ||
# 3. One or more "."-delimited non-negative integers. | ||
with raises(_BeartypeUtilTextVersionException): | ||
convert_str_version_to_tuple('0.15rc1.2') |