Skip to content

Commit

Permalink
add test for util.get_str_class_num()
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoge1001 committed Oct 12, 2024
1 parent c44eb85 commit ef51489
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/unittests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3369,3 +3369,61 @@ def test_logexc_with_log_level(self, caplog, log_level):
),
("tests.unittests.test_util", logging.DEBUG, "an error occurred"),
]


class TestRandStr:
def _get_str_class_num(str):
import string
str_class_num = 0
if any(c.islower() for c in str):
str_class_num += 1
if any(c.isupper() for c in str):
str_class_num += 1
if any(c.isdigit() for c in str):
str_class_num += 1
if any(c in string.punctuation for c in str):
str_class_num += 1
return str_class_num

@pytest.mark.parametrize(
"strlen, param_minclass, expected_minclass, expected_maxclass",
[
(1, 1, 1, 1),
(1, 2, 1, 1),
(1, 3, 1, 1),
(1, 4, 1, 1),
(2, 1, 1, 2),
(2, 2, 2, 2),
(2, 3, 2, 2),
(2, 4, 2, 2),
(3, 1, 1, 3),
(3, 2, 2, 3),
(3, 3, 3, 3),
(3, 4, 3, 3),
(4, 1, 1, 3),
(4, 2, 2, 3),
(4, 3, 3, 3),
(4, 4, 4, 4),
(5, 1, 1, 3),
(5, 2, 2, 3),
(5, 3, 3, 3),
(5, 4, 4, 4),
(5, 5, 4, 4),
(6, 1, 1, 3),
(6, 2, 2, 3),
(6, 3, 3, 3),
(6, 4, 4, 4),
(6, 5, 4, 4),
(6, 6, 4, 4),
(20, 1, 1, 3),
(20, 2, 2, 3),
(20, 3, 3, 3),
(20, 4, 4, 4),
(20, 5, 4, 4),
],
)
def test_get_str_class_num(self, strlen, param_minclass, expected_minclass, expected_maxclass):
res_rand_str = util.rand_str_minclass(strlen, param_minclass)
actual_class = self._get_str_class_num(res_rand_str)
assert actual_class >= expected_minclass
assert actual_class <= expected_maxclass

0 comments on commit ef51489

Please sign in to comment.