Skip to content

Commit

Permalink
Add tests for weasyl.forms.expect_id (#1459)
Browse files Browse the repository at this point in the history
Reviewed-by: Charmander <~@charmander.me>
  • Loading branch information
charmander authored Nov 1, 2024
2 parents 236a5d7 + 0154da3 commit e5b5464
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions weasyl/test/test_forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pytest

from weasyl import forms
from weasyl.error import WeasylError


INVALID_IDS = (
'',
'a',
'0',
'-1',
'9999999999999999999999',
'\0',
'٨',
'+1',
pytest.param('01', marks=pytest.mark.xfail()),
'1.',
' 1',
'1\n',
'0x1',
'1a',
)

VALID_IDS = (
('1', 1),
('10', 10),
('2147483647', 2147483647),
)


@pytest.mark.parametrize('string', INVALID_IDS)
def test_expect_id_invalid(string: str):
with pytest.raises(WeasylError):
forms.expect_id(string)


@pytest.mark.parametrize('string,expected', VALID_IDS)
def test_expect_id_valid(string: str, expected: int):
assert forms.expect_id(string) == expected

0 comments on commit e5b5464

Please sign in to comment.