view env/lib/python3.9/site-packages/galaxy/tool_util/verify/asserts/tabular.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
line wrap: on
line source

import re


def get_first_line(output):
    match = re.search("^(.*)$", output, flags=re.MULTILINE)
    if match is None:
        return None
    else:
        return match.group(1)


def assert_has_n_columns(output, n, sep='\t'):
    """ Asserts the tabular output contains n columns. The optional
    sep argument specifies the column seperator used to determine the
    number of columns."""
    n = int(n)
    first_line = get_first_line(output)
    assert first_line is not None, "Was expecting output with %d columns, but output was empty." % n
    assert len(first_line.split(sep)) == n, "Output does not have %d columns." % n