Example #1
0
def decision_table():
    ''' Simulate the invocation of the example decision table.
    Note that the standard slim table() / execute() / reset() steps 
    are missing from this simplistic sequence '''
    execution_context = ExecutionContext()
    results = Results()
    instr_list = [
        ['1', 'import', 'waferslim.examples.decision_table'],
        ['2', 'make', 'table', 'ShouldIBuyMilk'],
        ['3', 'call', 'table', 'setCashInWallet', '10'],
        ['4', 'call', 'table', 'setCreditCard', 'yes'],
        ['5', 'call', 'table', 'setPintsOfMilkRemaining', '1'],
        [
            '6',
            'call',
            'table',
            'goToStore',
        ],
    ]
    Instructions(instr_list).execute(execution_context, results)
    spec = lancelot.Spec(results.collection())
    spec.it().should_contain(['1', 'OK'])
    spec.it().should_contain(['2', 'OK'])
    spec.it().should_contain(['3', '/__VOID__/'])
    spec.it().should_contain(['4', '/__VOID__/'])
    spec.it().should_contain(['5', '/__VOID__/'])
    spec.it().should_contain(['6', 'no'])
Example #2
0
    def handles_stoptest_exceptions(self):
        ''' if stop test exception is thrown  stop executing instructions '''
        mock_fn = lancelot.MockSpec(name='mock_fn')
        mock_call = lancelot.MockSpec(name='mock_call')
        results = lancelot.MockSpec(name='results')
        a_list = [['id_', 'call', 'instance', 'fn', 'arg'],
                  ['id_', 'call', 'instance2', 'fn2', 'arg2']]
        instructions = Instructions(a_list,
                                    lambda item: mock_fn.instruction_for(item))
        spec = lancelot.Spec(instructions)
        ctx = ExecutionContext()
        msg = "I couldn't eat another thing. I'm absolutely stuffed."

        # Suppress warning log message that we know will be generated
        logger = logging.getLogger('Instructions')
        log_level = logger.getEffectiveLevel()
        logger.setLevel(logging.ERROR)
        try:
            spec.execute(ctx, results).should_collaborate_with(
                mock_fn.instruction_for(a_list[0]).will_return(mock_call),
                mock_call.execute(ctx,
                                  results).will_raise(StopTestException(msg)),
                results.failed(mock_call, msg, True))
        finally:
            # Put logger back to how it was
            logger.setLevel(log_level)
        ctx.cleanup_imports()
Example #3
0
def table_table():
    ''' Simulate the invocation of the example "table" table. '''
    execution_context = ExecutionContext()
    results = Results()
    instr_list = [
        ['1', 'import', 'waferslim.examples.table_table'],
        ['2', 'make', 'tableTable_1', 'Bowling'],
        [
            '3', 'call', 'tableTable_1', 'doTable',
            [[
                '3', '5', '4', '/', 'X', '', 'X', '', '3', '4', '6', '/', '7',
                '2', '3', '4', '9', '-', '4', '/', '3'
            ],
             [
                 '', '8', '', '28', '', '51', '', '68', '', '75', '', '92', '',
                 '101', '', '108', '', '117', '', '', '130'
             ]]
        ],
    ]
    Instructions(instr_list).execute(execution_context, results)
    spec = lancelot.Spec(results.collection())
    spec.it().should_contain(['1', 'OK'])
    spec.it().should_contain(['2', 'OK'])
    spec.it().should_contain(['3', lancelot.comparators.Type(list)])

    # 3rd result, 2nd item is list with query results
    spec = lancelot.Spec(results.collection()[2][1])
    spec.it().should_be(lancelot.comparators.Type(list))
    spec.__len__().should_be(2)  # list, len 2

    # 3rd result, 2nd item, 1st item is list with 1st "row" from results
    spec = lancelot.Spec(results.collection()[2][1][0])
    spec.it().should_be(lancelot.comparators.Type(list))
    spec.it().should_be([
        TableTableConstants.cell_no_change()
        for cell in results.collection()[2][1][0]
    ])

    # 3rd result, 2nd item, 2ndt item is list with 2nd "row" from results
    spec = lancelot.Spec(results.collection()[2][1][1])
    spec.it().should_be(lancelot.comparators.Type(list))
    spec.it().should_not_be([
        TableTableConstants.cell_no_change()
        for cell in results.collection()[2][1][1]
    ])
