99# See the License for the specific language governing permissions and
1010# limitations under the License.
1111
12- from typing import List
12+ from typing import List , Optional
1313
14+ import pytest
15+
16+ from src .model .document import Document , CreationInfo
1417from src .validation .document_validator import validate_full_spdx_document
15- from src .validation .validation_message import ValidationMessage
16- from tests .fixtures import document_fixture
18+ from src .validation .validation_message import ValidationMessage , ValidationContext , SpdxElementType
19+ from tests .fixtures import document_fixture , creation_info_fixture
1720
1821
1922def test_valid_document ():
@@ -22,4 +25,34 @@ def test_valid_document():
2225
2326 assert validation_messages == []
2427
25- # TODO: https://github.com/spdx/tools-python/issues/375
28+
29+ @pytest .mark .parametrize ("creation_info, version_input, expected_message" ,
30+ [(creation_info_fixture (spdx_version = "SPDX-2.3" ), "SPDX-2.3" , None ),
31+ (creation_info_fixture (spdx_version = "SPDX-2.3" ), None , None ),
32+ (creation_info_fixture (spdx_version = "SPDX-2.3" ), "SPDX-2.2" ,
33+ "provided SPDX version SPDX-2.2 does not match the document's SPDX version SPDX-2.3" ),
34+ (creation_info_fixture (spdx_version = "SPDX-2.3" ), "SPDX2.3" ,
35+ "provided SPDX version SPDX2.3 does not match the document's SPDX version SPDX-2.3" ),
36+ (creation_info_fixture (spdx_version = "SPDX2.3" ), "SPDX-2.3" ,
37+ 'the document\' s spdx_version must be of the form "SPDX-[major].[minor]" but is: SPDX2.3' ),
38+ (creation_info_fixture (spdx_version = "SPDX2.3" ), None ,
39+ 'the document\' s spdx_version must be of the form "SPDX-[major].[minor]" but is: SPDX2.3' ),
40+ (creation_info_fixture (spdx_version = "SPDX2.3" ), "SPDX2.3" ,
41+ 'the document\' s spdx_version must be of the form "SPDX-[major].[minor]" but is: SPDX2.3' ),
42+ ])
43+ def test_spdx_version_handling (creation_info : CreationInfo , version_input : str , expected_message : Optional [str ]):
44+ document : Document = document_fixture (creation_info = creation_info )
45+ validation_messages : List [ValidationMessage ] = validate_full_spdx_document (document , version_input )
46+
47+ context = ValidationContext (spdx_id = creation_info .spdx_id , element_type = SpdxElementType .DOCUMENT )
48+ expected : List [ValidationMessage ] = []
49+
50+ if expected_message :
51+ expected .append (ValidationMessage (expected_message , context ))
52+ expected .append (ValidationMessage ("There are issues concerning the SPDX version of the document. "
53+ "As subsequent validation relies on the correct version, "
54+ "the validation process has been cancelled." , context ))
55+
56+ assert validation_messages == expected
57+
58+ # TODO: https://github.com/spdx/tools-python/issues/375
0 commit comments