def test_can_ignore(self):
     """Test whether comments and whitespace-only lines are ignored."""
     self.assertEqual(_can_ignore("# a comment..."), True)
     self.assertEqual(_can_ignore("  \t# a comment..."), True)
     self.assertEqual(_can_ignore("  \t\n   "), True)
     self.assertEqual(_can_ignore("abc"), False)
     self.assertEqual(_can_ignore(" \t abc   "), False)
Exemple #2
0
def format_participant_list(participants_f, url_prefix):
    """Formats an HTML list of personal IDs with links to personal results.

    Returns the HTML list as a string suitable for writing to a file. Personal
    IDs will be sorted.

    Arguments:
        participants_f - file containing a single personal ID per line. If
            additional tab-separated columns exist, they will be ignored (this
            allows the file to be in the same format as that accepted by
            my_microbes.parse.parse_recipients for convenience)
        url_prefix - URL to prefix each personal ID with to provide links to
            personalized results (string)
    """
    personal_ids = []

    for line in participants_f:
        if not _can_ignore(line):
            personal_id = line.strip().split('\t')[0].strip()

            if personal_id in personal_ids:
                raise ValueError("The personal ID '%s' has already been "
                                 "encountered. Personal IDs must be unique." %
                                 personal_id)

            personal_ids.append(personal_id)

    personal_ids.sort()

    url_prefix = url_prefix if url_prefix.endswith('/') else url_prefix + '/'

    result = '<ul>\n'
    for personal_id in personal_ids:
        url = url_prefix + personal_id + '/index.html'
        result += '  <li><a href="%s" target="_blank">%s</a></li>\n' % (
                url, personal_id)
    result += '</ul>\n'

    return result