@@ -2125,10 +2125,7 @@ def handler(wrapped, trigger):
21252125 assert result .group (1 ) == 'reverse'
21262126
21272127
2128- def test_command_from_callable_regex_pattern (mockbot ):
2129- # TODO: this test must FAIL for Sopel 8.0
2130- # Command name as regex pattern will be removed in Sopel 8.0
2131-
2128+ def test_command_from_callable_escaped_regex_pattern (mockbot ):
21322129 # prepare callable
21332130 @plugin .commands ('main .*' )
21342131 def handler (wrapped , trigger ):
@@ -2139,21 +2136,23 @@ def handler(wrapped, trigger):
21392136 # create rule from a cleaned callable
21402137 rule = rules .Command .from_callable (mockbot .settings , handler )
21412138
2142- # match on ".main anything"
2139+ # does not match on ".main anything"
21432140 line = ':[email protected] PRIVMSG #sopel :.main anything' 21442141 pretrigger = trigger .PreTrigger (mockbot .nick , line )
21452142 results = list (rule .match (mockbot , pretrigger ))
21462143
2144+ assert not results , 'Regex commands are not allowed since Sopel 8.0'
2145+
2146+ # match on ".main .*"
2147+ line = ':[email protected] PRIVMSG #sopel :.main .*' 2148+ pretrigger = trigger .PreTrigger (mockbot .nick , line )
2149+ results = list (rule .match (mockbot , pretrigger ))
2150+
21472151 assert len (results ) == 1 , (
2148- 'Exactly 1 command must match; MUST fail for Sopel 8.0 ' )
2152+ 'Command name must be escaped to get an exact match ' )
21492153 result = results [0 ]
2150- assert result .group (0 ) == '.main anything'
2151- assert result .group (1 ) == 'main anything'
2152- assert result .group (2 ) is None
2153- assert result .group (3 ) is None
2154- assert result .group (4 ) is None
2155- assert result .group (5 ) is None
2156- assert result .group (6 ) is None
2154+ assert result .group (0 ) == '.main .*'
2155+ assert result .group (1 ) == 'main .*'
21572156
21582157
21592158def test_command_from_callable_invalid (mockbot ):
@@ -2169,21 +2168,6 @@ def handler(wrapped, trigger):
21692168 rules .Command .from_callable (mockbot .settings , handler )
21702169
21712170
2172- def test_command_escape_name ():
2173- rule = rules .Command ('hello' , r'\.' , plugin = 'testplugin' )
2174-
2175- assert rule .escape_name ('hello' ) == 'hello'
2176- assert rule .escape_name ('hello world' ) == r'hello\ world'
2177- assert rule .escape_name (r'hello\ world' ) == r'hello\ world' , (
2178- 'Valid pattern must not be escaped' )
2179- assert rule .escape_name (r'.*' ) == r'.*' , (
2180- 'Valid pattern must not be escaped' )
2181- assert rule .escape_name (r'a[bc]d' ) == r'a[bc]d' , (
2182- 'Valid pattern must not be escaped' )
2183- assert rule .escape_name (r'hello(' ) == r'hello\(' , (
2184- 'Invalid pattern must be escaped' )
2185-
2186-
21872171# -----------------------------------------------------------------------------
21882172# tests for :class:`sopel.plugins.rules.NickCommand`
21892173
@@ -2444,10 +2428,6 @@ def handler(wrapped, trigger):
24442428
24452429
24462430def test_nick_command_from_callable_regex_pattern (mockbot ):
2447- # TODO: this test must FAIL for Sopel 8.0
2448- # Command name as regex pattern will be removed in Sopel 8.0
2449-
2450- # prepare callable
24512431 @plugin .nickname_commands ('do .*' )
24522432 def handler (wrapped , trigger ):
24532433 wrapped .reply ('Hi!' )
@@ -2457,16 +2437,21 @@ def handler(wrapped, trigger):
24572437 # create rule from a cleaned callable
24582438 rule = rules .NickCommand .from_callable (mockbot .settings , handler )
24592439
2460- # match on ".main anything"
2440+ # does not match on ".do anything"
24612441 line = ':[email protected] PRIVMSG #sopel :TestBot: do anything' 24622442 pretrigger = trigger .PreTrigger (mockbot .nick , line )
24632443 results = list (rule .match (mockbot , pretrigger ))
24642444
2465- assert len (results ) == 1 , (
2466- 'Exactly 1 command must match; MUST fail for Sopel 8.0' )
2445+ assert not results , 'Regex commands are not allowed since Sopel 8.0'
2446+
2447+ # match on ".do .*"
2448+ line = ':[email protected] PRIVMSG #sopel :TestBot: do .*' 2449+ pretrigger = trigger .PreTrigger (mockbot .nick , line )
2450+ results = list (rule .match (mockbot , pretrigger ))
2451+ assert len (results ) == 1 , 'Exactly 1 command must match'
24672452 result = results [0 ]
2468- assert result .group (0 ) == 'TestBot: do anything '
2469- assert result .group (1 ) == 'do anything '
2453+ assert result .group (0 ) == 'TestBot: do .* '
2454+ assert result .group (1 ) == 'do .* '
24702455 assert result .group (2 ) is None
24712456 assert result .group (3 ) is None
24722457 assert result .group (4 ) is None
@@ -2649,9 +2634,6 @@ def handler(wrapped, trigger):
26492634
26502635
26512636def test_action_command_from_callable_regex_pattern (mockbot ):
2652- # TODO: this test must FAIL for Sopel 8.0
2653- # Command name as regex pattern will be removed in Sopel 8.0
2654-
26552637 # prepare callable
26562638 @plugin .action_commands ('do .*' )
26572639 def handler (wrapped , trigger ):
@@ -2662,16 +2644,22 @@ def handler(wrapped, trigger):
26622644 # create rule from a cleaned callable
26632645 rule = rules .ActionCommand .from_callable (mockbot .settings , handler )
26642646
2665- # match on ".main anything"
2647+ # does not match on ".do anything"
26662648 line = ':[email protected] PRIVMSG #sopel :\x01 ACTION do anything\x01 ' 26672649 pretrigger = trigger .PreTrigger (mockbot .nick , line )
26682650 results = list (rule .match (mockbot , pretrigger ))
26692651
2670- assert len (results ) == 1 , (
2671- 'Exactly 1 command must match; MUST fail for Sopel 8.0' )
2652+ assert not results , 'Regex commands are not allowed since Sopel 8.0'
2653+
2654+ # match on ".do .*"
2655+ line = ':[email protected] PRIVMSG #sopel :\x01 ACTION do .*\x01 ' 2656+ pretrigger = trigger .PreTrigger (mockbot .nick , line )
2657+ results = list (rule .match (mockbot , pretrigger ))
2658+
2659+ assert len (results ) == 1 , 'Exactly 1 command must match'
26722660 result = results [0 ]
2673- assert result .group (0 ) == 'do anything '
2674- assert result .group (1 ) == 'do anything '
2661+ assert result .group (0 ) == 'do .* '
2662+ assert result .group (1 ) == 'do .* '
26752663 assert result .group (2 ) is None
26762664 assert result .group (3 ) is None
26772665 assert result .group (4 ) is None
0 commit comments