def test_calculator_with_division(capsys): with patch('sys.argv', ['', 'd', '2', '4']): app = asynccli.App(Calculator) app.run() out, _ = capsys.readouterr() assert out == "0.5\n"
def test_calculator_with_multiplication(capsys): with patch('sys.argv', ['', 'm', '2', '4']): app = asynccli.App(Calculator) app.run() out, _ = capsys.readouterr() assert out == "8\n"
def test_division_calculator(capsys): # sys.argv = ['1', '2'] with patch('sys.argv', ['', '1', '2']): app = asynccli.App(Calculator) app.run() out, _ = capsys.readouterr() assert out == "0.5\n"
import asynccli class MyCLI(asynccli.CLI): async def call(self): print("Hello, world.") if __name__ == '__main__': app = asynccli.App(MyCLI) app.run()
import asynccli async def mycli(): print("Hello, world.") class MultiplicationCalculator(asynccli.CLI): first_num = asynccli.Integer(help_text='This is some help text.') second_num = asynccli.Integer() async def call(self): print(self.first_num * self.second_num) class Calculator(asynccli.TieredCLI): m = MultiplicationCalculator if __name__ == '__main__': app = asynccli.App(Calculator, mycli) app.run()
import asynccli async def mycli(): print("Hello, world.") if __name__ == '__main__': app = asynccli.App(mycli) app.run()
def test_hello_world_class(capsys): app = asynccli.App(MyCLI) app.run() out, _ = capsys.readouterr() assert out == "Hello, world.\n"
def test_hello_world_basic(capsys): app = asynccli.App(mycli) app.run() out, _ = capsys.readouterr() assert out == "Hello, world.\n"
def test_setup_teardown(capsys): app = asynccli.App(MyCLI) app.run() out, _ = capsys.readouterr() assert out == "setup\nHello, world.\nteardown\n"
import asynccli class DivisionCalculator(asynccli.CLI): first_num = asynccli.Integer(help_text='This is some help text.') second_num = asynccli.Integer() async def call(self): print(self.first_num / self.second_num) if __name__ == '__main__': app = asynccli.App(DivisionCalculator) app.run()