Esempio n. 1
0
def test_sub_parsers_help(capsys):
    # do we get the `name` substitution right?
    SingleFileExperimentFactory.__doc__ = 'Description of {parser_name}'
    cli = CLI()
    assert cli.all_subparsers['data'].parser_name == 'data'

    with parsing_output(capsys) as text:
        parse('data --help')

    assert 'Description of data' in text.std

    # is custom sub-parser screen displayed and description used included in it?
    SingleFileExperimentFactory.description = 'A dummy description'
    SingleFileExperimentFactory.epilog = 'A dummy epilog'

    with parsing_output(capsys) as text:
        parse('data --help')

    lines = text.std.split('\n')
    half_of_output = len(lines) // 2

    # is description in the text and is it in the first 50% of lines?
    assert any(SingleFileExperimentFactory.description in line
               for line in lines[:half_of_output])
    # is the epilog in the text and is it in the last 50% of lines?
    assert any(SingleFileExperimentFactory.epilog in line
               for line in lines[half_of_output:])
Esempio n. 2
0
def test_database(capsys):
    with parsing_output(capsys) as text:
        parse('gsea database --show_gene_sets')
    assert 'HALLMARK_HYPOXIA' in text.std

    db = create_test_db()
    assert len(db.gene_sets) == 2
Esempio n. 3
0
def test_shows_usage_when_no_args(capsys):

    # if there are no arguments provided, the parser should
    # show the usage summary (and do not raise any errors)
    with parsing_output(capsys) as text:
        parse(None)

    assert 'usage' in text.err
Esempio n. 4
0
def test_general_help(capsys):

    with parsing_output(capsys) as text:
        parse('--help')

    for method in Method.members:
        assert method in text.std

    with parsing_error(match='unrecognized arguments: --controll'):
        p_parse('data merged.tsv --case 1 --controll 2 control c.tsv')
Esempio n. 5
0
def test_methods(capsys, test_files):
    suffix = 'case t.tsv control c.tsv'

    class MyMethod(Method):

        name = 'some_method'
        help = 'Some important text help'

        other_argument = Argument(
            type=int,
            help='Only integer numbers!',
            default=0,
        )

        def __init__(self,
                     mode,
                     my_argument: float = None,
                     other_argument=None):
            """

            Args:
                mode: This argument has to be passed!
                my_argument: Help and documentation for my_argument
                other_argument: Documentation for the other_argument
            """

            if mode == 'active':
                raise Success('In active mode!')
            if my_argument == 1.4:
                raise Success('Correct Argument provided +1')
            if type(other_argument) is int:
                raise Success(f'Parsed +{other_argument}')

        def run(self, experiment):
            raise Success('Run +10')

    # test mode which is a required argument
    with pytest.raises(Success, message='In active mode!'):
        parse(f'some_method active {suffix}')

    # test my_argument
    with pytest.raises(Success, message='Correct Argument provided +1'):
        parse(f'some_method a --my_argument 1.4 {suffix}')

    # test run
    with pytest.raises(Success, message='Run +10'):
        run(f'run.py some_method a --my_argument 2.1 {suffix}'.split())

    # test other_argument
    with pytest.raises(Success, message='Parsed +5'):
        parse(f'some_method a --other_argument 5 {suffix}')

    # test help
    for test_command in ['some_method --help', '-h some_method']:
        with parsing_output(capsys, contains='Some important text help'):
            parse(test_command)

    with parsing_output(capsys, does_not_contain='Some important text help'):
        parse('--help')

    # test arguments help
    arguments_help = {
        'This argument has to be passed!': True,
        'Help and documentation for my_argument': True,
        'Only integer numbers!': True,
        # Following should not be shown, as it is overwritten by
        # "integers-only" text above from Argument definition:
        'Documentation for the other_argument': False
    }

    for text, is_expected in arguments_help.items():
        contains, does_not_contain = None, None
        if is_expected:
            contains = text
        else:
            does_not_contain = text

        with parsing_output(capsys,
                            contains=contains,
                            does_not_contain=does_not_contain):
            parse('some_method -h')
Esempio n. 6
0
def test_help(capsys):
    with parsing_output(capsys) as text:
        parse('gsea --help')
    assert 'GSEA method' in text.std
Esempio n. 7
0
def test_licence(capsys):
    with parsing_output(capsys) as text:
        parse('gsea --show_licence')
    assert 'copyright (c) 2004-2017 Broad Institute, Inc.' in text.std
Esempio n. 8
0
def test_database(capsys):
    with parsing_output(capsys) as text:
        parse('gsea database --show_gene_sets')
    assert 'HALLMARK_HYPOXIA' in text.std
Esempio n. 9
0
def test_help(capsys):
    with parsing_output(capsys) as text:
        parse('SPIA --help')
    assert 'signaling pathway impact analysis (SPIA)' in text.std