Exemple #1
0
def travis_fail_test_cache_clear():
    command = ["true"]
    c = procin.Command(cache=True, cache_dir="test")
    c.run(command)
    assert c.in_cache(command) != None
    c.clear_cache()
    assert c.in_cache(command) == None
Exemple #2
0
def test_sematics():
    c = procin.Command()
    ab = c.run(["echo", "-n", "[]"], json=True)
    assert ab == []
    with pytest.raises(AttributeError) as excinfo:
        ab = c.run(["echo", "-n", "[]"], x=True)
    with pytest.raises(json.decoder.JSONDecodeError) as excinfo:
        ab = c.run(["echo", "-n", "not json"], json=True)
Exemple #3
0
def test_array():
    c = procin.Command(json=True)
    ab = c.run(["echo", "-n", "[]"])
    assert ab == []
    ab = c.run(["echo", "[]"])
    assert ab == []
    ab = c.run(["/bin/echo", f'{{"v": "{wierd_string}"}}'])
    assert ab["v"] == wierd_string
Exemple #4
0
def test_cache(tmpdir):
    c = procin.Command(json=True, cache=True, cache_dir=str(tmpdir))
    command = ["/bin/echo", "-n", '{"h": "hello"}']
    assert c.in_cache(command) == None
    j = c.run(command)
    assert j["h"] == "hello"
    s = c.in_cache(command)
    js = json.loads(s)
    assert j == js
    assert j == c.run(command)
Exemple #5
0
def test_filename():
    c = procin.Command()
    command = [wierd_string]
    s = c.command_to_filename(command)
    assert c.filename_to_command(s) == command
    command = ["echo", "-n", "[]"]
    s = c.command_to_filename(command)
    print(s)
    assert s == "echo^n-n^n^l^r^n"
    assert c.filename_to_command(s) == command
    print(command)
Exemple #6
0
def test_run_does_not_change_defaults():
    c = procin.Command(json=True)
    js = c.run(["echo", "-n", "[]"], json=False)
    assert(isinstance(js, str))
    js = c.run(["echo", "-n", "[]"])
    assert(not isinstance(js, str))
Exemple #7
0
def test_run_fail():
    c = procin.Command()
    with pytest.raises(Exception) as excinfo:
        _ = c.run(["false"])
    result = c.run(["false"], catch=True)
Exemple #8
0
def test_print_output(capsys):
    c = procin.Command(print_output=True)
    ab = c.run(["echo", "hi"])
    captured = capsys.readouterr()
    assert "echo" not in captured.out
    assert "hi" in captured.out
Exemple #9
0
#!/usr/bin/env python
import click
import subprocess
import json
import pendulum
import functools
import typer
import procin
from typing import Optional

runner = procin.Command(cache=True, cache_dir="rc", json=True)


@functools.lru_cache(maxsize=1)
def resource_groups():
    rgs = runner.run(['ibmcloud', 'resource', 'groups', '--output', 'json'])
    rgid_rg = {}
    for rg in rgs:
        click.echo(f'{rg["name"]} {rg["id"]}')
        rgid_rg[rg["id"]] = rg
    return {**rgid_rg, **{"*": {"name": "*", "id": "*"}}}


@functools.lru_cache(maxsize=1)
def ic_resource_service_instances():
    return runner.run([
        'ibmcloud', 'resource', 'service-instances', '--type', 'all',
        '--all-resource-groups', '--output', 'json'
    ])