-
-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2222 from sopel-irc/adminchannel-hostmask-fix
adminchannel: fix, simplify, and comment hostmask utility function
- Loading branch information
Showing
2 changed files
with
86 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Tests for Sopel's ``adminchannel`` plugin""" | ||
from __future__ import generator_stop | ||
|
||
import pytest | ||
|
||
from sopel.modules import adminchannel | ||
|
||
|
||
VALID_INPUTS = ( | ||
('justanick', 'justanick!*@*'), | ||
('just-a.host', '*!*@just-a.host'), | ||
('justauser@', '*!justauser@*'), | ||
('someuser@just-a.host', '*!someuser@just-a.host'), | ||
('someuser@dotlesshost', '*!someuser@dotlesshost'), | ||
('somenick!someuser', 'somenick!someuser@*'), | ||
('somenick!someuser@', 'somenick!someuser@*'), | ||
('somenick!someuser@', 'somenick!someuser@*'), | ||
('full!host@mask', 'full!host@mask'), | ||
('full!mask@host.with.dots', 'full!mask@host.with.dots'), | ||
('libera/style/cloak', '*!*@libera/style/cloak'), | ||
) | ||
|
||
INVALID_INPUTS = ( | ||
'mask with whitespace', | ||
'cloak/with whitespace', | ||
'nick!auser@something with whitespace', | ||
'nick with spaces!user@host', | ||
'nick!user with spaces@host', | ||
'two!user!names@host', | ||
'two!user@host@names', | ||
) | ||
|
||
|
||
@pytest.mark.parametrize('raw, checked', VALID_INPUTS) | ||
def test_configureHostMask(raw, checked): | ||
"""Test the `configureHostMask` helper for functionality and compatibility.""" | ||
assert adminchannel.configureHostMask(raw) == checked | ||
|
||
|
||
@pytest.mark.parametrize('raw', INVALID_INPUTS) | ||
def test_configureHostMask_invalid(raw): | ||
with pytest.raises(ValueError): | ||
adminchannel.configureHostMask(raw) |