Skip to content

Commit

Permalink
Permissive version string matching x 2.
Browse files Browse the repository at this point in the history
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
leycec committed Sep 22, 2023
1 parent d7ab7ce commit 771b9d7
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
1 change: 0 additions & 1 deletion beartype/_util/text/utiltextversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from re import compile as re_compile

# ....................{ CONVERTERS }....................
#FIXME: Unit test us up, please.
def convert_str_version_to_tuple(version: str) -> Tuple[int, ...]:
'''
Convert the passed human-readable ``.``-delimited version string into a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# See "LICENSE" for further details.

'''
Project-wide **Python identifier** utility unit tests.
Project-wide **Python identifier utility** unit tests.
This submodule unit tests the public API of the private
:mod:`beartype._util.text.utiltextidentifier` submodule.
Expand Down
84 changes: 84 additions & 0 deletions beartype_test/a00_unit/a20_util/text/test_utiltextversion.py
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')

0 comments on commit 771b9d7

Please sign in to comment.