| 549 | |
| 550 | |
| 551 | def test_simple(): |
| 552 | with taddons.context() as tctx: |
| 553 | c = command.CommandManager(tctx.master) |
| 554 | a = TAddon() |
| 555 | c.add("one.two", a.cmd1) |
| 556 | assert c.commands["one.two"].help == "cmd1 help" |
| 557 | assert c.execute("one.two foo") == "ret foo" |
| 558 | assert c.execute('one.two "foo"') == "ret foo" |
| 559 | assert c.execute("one.two 'foo bar'") == "ret foo bar" |
| 560 | assert c.call("one.two", "foo") == "ret foo" |
| 561 | with pytest.raises(exceptions.CommandError, match="Unknown"): |
| 562 | c.execute("nonexistent") |
| 563 | with pytest.raises(exceptions.CommandError, match="Invalid"): |
| 564 | c.execute("") |
| 565 | with pytest.raises(exceptions.CommandError, match="argument mismatch"): |
| 566 | c.execute("one.two too many args") |
| 567 | with pytest.raises(exceptions.CommandError, match="Unknown"): |
| 568 | c.call("nonexistent") |
| 569 | with pytest.raises(exceptions.CommandError, match="Unknown"): |
| 570 | c.execute("\\") |
| 571 | |
| 572 | c.add("empty", a.empty) |
| 573 | c.execute("empty") |
| 574 | |
| 575 | fp = io.StringIO() |
| 576 | c.dump(fp) |
| 577 | assert fp.getvalue() |
| 578 | |
| 579 | |
| 580 | def test_typename(): |