11# type: ignore
22
3- import unittest
3+
4+ import pytest
45
56from sifter .grammar .tag import Tag as GrammarTag
67from sifter .grammar .rule import Rule , RuleSyntaxError
@@ -18,60 +19,39 @@ def __init__(self, arguments=None, tests=None):
1819 super (MockRule , self ).__init__ (arguments , tests )
1920
2021
21- class TestValidationFn (unittest .TestCase ):
22-
23- def test_too_many_args (self ) -> None :
24- mock_rule = MockRule ([GrammarTag ('IS' ), 13 , ])
25- self .assertRaises (
26- RuleSyntaxError ,
27- mock_rule .validate_arguments ,
28- )
29-
30- def test_not_enough_args (self ) -> None :
31- mock_rule = MockRule ([13 , ])
32- self .assertRaises (
33- RuleSyntaxError ,
34- mock_rule .validate_arguments ,
35- [
36- Number (),
37- StringList (),
38- ],
39- )
40-
41-
42- class TestTagValidator (unittest .TestCase ):
43-
44- def test_allowed_tag (self ) -> None :
45- mock_validator = TagValidator (['MOCK' , 'IS' , ])
46- self .assertEqual (
47- mock_validator .validate ([GrammarTag ('IS' )], 0 ),
48- 1
49- )
50-
51- def test_allowed_single_tag (self ) -> None :
52- # test the case for a non-list single tag name
53- mock_validator = TagValidator ('IS' )
54- self .assertEqual (
55- mock_validator .validate ([GrammarTag ('IS' )], 0 ),
56- 1
57- )
58-
59- def test_not_allowed_tag (self ) -> None :
60- mock_validator = TagValidator (['MOCK' , 'FOO' , ])
61- self .assertEqual (
62- mock_validator .validate ([GrammarTag ('IS' )], 0 ),
63- 0
64- )
65-
66- def test_not_allowed_single_tag (self ) -> None :
67- # test the case for a non-list single tag name. test when the tag is a
68- # substring of the allowed tag.
69- mock_validator = TagValidator ('ISFOO' )
70- self .assertEqual (
71- mock_validator .validate ([GrammarTag ('IS' )], 0 ),
72- 0
73- )
74-
75-
76- if __name__ == '__main__' :
77- unittest .main ()
22+ def test_too_many_args () -> None :
23+ mock_rule = MockRule ([GrammarTag ('IS' ), 13 , ])
24+ with pytest .raises (RuleSyntaxError ):
25+ mock_rule .validate_arguments ()
26+
27+
28+ def test_not_enough_args () -> None :
29+ mock_rule = MockRule ([13 , ])
30+ with pytest .raises (RuleSyntaxError ):
31+ mock_rule .validate_arguments ([
32+ Number (),
33+ StringList (),
34+ ])
35+
36+
37+ def test_allowed_tag () -> None :
38+ mock_validator = TagValidator (['MOCK' , 'IS' , ])
39+ assert mock_validator .validate ([GrammarTag ('IS' )], 0 ) == 1
40+
41+
42+ def test_allowed_single_tag () -> None :
43+ # test the case for a non-list single tag name
44+ mock_validator = TagValidator ('IS' )
45+ assert mock_validator .validate ([GrammarTag ('IS' )], 0 ) == 1
46+
47+
48+ def test_not_allowed_tag () -> None :
49+ mock_validator = TagValidator (['MOCK' , 'FOO' , ])
50+ assert mock_validator .validate ([GrammarTag ('IS' )], 0 ) == 0
51+
52+
53+ def test_not_allowed_single_tag () -> None :
54+ # test the case for a non-list single tag name. test when the tag is a
55+ # substring of the allowed tag.
56+ mock_validator = TagValidator ('ISFOO' )
57+ assert mock_validator .validate ([GrammarTag ('IS' )], 0 ) == 0
0 commit comments