def test_create(self):
        '''
        Testa a criação da matriz com o método `create`.
        '''

        # Testa a criação com dimensões iguais a zero.
        # Deve resultar em exceção.
        for n, m in ((0, 0), (0, 1), (1, 0)):
            with self.subTest(m=m, n=n):
                try:
                    check = False
                    matrix = commands.create(m, n)
                except exceptions.InvalidSize:
                    check = True
                self.assertTrue(check)

        # Testa a criação com dimensões válidas
        for n in range(1, 5):
            for m in range(1, 5):
                with self.subTest(m=m, n=n):
                    matrix = commands.create(m, n)
                    # verifica o número de linhas
                    self.assertTrue(len(matrix) == m)
                    # verifica o conteúdo das colunas
                    self.assertTrue(
                        all(''.join(line) == 'O' * n for line in matrix))
Beispiel #2
0
def handle_command(command, options, parser):
    if command == 'create':
        create(options, parser)
    if command == 'update':
        update(options, parser)
    if command == 'find':
        find(options, parser)
    if command == 'mo':
        mo(options, parser)
Beispiel #3
0
def handle_input():
    global currentUser
    user_input = str
    print(colored(f'What do you want to do now, {currentUser[1]} ? ',
                  'red',
                  attrs=['bold', 'blink']),
          end=colored('» ', 'yellow', attrs=['bold']))
    user_input = input()
    if user_input == 'exit':
        print(
            colored(
                '\n' +
                'Thank you for using the app, see you again soon, byebye ! \n ლ(╥﹏╥ლ)',
                'red',
                attrs=['bold', 'blink']), "\n")
        sys.exit()
    elif 'create' in user_input:
        create(user_input, currentUser)
    elif 'list' in user_input:
        list_task(user_input, currentUser)
    elif "add" in user_input:
        add_task(currentUser)
    elif 'mark' in user_input:
        mark_task(user_input, currentUser)
    elif 'remove' in user_input:
        remove_task(currentUser)
    elif 'edit' in user_input:
        edit_task(currentUser)
    elif 'user' in user_input:
        list_user(user_input, currentUser)
    elif 'project' in user_input or "proj" in user_input:
        list_projects(currentUser, user_input)
    elif 'assign' in user_input:
        assign_projects(currentUser)
    elif 'finish' in user_input:
        mark_projects(currentUser)
    elif 'history' in user_input:
        list_history(currentUser)
    elif 'who-to-fire' in user_input:
        who_to_fire()
    elif 'help' in user_input:
        print_menu()
        handle_input()
    else:
        print(
            colored(
                """Sorry, I don't understand that command, please input the right command or type 'help' for the list of commands, thanks! """,
                'red',
                attrs=['bold', 'blink']))
    def test_clear(self):
        '''
        C
        Limpa a matriz. O tamanho permanece o mesmo.
        Todos os pixels ficam brancos (O).
        '''
        m, n = 5, 5
        matrix = commands.create(m, n)
        for line in matrix:
            line[2] = 'A'
        matrix_str = ''.join(itertools.chain.from_iterable(matrix))
        self.assertTrue(matrix_str != 'O' * m * n)

        matrix = commands.clear(matrix)
        matrix_str = ''.join(itertools.chain.from_iterable(matrix))
        self.assertTrue(matrix_str == 'O' * m * n)
Beispiel #5
0
def run_agent_mode():
    """
    Prompt the user for commands and listen for the response.
    Commands are run with agent parameters and limitations.
    When the "logout" command is given, this function returns.
    """
    print 'Logged in as agent'
    records = []
    deleted_accounts = []
    while True:
        line = inputOutput.prompt_for_input().lower()
        if line == 'logout':
            inputOutput.write_summary_file(records, sys.argv[2])
            print 'Logged out'
            return
        elif line == 'transfer':
            tmp_transfer = commands.transfer(True)
            if (validation.validate_deleted(tmp_transfer[1], deleted_accounts)
                    or validation.validate_deleted(tmp_transfer[2],
                                                   deleted_accounts)):
                records.append(tmp_transfer)
                print 'Transfer successful'
            else:
                print 'Error: Account does not exist'
        elif line == 'withdraw':
            tmp_withdraw = commands.withdraw(True, {})
            if validation.validate_deleted(tmp_withdraw[1], deleted_accounts):
                records.append(tmp_withdraw)
                print 'Withdraw successful'
            else:
                print 'Error: Account does not exist'
        elif line == 'deposit':
            tmp_deposit = commands.deposit(True)
            if validation.validate_deleted(tmp_deposit[1], deleted_accounts):
                records.append(tmp_deposit)
                print 'Deposit successful'
            else:
                print 'Error: Account does not exist'
        elif line == 'create':
            records.append(commands.create())
        elif line == 'delete':
            tmp_delete = commands.delete()
            records.append(tmp_delete)
            deleted_accounts.append(tmp_delete[1])
        else:
            print 'Error: command not recognized'
Beispiel #6
0
async def on_message(message):  # This is overwritting the default on_message()
    if message.content.startswith(PREFIX):
        asyncio.ensure_future(commands.create(message, PREFIX, client))

    else:
        pass