def test_basic_int_add(): expected = 3 @cli def simple1(first: int, second: float): assert first + second == expected main(None, "simple1", "1", "2")
def test_basic_help(): @cli def simple4(first: int, second: float): pass with pytest.raises(SystemExit) as pytest_wrapped_e: main(None, "simple4", "--help") assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == 0
def test_basic_default(): expected = 3 @cli def simple3(first: int, second: float = 2): """ Explanation :param first: First :param second: Second """ assert first + second == expected main(None, "simple3", "1")
def test_basic_docs(): expected = 3 @cli def simple2(first: int, second: float): """ Explanation :param first: First :param second: Second """ assert first + second == expected main(None, "simple2", "1", "2")
def fallback(version_info=None): if use_timing: print("before imports", time.time() - sys.cliche_ts__) for import_name in sorted(set(function_to_imports.values())): t1 = time.time() __import__(import_name) if use_timing: print("import time", import_name, time.time() - sys.cliche_ts__) if use_timing: print("before main import", time.time() - sys.cliche_ts__) from cliche import main main(version_info=version_info)
from cliche import cli, main from pydantic import BaseModel class B(BaseModel): b: str class Item(BaseModel): a: str = "good_one" b: str @cli def print_item(item: Item, b: int = 2): print(repr(item), b) # does not yet work without main() main()
def fallback(version_info=None): for import_name in sorted(set(function_to_imports.values())): __import__(import_name) from cliche import main main(version_info=version_info)
version_info = None for cache_value in cache.values(): import_name = cache_value["import_name"] functions = cache_value["functions"] version_info = version_info or cache_value.get("version_info") if not functions: continue for function in functions: function_to_imports[function] = import_name def fallback(version_info=None): for import_name in sorted(set(function_to_imports.values())): __import__(import_name) from cliche import main main(version_info=version_info) if len(sys.argv) > 1: command = sys.argv[1] if command in function_to_imports: __import__(function_to_imports[command]) from cliche import main main(version_info=version_info) else: fallback(version_info=version_info) else: fallback(version_info=version_info)
def mainer(*args): cliche.main_called = [] main(None, None, "simple", *args)