1818
1919from unittest import TestCase
2020
21+ from ddt import ddt , named_data
22+
2123from cyclonedx .exception .model import InvalidCreIdException
2224from cyclonedx .model .definition import CreId , Definitions , Level , Requirement , Standard
2325
@@ -29,13 +31,13 @@ def test_init(self) -> Definitions:
2931 dr = Definitions (
3032 standards = (s , ),
3133 )
34+ self .assertEqual (1 , len (dr .standards ))
3235 self .assertIs (s , tuple (dr .standards )[0 ])
3336 return dr
3437
3538 def test_filled (self ) -> None :
3639 dr = self .test_init ()
3740 self .assertIsNotNone (dr .standards )
38- self .assertEqual (1 , len (dr .standards ))
3941 self .assertTrue (dr )
4042
4143 def test_empty (self ) -> None :
@@ -68,6 +70,7 @@ def test_equal(self) -> None:
6870 self .assertTrue (dr1 == tr2 )
6971
7072
73+ @ddt
7174class TestModelCreId (TestCase ):
7275
7376 def test_different (self ) -> None :
@@ -84,21 +87,21 @@ def test_same(self) -> None:
8487 self .assertEqual (hash (id1 ), hash (id2 ))
8588 self .assertTrue (id1 == id2 )
8689
87- def test_invalid_id (self ) -> None :
90+ def test_invalid_no_id (self ) -> None :
8891 with self .assertRaises (TypeError ):
8992 CreId ()
93+
94+ @named_data (
95+ ['empty' , '' ],
96+ ['arbitrary string' , 'some string' ],
97+ ['missing prefix' , '123-456' ],
98+ ['additional part' , 'CRE:123-456-789' ],
99+ ['no numbers' , 'CRE:abc-def' ],
100+ ['no delimiter' , 'CRE:123456' ],
101+ )
102+ def test_invalid_id (self , wrong_id ) -> None :
90103 with self .assertRaises (InvalidCreIdException ):
91- CreId ('' )
92- with self .assertRaises (InvalidCreIdException ):
93- CreId ('some string' )
94- with self .assertRaises (InvalidCreIdException ):
95- CreId ('123-456' )
96- with self .assertRaises (InvalidCreIdException ):
97- CreId ('CRE:123-456-789' )
98- with self .assertRaises (InvalidCreIdException ):
99- CreId ('CRE:abc-def' )
100- with self .assertRaises (InvalidCreIdException ):
101- CreId ('CRE:123456' )
104+ CreId (wrong_id )
102105
103106
104107class TestModelRequirements (TestCase ):
0 commit comments