-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for weasyl.forms.expect_id (#1459)
Reviewed-by: Charmander <~@charmander.me>
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 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
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 |