예제 #1
0
def cli(args, version, loglevel, shorten, check):
    """CLI entrypoint to test the stenotype backend.

    Enter any number of stenotype expressions to see which standard annotations they will
    resolve into. There is no need to double quote expression or to assign them to a
    value, the following will just work:

    \b
      $ stenotype 'bool or int'
      typing.Union[bool, int]
      $ stenotype '(int) -> bool'
      typing.Signature[[int], bool]

    You can also enter multiple arguments that will be executed in turn and consider each
    other in the context of, for example, custom type variables:

    \b
      $ stenotype 'T, int' 'bool or T'
      T = TypeVar[int]
      typing.Union[bool, T]
    """
    # early exits
    if version:
        click.echo(f"stenotype {__version__}")
        exit(0)
    if shorten and check:
        click.echo("Flags --shorten and --check can't be used simultaneously.",
                   err=True)
        exit(1)
    if not args:
        click.echo("No arguments entered, nothing to do.", err=True)
        exit(0)

    util.setup_logging(loglevel)
    try:
        if shorten:
            expressions = (f"stub inverse function: {arg}" for arg in args)
        else:
            expressions = (unparse(to_typing(parse(arg))) for arg in args)
        for expression in expressions:
            click.echo(expression)
    except util.StenotypeException as e:
        click.echo(e, err=True)
        exit(1)
예제 #2
0
def test_tricky_tuples():
    assert parse("(foo, bar)") == ste.Tuple(elements=(ste.Identifier("foo"),
                                                      ste.Identifier("bar")))
    assert parse("(foo, bar, ...)") == ste.Tuple(
        elements=(ste.Identifier("foo"), ste.Identifier("bar"), ste.Dots()))
예제 #3
0
def test_signatures(steno, parsed):
    assert parse(steno) == parsed
예제 #4
0
def test_callables(steno, parsed):
    assert parse(steno) == parsed
예제 #5
0
def test_shorthands(steno, parsed):
    assert parse(steno) == parsed
예제 #6
0
def test_containers(steno, parsed):
    assert isinstance(parse(steno), parsed)
예제 #7
0
def test_specials(steno, parsed):
    assert parse(steno) == parsed
예제 #8
0
def test_terminals(steno, parsed):
    assert parse(steno) == parsed
예제 #9
0
def test_typing(steno, parsed):
    assert parse(steno) == parsed
예제 #10
0
def test_literals(literal):
    # testing literals is a little different from other types
    assert parse(str(literal)) == ste.Literal(literal)
예제 #11
0
def test_shorthands(element):
    assert parse(unparse(element)) == element
예제 #12
0
def test_containers(element):
    assert parse(unparse(element)) == element
예제 #13
0
def test_specials(element):
    assert parse(unparse(element)) == element
예제 #14
0
def test_typing(element):
    assert parse(unparse(element)) == element
예제 #15
0
def test_terminals(element):
    assert parse(unparse(element)) == element