Esempio n. 1
0
def build_mutator(cfg):
    operators_set = set()

    if cfg.experimental_operators:
        operators_set |= operators.experimental_operators

    name_to_operator = build_name_to_operator_map()

    if cfg.operator:
        operators_set |= {
            get_operator(name, name_to_operator)
            for name in cfg.operator
        }
    else:
        operators_set |= operators.standard_operators

    operators_set -= {
        get_operator(name, name_to_operator)
        for name in cfg.disable_operator
    }

    if cfg.order == 1:
        return controller.FirstOrderMutator(operators_set, cfg.percentage)
    else:
        hom_strategy = build_hom_strategy(cfg)
        return controller.HighOrderMutator(operators_set,
                                           cfg.percentage,
                                           hom_strategy=hom_strategy)
Esempio n. 2
0
 def setUp(self):
     target_loader = MockModulesLoader('target', self.TARGET_SRC)
     test_loader = MockModulesLoader('test', self.TEST_SRC)
     self.score_view = MutationScoreStoreView()
     mutator = controller.FirstOrderMutator(
         [operators.ArithmeticOperatorReplacement], percentage=100)
     self.mutation_controller = MockMutationController(
         target_loader=target_loader,
         test_loader=test_loader,
         views=[self.score_view],
         mutant_generator=mutator,
         mutate_covered=True,
     )
Esempio n. 3
0
    def test_first_order_mutation(self):
        mutator = controller.FirstOrderMutator(
            operators=[operators.ArithmeticOperatorReplacement, operators.AssignmentOperatorReplacement],
        )
        target_ast = utils.create_ast('x += y + z')

        for number, (mutations, mutant) in enumerate(mutator.mutate(target_ast)):
            self.assertIn(number, [0, 1])
            self.assertEqual(len(mutations), 1)
            if number == 0:
                self.assertEqual('x += y - z', codegen.to_source(mutant))
            elif number == 1:
                self.assertEqual('x -= y + z', codegen.to_source(mutant))

        self.assertEqual(codegen.to_source(target_ast), 'x += y + z')