Пример #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_shorthands(typing_type, element):
    assert typing_type == unparse(normalize(element))
Пример #3
0
def test_callable_signatures(typing_type, element):
    assert typing_type == unparse(normalize(element))
Пример #4
0
def test_specials(typing_type, element):
    assert typing_type == unparse(normalize(element))
Пример #5
0
def test_containers(typing_type, element):
    assert typing_type == unparse(normalize(element))
Пример #6
0
def test_unknown():
    with pytest.raises(NotImplementedError,
                       match="cannot be represented") as e:
        unparse(object())
Пример #7
0
def test_terminals(typing_type, element):
    assert typing_type == unparse(normalize(element))
Пример #8
0
def test_shorthands(element):
    assert parse(unparse(element)) == element
Пример #9
0
def test_containers(element):
    assert parse(unparse(element)) == element
Пример #10
0
def test_specials(element):
    assert parse(unparse(element)) == element
Пример #11
0
def test_typing(element):
    assert parse(unparse(element)) == element
Пример #12
0
def test_terminals(element):
    assert parse(unparse(element)) == element