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)
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()))
def test_signatures(steno, parsed): assert parse(steno) == parsed
def test_callables(steno, parsed): assert parse(steno) == parsed
def test_shorthands(steno, parsed): assert parse(steno) == parsed
def test_containers(steno, parsed): assert isinstance(parse(steno), parsed)
def test_specials(steno, parsed): assert parse(steno) == parsed
def test_terminals(steno, parsed): assert parse(steno) == parsed
def test_typing(steno, parsed): assert parse(steno) == parsed
def test_literals(literal): # testing literals is a little different from other types assert parse(str(literal)) == ste.Literal(literal)
def test_shorthands(element): assert parse(unparse(element)) == element
def test_containers(element): assert parse(unparse(element)) == element
def test_specials(element): assert parse(unparse(element)) == element
def test_typing(element): assert parse(unparse(element)) == element
def test_terminals(element): assert parse(unparse(element)) == element