Exemplo n.º 1
0
    def test_code_mutator_with_filter(self):
        def line_filter(line, line_no):
            return line_no % 2 == 1

        code = "x = 1\ny = 2\nz = 3\nw = 4"
        mutators = [mutator.NumberMutator]
        mutations = list(mutator.code_mutator(mutators, code, line_filter))
        self.assertEquals(["x = 2\ny = 2\nz = 3\nw = 4",
                           "x = 1\ny = 2\nz = 4\nw = 4"],
                          [codegen.to_source(m) for line_no, pos, m, class_name in mutations])
Exemplo n.º 2
0
    def test_code_mutator_multiple_classes(self):
        def line_filter(line, line_no):
            return True

        code = "x = 1\ny = True"
        mutators = [mutator.NumberMutator, mutator.BooleanMutator]
        mutations = list(mutator.code_mutator(mutators, code, line_filter))
        self.assertEquals(["x = 2\ny = True",
                           "x = 1\ny = False"],
                          [codegen.to_source(m) for line_no, pos, m, class_name in mutations])