예제 #1
0
def apply_fixer_diff(original_diffs, fixer_diff, strategy_context):
    """Apply the relevant changes from fixer_diff

    Using the original_diff and fixer_diff, find the intersecting
    changes and delegate to the requested workflow strategy
    to apply and commit the changes.
    """
    if 'strategy' not in strategy_context:
        raise ConfigurationError('Missing `workflow` configuration.')

    strategy = strategy_context['strategy']
    if strategy not in workflow_strategies:
        raise ConfigurationError(u'Unknown workflow `{}`'.format(strategy))

    try:
        log.info('Using %s workflow to apply fixer changes', strategy)
        workflow = workflow_strategies[strategy](strategy_context)
    except Exception as e:
        msg = u'Could not create {} workflow. Got {}'.format(strategy, e)
        raise ConfigurationError(msg)

    changes_to_apply = find_intersecting_diffs(original_diffs, fixer_diff)
    if len(changes_to_apply) == 0:
        log.info('No intersecting changes found. Skipping fixer workflow.')
        return
    workflow.execute(changes_to_apply)
예제 #2
0
 def test_run_tools__fixer_errors(self):
     error_message = 'A bad thing'
     cases = (
         WorkflowError(error_message),
         ConfigurationError(error_message)
     )
     for case in cases:
         yield self._test_run_tools_fixer_error_scenario, case
예제 #3
0
 def test_run_tools_fixer_error_scenario(self):
     errors = [
         WorkflowError('A bad workflow thing'),
         ConfigurationError('A bad configuration thing'),
     ]
     for error in errors:
         self.tool_stub.reset()
         self.fixer_stub.reset()
         self._test_run_tools_fixer_error_scenario(error)