Assert that all registered locations' parent locations are also registered.

def _sanity_check_registered_locations_parent_locations(query_metadata_table):
    """Assert that all registered locations' parent locations are also registered."""
    for location, location_info in query_metadata_table.registered_locations:
        if (location != query_metadata_table.root_location and
                not query_metadata_table.root_location.is_revisited_at(location)):
            # If the location is not the root location and is not a revisit of the root,
            # then it must have a parent location.
            if location_info.parent_location is None:
                raise AssertionError(u'Found a location that is not the root location of the query '
                                     u'or a revisit of the root, but does not have a parent: '
                                     u'{} {}'.format(location, location_info))

        if location_info.parent_location is not None:
            # Make sure the parent_location is also registered.
            # If the location is not registered, the following line will raise an error.
            query_metadata_table.get_location_info(location_info.parent_location)