2020from spdx .parser .error import SPDXParsingError
2121from spdx .parser .tagvalue .parser import Parser
2222
23- DOCUMENT_STR = ' \n ' .join ([
24- ' SPDXVersion: SPDX-2.3' ,
25- ' DataLicense: CC0-1.0' ,
26- ' DocumentName: Sample_Document-V2.3' ,
27- ' SPDXID: SPDXRef-DOCUMENT' ,
28- ' DocumentComment: <text>Sample Comment</text>' ,
29- ' DocumentNamespace: https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301' ,
30- ' ExternalDocumentRef: DocumentRef-spdx-tool-1.2 http://spdx.org/spdxdocs/spdx-tools-v1.2-3F2504E0-4F89-41D3-9A0C-0305E82C3301 SHA1: d6a770ba38583ed4bb4525bd96e50461655d2759' ,
31- ' Creator: Person: Bob (bob@example.com)' ,
32- ' Creator: Organization: Acme.' ,
33- ' Created: 2010-02-03T00:00:00Z' ,
34- ' CreatorComment: <text>Sample Comment \n with multiple \n lines.</text>' ,
35- ' LicenseListVersion: 3.17'
23+ DOCUMENT_STR = " \n " .join ([
24+ " SPDXVersion: SPDX-2.3" ,
25+ " DataLicense: CC0-1.0" ,
26+ " DocumentName: Sample_Document-V2.3" ,
27+ " SPDXID: SPDXRef-DOCUMENT" ,
28+ " DocumentComment: <text>Sample Comment</text>" ,
29+ " DocumentNamespace: https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301" ,
30+ " ExternalDocumentRef: DocumentRef-spdx-tool-1.2 http://spdx.org/spdxdocs/spdx-tools-v1.2-3F2504E0-4F89-41D3-9A0C-0305E82C3301 SHA1: d6a770ba38583ed4bb4525bd96e50461655d2759" ,
31+ " Creator: Person: Bob (bob@example.com)" ,
32+ " Creator: Organization: Acme." ,
33+ " Created: 2010-02-03T00:00:00Z" ,
34+ " CreatorComment: <text>Sample Comment \n with multiple \n lines.</text>" ,
35+ " LicenseListVersion: 3.17"
3636])
3737
3838
@@ -43,15 +43,15 @@ def test_parse_creation_info():
4343 creation_info = document .creation_info
4444 assert creation_info is not None
4545 assert creation_info .spdx_version == "SPDX-2.3"
46- assert creation_info .data_license == ' CC0-1.0'
47- assert creation_info .name == ' Sample_Document-V2.3'
48- assert creation_info .spdx_id == ' SPDXRef-DOCUMENT'
49- assert creation_info .document_comment == ' Sample Comment'
50- assert creation_info .document_namespace == ' https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301'
46+ assert creation_info .data_license == " CC0-1.0"
47+ assert creation_info .name == " Sample_Document-V2.3"
48+ assert creation_info .spdx_id == " SPDXRef-DOCUMENT"
49+ assert creation_info .document_comment == " Sample Comment"
50+ assert creation_info .document_namespace == " https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301"
5151 TestCase ().assertCountEqual (creation_info .creators ,
5252 [Actor (ActorType .PERSON , "Bob" , "bob@example.com" ),
5353 Actor (ActorType .ORGANIZATION , "Acme." )])
54- assert creation_info .creator_comment == ' Sample Comment \n with multiple \n lines.'
54+ assert creation_info .creator_comment == " Sample Comment \n with multiple \n lines."
5555 assert creation_info .created == datetime (2010 , 2 , 3 )
5656 assert creation_info .license_list_version == Version (3 , 17 )
5757 assert creation_info .external_document_refs == [ExternalDocumentRef ("DocumentRef-spdx-tool-1.2" ,
@@ -61,28 +61,28 @@ def test_parse_creation_info():
6161
6262
6363@pytest .mark .parametrize ("document_str, expected_message" ,
64- ([(' \n ' .join (
65- [' SPDXVersion: SPDX-2.3' , ' DataLicense: CC0-1.0' , ' DocumentName: Sample_Document-V2.3' ,
66- ' SPDXID: SPDXRef-DOCUMENT' , ' DocumentComment: <text>Sample Comment</text>' ,
67- ' DocumentNamespace: <text>Sample Comment</text>' ,
68- ' ExternalDocumentRef: DocumentRef-spdx-tool-1.2:htp://spdx.org:SHA1: d6a770ba38583ed4bb4525bd96e50461655d2759' ,
69- ' Creator: Person Bob (bob@example.com)' , ' Creator: Organization: Acme [email]' ,
70- ' Created: 2010-02-03T00:00:0Z' , ' CreatorComment: <text>Sample Comment</text>' ,
71- ' LicenseListVersion: 7' ]),
72- "Error while parsing CreationInfo: "
73- "['Error while parsing DocumentNamespace: Token did not match specified grammar rule. "
74- "Line: 6', 'Error while parsing ExternalDocumentRef: "
75- "Token did not match specified grammar rule. Line: 7', 'Error while parsing Creator: "
76- "Token did not match specified grammar rule. Line: 8', 'Error while parsing Created: "
77- "Token did not match specified grammar rule. Line: 10', '7 is not a valid version string']" ),
78- ( ' \n ' .join (
79- [ ' SPDXVersion: SPDX-2.3' , ' DataLicense: CC0-1.0' , ' DocumentName: Sample_Document-V2.3' ,
80- ' SPDXID: SPDXRef-DOCUMENT' ]),
81- r"__init__() missing 3 required positional arguments: "
82- r"'document_namespace', 'creators', and 'created'" ),
83- ( ' LicenseListVersion: 3.5\n LicenseListVersion: 3.7' ,
84- "Error while parsing CreationInfo: ['Multiple values for LicenseListVersion "
85- "found. Line: 2']" )]))
64+ ([(" \n " .join (
65+ [" SPDXVersion: SPDX-2.3" , " DataLicense: CC0-1.0" , " DocumentName: Sample_Document-V2.3" ,
66+ " SPDXID: SPDXRef-DOCUMENT" , " DocumentComment: <text>Sample Comment</text>" ,
67+ " DocumentNamespace: <text>Sample Comment</text>" ,
68+ " ExternalDocumentRef: DocumentRef-spdx-tool-1.2:htp://spdx.org:SHA1: d6a770ba38583ed4bb4525bd96e50461655d2759" ,
69+ " Creator: Person Bob (bob@example.com)" , " Creator: Organization: Acme [email]" ,
70+ " Created: 2010-02-03T00:00:0Z" , " CreatorComment: <text>Sample Comment</text>" ,
71+ " LicenseListVersion: 7" ]),
72+ "Error while parsing CreationInfo: ['Error while parsing DocumentNamespace: "
73+ "Token did not match specified grammar rule. Line: 6', 'Error while parsing "
74+ "ExternalDocumentRef: Token did not match specified grammar rule. Line: 7', "
75+ "'Error while parsing Creator: Token did not match specified grammar rule. Line: 8', "
76+ "'Error while parsing Created: Token did not match specified grammar rule. Line: 10', "
77+ "'7 is not a valid version string']" ),
78+ ( " \n " .join (
79+ [ " SPDXVersion: SPDX-2.3" , " DataLicense: CC0-1.0" , " DocumentName: Sample_Document-V2.3" ,
80+ " SPDXID: SPDXRef-DOCUMENT" ]),
81+ r"__init__() missing 3 required positional arguments: 'document_namespace', "
82+ r" 'creators', and 'created'" ),
83+ ( " LicenseListVersion: 3.5\n LicenseListVersion: 3.7" ,
84+ "Error while parsing CreationInfo: ['Multiple values for LicenseListVersion found. "
85+ " Line: 2']" )]))
8686def test_parse_invalid_creation_info (document_str , expected_message ):
8787 parser = Parser ()
8888 with pytest .raises (SPDXParsingError ) as err :
0 commit comments