]>
git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/tests/test_terminal.py
2 from ceph_volume
import terminal
5 class SubCommand(object):
7 help = "this is the subcommand help"
9 def __init__(self
, argv
):
16 class BadSubCommand(object):
18 def __init__(self
, argv
):
25 class TestSubhelp(object):
27 def test_no_sub_command_help(self
):
28 assert terminal
.subhelp({}) == ''
30 def test_single_level_help(self
):
31 result
= terminal
.subhelp({'sub': SubCommand
})
33 assert 'this is the subcommand help' in result
35 def test_has_title_header(self
):
36 result
= terminal
.subhelp({'sub': SubCommand
})
37 assert 'Available subcommands:' in result
39 def test_command_with_no_help(self
):
40 class SubCommandNoHelp(object):
42 result
= terminal
.subhelp({'sub': SubCommandNoHelp
})
46 class TestDispatch(object):
48 def test_no_subcommand_found(self
):
49 result
= terminal
.dispatch({'sub': SubCommand
}, argv
=[])
52 def test_no_main_found(self
):
55 def __init__(self
, argv
):
57 result
= terminal
.dispatch({'sub': NoMain
}, argv
=['sub'])
60 def test_subcommand_found_and_dispatched(self
):
61 with pytest
.raises(SystemExit) as error
:
62 terminal
.dispatch({'sub': SubCommand
}, argv
=['sub'])
63 assert str(error
.value
) == '0'
65 def test_subcommand_found_and_dispatched_with_errors(self
):
66 with pytest
.raises(SystemExit) as error
:
67 terminal
.dispatch({'sub': BadSubCommand
}, argv
=['sub'])
68 assert str(error
.value
) == '100'