Example #1
0
def cli_validator_listdir(cli_setup, validator):

    _, api, _, prefix = cli_setup

    with open('test.txt', 'w') as f:
        f.write('test test')

    tas_archive = api.create('impactlab/climate/tas/tas_daily_us.csv')
    tas_archive.update('test.txt')
    precip_archive = api.create('impactlab/climate/pr/pr_daily_us.csv')
    precip_archive.update('test.txt')
    socio = api.create('impactlab/mortality/global/mortality_global_daily.csv')
    socio.update('test.txt')
    socio1 = api.create('impactlab/conflict/global/conflict_global_daily.csv')
    socio1.update('test.txt')
    socio2 = api.create('impactlab/labor/global/labor_global_daily.csv')
    socio2.update('test.txt')

    validator.call_engines['datafs'] = ClickValidator(app=cli, prefix=prefix)

    yield validator.teststring

    del validator.call_engines['datafs']

    try:
        tas_archive.delete()
        precip_archive.delete()
        socio.delete()
        socio1.delete()
        socio2.delete()
        os.remove('test.txt')
    except KeyError:
        pass
Example #2
0
def cli_validator_and_api(cli_setup, validator):

    _, api, _, prefix = cli_setup

    try:
        api.delete_archive('my_archive')
    except KeyError:
        pass

    validator.call_engines['datafs'] = ClickValidator(app=cli, prefix=prefix)

    yield validator.teststring, api

    del validator.call_engines['datafs']
Example #3
0
def test_validator():

    teststr = r'''

    .. code-block:: bash

        $ hello Polly
        Hello Polly!

        $ echo 'Pining for the fjords' # doctest: +NORMALIZE_WHITESPACE
        Pining for the fjords

    Pipes don't work, so we can't redirect this value into a file. But we can
    write a file with python:

    .. code-block:: bash

        $ python -c \
        >     "with open('tmp.txt', 'w+') as f: f.write('Pushing up daisies')"

        $ cat tmp.txt
        Pushing up daisies

    '''

    tester = Runner()
    tester.call_engines['hello'] = ClickValidator(hello)
    tester.call_engines['echo'] = SubprocessValidator()
    tester.call_engines['python'] = SubprocessValidator()
    tester.call_engines['cat'] = SubprocessValidator()

    tester.teststring(teststr)

    badstr = '''

    The following block of code should cause an error:

    .. code-block:: bash

        $ rm tmp.txt

    '''

    with pytest.raises(ValueError):
        tester.teststring(badstr)

    os.remove('tmp.txt')
Example #4
0
def test_bad_command():

    badstr = '''

    .. code-block:: bash

        $ badcmd Polly # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        ValueError: This command doesn't work!

    '''

    tester = Runner()
    tester.call_engines['badcmd'] = ClickValidator(badcmd)

    tester.teststring(badstr)
Example #5
0
def cli_validator_dual_auth(cli_setup_dual_auth, validator):

    _, api, _, prefix = cli_setup_dual_auth

    try:
        api.delete_archive('my_archive')
    except KeyError:
        pass

    validator.call_engines['datafs'] = ClickValidator(app=cli, prefix=prefix)

    api.attach_authority('my_authority', TempFS())

    try:
        yield validator.teststring

    finally:
        api._authorities['my_authority'].fs.close()
        del validator.call_engines['datafs']
Example #6
0
def cli_validator_manager_various(cli_setup, validator):

    _, api, _, prefix = cli_setup

    archive_names = []
    for indices in itertools.product(*(range(1, 6) for _ in range(3))):
        archive_name = ('project{}_variable{}_scenario{}.nc'.format(*indices))
        archive_names.append(archive_name)

    for i, name in enumerate(archive_names):

        if i % 3 == 0:
            try:
                api.create(name, tags=['team1'])
            except KeyError:
                pass

        elif i % 2 == 0:
            try:
                api.create(name, tags=['team2'])
            except KeyError:
                pass
        else:
            try:
                api.create(name, tags=['team3'])
            except KeyError:
                pass

    validator.call_engines['datafs'] = ClickValidator(app=cli, prefix=prefix)

    yield validator.teststring

    del validator.call_engines['datafs']

    # Teardown

    for arch in map(api.get_archive, archive_names):
        arch.delete()
Example #7
0
def test_string_command():

    teststr = '''

    .. code-block:: bash

        $ hello Polly
        Hello Polly!

        $ hello Polly Parrot
        Usage: hello [OPTIONS] NAME
        <BLANKLINE>
        Error: Got unexpected extra argument (Parrot)

        $ hello 'Polly Parrot'
        Hello Polly Parrot!

    '''

    tester = Runner()
    tester.call_engines['hello'] = ClickValidator(hello)

    tester.teststring(teststr)