11import pytest
22
33from _internal .models import ClassifierRoot , ClassifierNode
4+ from _internal .exceptions import InvalidClassifier
45
56
67def test_nested_prefixes ():
@@ -13,10 +14,10 @@ def test_nested_prefixes():
1314 ]
1415 )
1516
16- assert root .generate () == [
17- ClassifierNode ( "Foo" ) ,
18- ClassifierNode ( "Foo :: Bar" ) ,
19- ClassifierNode ( "Foo :: Bar :: Baz" ) ,
17+ assert [ node . full_name for node in root .generate ()] == [
18+ "Foo" ,
19+ "Foo :: Bar" ,
20+ "Foo :: Bar :: Baz" ,
2021 ]
2122
2223
@@ -31,12 +32,47 @@ def test_skip():
3132 ]
3233 )
3334
34- assert root .generate () == [
35- ClassifierNode ( "Foo :: Bar" ) ,
36- ClassifierNode ( "Foo :: Bar :: Baz" ) ,
35+ assert [ node . full_name for node in root .generate ()] == [
36+ "Foo :: Bar" ,
37+ "Foo :: Bar :: Baz" ,
3738 ]
3839
3940
4041def test_bad_deprecation_failure ():
41- with pytest .raises (Exception ) :
42+ with pytest .raises (InvalidClassifier ) as excinfo :
4243 ClassifierNode ("blah" , deprecated_by = ["spam" ])
44+
45+ assert excinfo .value .args == (
46+ "Using deprecated_by, but not marking the classifier as deprecated" ,
47+ )
48+
49+
50+ @pytest .mark .parametrize (
51+ "parent, child" ,
52+ [("Private" , "Foo" ), ("private" , "Foo" ), ("Foo" , "Private" ), ("Foo" , "private" ),],
53+ )
54+ def test_private_classifier_failure (parent , child ):
55+ with pytest .raises (InvalidClassifier ) as excinfo :
56+ ClassifierNode (
57+ parent , children = [ClassifierNode (child )],
58+ )
59+
60+ assert excinfo .value .args == ("Classifiers starting with 'Private' are invalid" ,)
61+
62+
63+ @pytest .mark .parametrize ("classifier" , [" Foo" , "Foo " ])
64+ def test_whitespace_classifier_failure (classifier ):
65+ with pytest .raises (InvalidClassifier ) as excinfo :
66+ ClassifierNode (classifier )
67+
68+ assert excinfo .value .args == (
69+ "Classifiers starting or ending with whitespace are invalid" ,
70+ )
71+
72+
73+ @pytest .mark .parametrize ("classifier" , ["Foo:" , "Foo :: Bar" ])
74+ def test_colon_classifier_failure (classifier ):
75+ with pytest .raises (InvalidClassifier ) as excinfo :
76+ ClassifierNode (classifier )
77+
78+ assert excinfo .value .args == ("Classifiers containing ':' are invalid" ,)
0 commit comments