Example #4
0
def script_table():
    ''' Simulate the invocation of the example script table. '''
    execution_context = ExecutionContext()
    results = Results()
    instr_list = [
                  ['1', 'import', 'waferslim.examples.script_table'],
                  ['2', 'make', 'table', 'LoginDialogDriver', 'wafer', 'slim'],
                  ['3', 'call', 'table', 'loginWithUsernameAndPassword', \
                   'wafer', 'thin' ],
                  ['4', 'call', 'table', 'loginMessage', ],
                  ['5', 'call', 'table', 'numberOfLoginAttempts', ],
                 ]
    Instructions(instr_list).execute(execution_context, results)
    spec = lancelot.Spec(results.collection())
    spec.it().should_contain(['1', 'OK'])
    spec.it().should_contain(['2', 'OK'])
    spec.it().should_contain(['3', 'false'])
    spec.it().should_contain(['4', 'wafer not logged in.'])
    spec.it().should_contain(['5', '1'])
Example #5
0
 def loops_through_list(self):
     ''' Instructions should collaborate with instruction_for to instantiate
     a list of instructions, which execute() loops through '''
     mock_fn = lancelot.MockSpec(name='mock_fn')
     mock_make = lancelot.MockSpec(name='mock_make')
     mock_call = lancelot.MockSpec(name='mock_call')
     a_list = [['id_0', 'make', 'instance', 'fixture', 'argument'],
               ['id_1', 'call', 'instance', 'f', '3']]
     instructions = Instructions(a_list,
                                 lambda item: mock_fn.instruction_for(item))
     spec = lancelot.Spec(instructions)
     ctx = ExecutionContext()
     results = Results()
     spec.execute(ctx, results).should_collaborate_with(
         mock_fn.instruction_for(a_list[0]).will_return(mock_make),
         mock_make.execute(ctx, results),
         mock_fn.instruction_for(a_list[1]).will_return(mock_call),
         mock_call.execute(ctx, results))
     ctx.cleanup_imports()
Example #6
0
def symbols():
    ''' Simulate the invocation of the decision table that uses symbols.
    Note that the standard slim table() / execute() / reset() steps 
    are missing from this simplistic sequence '''
    execution_context = ExecutionContext()
    results = Results()
    instr_list = [
        ['1', 'import', 'waferslim.examples.values_and_symbols'],
        ['2', 'make', 'table', 'SomeDecisionTable'],
        ['3', 'call', 'table', 'setInput', '3'],
        ['4', 'callAndAssign', 'V', 'table', 'output'],
        ['5', 'call', 'table', 'setInput', '$V'],
        ['6', 'call', 'table', 'output'],
    ]
    Instructions(instr_list).execute(execution_context, results)
    spec = lancelot.Spec(results.collection())
    spec.it().should_contain(['1', 'OK'])
    spec.it().should_contain(['2', 'OK'])
    spec.it().should_contain(['3', '/__VOID__/'])
    spec.it().should_contain(['4', '4'])
    spec.it().should_contain(['5', '/__VOID__/'])
    spec.it().should_contain(['6', '8'])
Example #7
0
def query_table():
    ''' Simulate the invocation of the example query table.
    Note that the standard slim table() step is missing from this 
    simplistic sequence '''
    execution_context = ExecutionContext()
    results = Results()
    instr_list = [
        ['1', 'import', 'waferslim.examples.query_table'],
        ['2', 'make', 'table', 'EmployeesHiredBefore', '1999-12-12'],
        [
            '3',
            'call',
            'table',
            'query',
        ],
    ]
    Instructions(instr_list).execute(execution_context, results)
    spec = lancelot.Spec(results.collection())
    spec.it().should_contain(['1', 'OK'])
    spec.it().should_contain(['2', 'OK'])
    spec.it().should_contain(['3', lancelot.comparators.Type(list)])

    # 3rd result, 2nd item is list with query results
    spec = lancelot.Spec(results.collection()[2][1])
    spec.it().should_be(lancelot.comparators.Type(list))
    spec.__len__().should_be(2)  # list, len 2

    # 3rd result, 2nd item, 1st item is list with one "row" from query
    spec = lancelot.Spec(results.collection()[2][1][0])
    spec.it().should_be(lancelot.comparators.Type(list))
    spec.__len__().should_be(4)  # list, len 4
    spec.it().should_contain(
        ['employee number', lancelot.comparators.Type(str)])
    spec.it().should_contain(['first name', lancelot.comparators.Type(str)])
    spec.it().should_contain(['last name', lancelot.comparators.Type(str)])
    spec.it().should_contain(['hire date', lancelot.comparators.Type(str)])