예제 #1
0
    def test_error_stack_given_final_value_if_no_interruption(s, tags):
        # tags are : bold, italic, and underline in that order
        def failing_processor(value, context):
            e = err.ValidationError("I'll fail you, no matter what",
                                    interrupt_validation=False)
            raise e

        processors = list((t, None) for t in tags)
        processors[1:1] = [[failing_processor,
                            None]]  # inserting at position 1
        rs = RunnerStack(None, *processors)
        with pytest.raises(err.ValidationErrorStack) as e:
            value = rs.run('some contents')
        assert e.value.data == '<u><i><b>' + 'some contents' + '</b></i></u>'
예제 #2
0
    def test_interrupts_validation_if_interrupt_flag_set_on_error(s, mocker):
        def failing_processor(value, context):
            e = err.ValidationError("I'll fail you, no matter what",
                                    interrupt_validation=True)
            raise e

        #mk = mocker.MagicMock() # probably better to declare some specs
        mk = mocker.MagicMock(spec=['run'])
        processors = tuple((t, None) for t in (failing_processor, mk))
        rs = RunnerStack(None, *processors)
        try:
            value = rs.run('some contents')
        except err.ValidationErrorStack as e:
            assert not mk.run.called
예제 #3
0
    def test_run_assigns_failing_value_to_error_after_validation(s, tags):
        # tags are : bold, italic, and underline in that order
        def failing_processor(value, context):
            e = err.ValidationError("I'll fail you, no matter what",
                                    interrupt_validation=True)
            raise e

        processors = list((t, None) for t in tags)
        processors[1:1] = [(failing_processor, None)
                           ]  # inserting at position 1
        rs = RunnerStack(None, *processors)
        try:
            value = rs.run('some contents')
        except err.ValidationErrorStack as e:
            assert e[0].data == '<b>' + 'some contents' + '</b>'
예제 #4
0
    def test_calls_next_runner_if_interrupt_flag_not_set_on_error(s, mocker):
        def failing_processor(value, context):
            e = err.ValidationError("I'll fail you, no matter what",
                                    interrupt_validation=False)
            raise e

        # we either need to specify spec to restrict the mock's public api
        # or test for `mock.run.called`
        #mk = mocker.MagicMock() # probably better to declare some specs
        mk = mocker.MagicMock(spec=['run', 'vino_init'])
        mk.vino_init.return_value = mk
        processors = tuple((t, None) for t in [failing_processor, mk])
        rs = RunnerStack(None, *processors)
        try:
            value = rs.run('some contents')
        except err.ValidationErrorStack as e:
            assert mk.run.called
예제 #5
0
 def test_executes_runners_in_fifo(s, tags):
     # tags are : bold, italic, and underline in that order
     processors = ((t, None) for t in tags)
     rs = RunnerStack(None, *processors)
     post_process = '<u><i><b>' + 'some contents' + '</b></i></u>'
     assert rs.run('some contents') == post_process
예제 #6
0
 def test_run_method_returns_value(s, randstr):
     context = None
     processor = (lambda v, c: v), None
     rs = RunnerStack(context, processor)
     assert rs.run(randstr) == randstr