@ -16,7 +16,7 @@ sys.path.insert(0, _ROOT_DIR)
import gclient_utils
import metadata . parse
import metadata . fields . known
class ParseTest ( unittest . TestCase ) :
def test_parse_single ( self ) :
@ -52,6 +52,10 @@ class ParseTest(unittest.TestCase):
] ,
)
# Check line numbers are recorded correctly.
self . assertEqual ( ( 1 , 23 ) ,
all_metadata [ 0 ] . get_first_and_last_line_number ( ) )
def test_parse_multiple ( self ) :
""" Check parsing works for multiple dependencies ' metadata. """
filepath = os . path . join ( _THIS_DIR , " data " ,
@ -83,6 +87,8 @@ class ParseTest(unittest.TestCase):
( " Local Modifications " , " None, \n EXCEPT: \n * nothing. " ) ,
] ,
)
self . assertEqual ( ( 1 , 20 ) ,
all_metadata [ 0 ] . get_first_and_last_line_number ( ) )
# Check the parser handles different casing for field names, and
# strips leading and trailing whitespace from values.
@ -102,6 +108,8 @@ class ParseTest(unittest.TestCase):
( " Local Modifications " , " None. " ) ,
] ,
)
self . assertEqual ( ( 24 , 35 ) ,
all_metadata [ 1 ] . get_first_and_last_line_number ( ) )
# Check repeated fields persist in the metadata's entries.
self . assertListEqual (
@ -119,6 +127,8 @@ class ParseTest(unittest.TestCase):
" field, and \n missing a mandatory field. " ) ,
] ,
)
self . assertEqual ( ( 40 , 50 ) ,
all_metadata [ 2 ] . get_first_and_last_line_number ( ) )
def test_parse_multiple_local_modifications ( self ) :
""" Check parsing works for multiple dependencies, each with different local modifications. """
@ -137,6 +147,8 @@ class ParseTest(unittest.TestCase):
" 1. Modified X file \n 2. Deleted Y file " ) ,
] ,
)
self . assertEqual ( ( 1 , 5 ) ,
all_metadata [ 0 ] . get_first_and_last_line_number ( ) )
self . assertListEqual (
all_metadata [ 1 ] . get_entries ( ) ,
@ -145,6 +157,8 @@ class ParseTest(unittest.TestCase):
( " Local Modifications " , " None " ) ,
] ,
)
self . assertEqual ( ( 9 , 10 ) ,
all_metadata [ 1 ] . get_first_and_last_line_number ( ) )
self . assertListEqual (
all_metadata [ 2 ] . get_entries ( ) ,
@ -153,6 +167,8 @@ class ParseTest(unittest.TestCase):
( " Local Modifications " , " None. " ) ,
] ,
)
self . assertEqual ( ( 14 , 24 ) ,
all_metadata [ 2 ] . get_first_and_last_line_number ( ) )
self . assertListEqual (
all_metadata [ 3 ] . get_entries ( ) ,
@ -161,6 +177,36 @@ class ParseTest(unittest.TestCase):
( " Local Modifications " , " None, \n Except modified file X. " ) ,
] ,
)
self . assertEqual ( ( 28 , 30 ) ,
all_metadata [ 3 ] . get_first_and_last_line_number ( ) )
def test_parse_per_field_line_numbers ( self ) :
""" Check parsing marks the line numbers of each individual fields. """
filepath = os . path . join ( _THIS_DIR , " data " ,
" README.chromium.test.single-valid " )
content = gclient_utils . FileRead ( filepath )
all_metadata = metadata . parse . parse_content ( content )
self . assertEqual ( len ( all_metadata ) , 1 )
dm = all_metadata [ 0 ]
field_spec = metadata . fields . known
expected_line_numbers = {
field_spec . NAME : [ 1 ] ,
field_spec . SHORT_NAME : [ 2 ] ,
field_spec . URL : [ 3 , 4 ] ,
field_spec . VERSION : [ 8 ] ,
field_spec . DATE : [ 9 ] ,
field_spec . LICENSE : [ 10 ] ,
field_spec . LICENSE_FILE : [ 11 ] ,
field_spec . SECURITY_CRITICAL : [ 12 ] ,
field_spec . SHIPPED : [ 13 ] ,
field_spec . CPE_PREFIX : [ 14 ] ,
field_spec . DESCRIPTION : [ 16 , 17 , 18 ] ,
field_spec . LOCAL_MODIFICATIONS : [ 20 , 21 ] ,
}
self . assertEqual ( dm . get_field_line_numbers ( metadata . fields . known . NAME ) ,
[ 1 ] )
if __name__ == " __main__ " :
unittest . main ( )