1313from __future__ import print_function
1414from __future__ import unicode_literals
1515
16+ import sys
1617import unittest
1718from unittest import TestCase
1819
@@ -95,6 +96,14 @@ def test_pacakage(self):
9596 self .token_assert_helper (self .l .token (), 'PKG_VERF_CODE' , 'PackageVerificationCode' , 3 )
9697 self .token_assert_helper (self .l .token (), 'LINE' , '4e3211c67a2d28fced849ee1bb76e7391b93feba (SpdxTranslatorSpdx.rdf, SpdxTranslatorSpdx.txt)' , 3 )
9798
99+ def test_unknown_tag (self ):
100+ data = '''
101+ SomeUnknownTag: SomeUnknownValue
102+ '''
103+ self .l .input (data )
104+ self .token_assert_helper (self .l .token (), 'UNKNOWN_TAG' , 'SomeUnknownTag' , 2 )
105+ self .token_assert_helper (self .l .token (), 'LINE' , 'SomeUnknownValue' , 2 )
106+
98107 def token_assert_helper (self , token , ttype , value , line ):
99108 assert token .type == ttype
100109 assert token .value == value
@@ -158,6 +167,8 @@ class TestParser(TestCase):
158167 'FileComment: <text>Very long file</text>'
159168 ])
160169
170+ unknown_tag_str = 'SomeUnknownTag: SomeUnknownValue'
171+
161172 complete_str = '{0}\n {1}\n {2}\n {3}\n {4}' .format (document_str , creation_str , review_str , package_str , file_str )
162173
163174 def setUp (self ):
@@ -207,6 +218,21 @@ def test_file(self):
207218 assert len (spdx_file .artifact_of_project_home ) == 1
208219 assert len (spdx_file .artifact_of_project_uri ) == 1
209220
221+ def test_unknown_tag (self ):
222+
223+ try :
224+ from StringIO import StringIO
225+ except ImportError :
226+ from io import StringIO
227+
228+ saved_out = sys .stdout
229+ sys .stdout = StringIO ()
230+ document , error = self .p .parse (self .unknown_tag_str )
231+ self .assertEqual (sys .stdout .getvalue (), 'Found unknown tag : SomeUnknownTag at line: 1\n ' )
232+ sys .stdout = saved_out
233+ assert error
234+ assert document is not None
235+
210236
211237if __name__ == '__main__' :
212238 unittest .main ()
0 commit comments