def __init__(self, commandLine, variablesToRequest=[]): """ Constructor. Calls the Command parent class's constructor. Stores some data by default to get some diagnostics of how the command has been used so we can determine if some tests have worked correctly or not. """ Command.__init__(self, 'test', variablesToRequest, commandLine) self.called = False self.gotData = False
def test_call_first_command(): func = mock.MagicMock() c1 = Command(command_type=CommandType.EQUAL, value="a", action=func.foo) c2 = Command(command_type=CommandType.START_WITH, value="a", action=func.bar) parser = Parser() parser.add_command(c1) parser.add_command(c2) parser.process_message("a") assert func.foo.called assert not func.bar.called
def __init__(self): Command.__init__( self, description="mpv ipc call cmdline wrapper", allow_abbrev=False ) self._parser.add_argument( "-s", "--socket", metavar="SOCKET", help="the socket location", type=str, default="/tmp/mpvsocket" )
def test_equal_command(): func = mock.MagicMock() c = Command(command_type=CommandType.EQUAL, value="a", action=func) parser = Parser() parser.add_command(c) parser.process_message("a") assert func.called
def test_start_with_command_not_ke(message): func = mock.MagicMock() c = Command(command_type=CommandType.START_WITH, value="foo", action=func) parser = Parser() parser.add_command(c) parser.process_message(message) assert not func.called
def test_in_list_command_not_ok(message): func = mock.MagicMock() c = Command(command_type=CommandType.IN_LIST, value=["a", "b", "c"], action=func) parser = Parser() parser.add_command(c) parser.process_message(message) assert not func.called
if os.path.exists(config_dir): break new_working_dir = os.path.split(working_dir)[0] if new_working_dir == working_dir: raise VexNoProject('No vex project found in {}'.format(os.getcwd())) working_dir = new_working_dir p = Project(config_dir, working_dir) if check: if empty and p.history_isempty(): raise VexNoHistory('Vex project exists, but `vex init` has not been run (or has been undone)') elif not p.clean_state(): raise VexUnclean('Another change is already in progress. Try `vex debug:status`') return p # CLI bits. Should handle environs, cwd, etc vex_cmd = Command('vex', 'a database for files') vex_cmd.long = """ vex is a command line program for saving changes to a project, switching between different versions, and sharing those changes. vex supports bash completion: run `complete -o nospace -C vex vex` """ @vex_cmd.on_error() def Error(path, args, exception, traceback):
import commands import ui from cli import Command from cli import CommandType from cli import POSITION_LIST from cli import Parser ui.say_hello() parser = Parser([ Command(command_type=CommandType.EQUAL, value="init", action=commands.init), Command(command_type=CommandType.EQUAL, value="f", action=commands.fetch_and_ls), # todo: get list of actions Command(command_type=CommandType.START_WITH, value="ls", action=commands.show_questions_by_tag), Command(command_type=CommandType.START_WITH, value="s ", action=commands.show_questions), Command(command_type=CommandType.START_WITH, value="sn ", action=commands.show_new_questions), Command(command_type=CommandType.START_WITH, value="del", action=commands.delete_questions), Command(command_type=CommandType.START_WITH, value="hide", action=commands.hide_tag), Command(command_type=CommandType.START_WITH, value="unhide",