Beispiel #1
0
    def run(self, state_machine, print_steps=None):
        if print_steps is None:
            print_steps = current_verbosity() >= Verbosity.debug

        try:
            for i in hrange(self.n_steps):
                strategy = state_machine.steps()

                template_set = False
                if i < len(self.record):
                    if self.record[i] is TOMBSTONE:
                        continue
                    _, data = self.record[i]
                    data = list(data)
                    for data_index in hrange(len(data) - 1, -1, -1):
                        try:
                            template = strategy.from_basic(data[data_index])
                            template_set = True
                            break
                        except BadData:
                            pass
                    if template_set:
                        data[data_index], data[-1] = (
                            data[-1], data[data_index]
                        )
                else:
                    data = []
                if not template_set:
                    parameter = strategy.draw_parameter(Random(
                        self.parameter_seed
                    ))
                    template = strategy.draw_template(
                        Random(self.templates[i]), parameter)
                    data.append(strategy.to_basic(template))

                new_record = (
                    strategy, data,
                )
                if i < len(self.record):
                    self.record[i] = new_record
                else:
                    self.record.append(new_record)

                strategy.from_basic(self.record[i][1][-1])
                value = strategy.reify(template)

                if print_steps:
                    state_machine.print_step(value)
                state_machine.execute_step(value)
        finally:
            state_machine.teardown()
Beispiel #2
0
    def run(self, state_machine, print_steps=None):
        if print_steps is None:
            print_steps = current_verbosity() >= Verbosity.debug

        try:
            for i in hrange(self.n_steps):
                strategy = state_machine.steps()

                template_set = False
                if i < len(self.record):
                    if self.record[i] is TOMBSTONE:
                        continue
                    _, data = self.record[i]
                    data = list(data)
                    for data_index in hrange(len(data) - 1, -1, -1):
                        try:
                            template = strategy.from_basic(data[data_index])
                            template_set = True
                            break
                        except BadData:
                            pass
                    if template_set:
                        data[data_index], data[-1] = (
                            data[-1], data[data_index]
                        )
                else:
                    data = []
                if not template_set:
                    parameter = strategy.draw_parameter(Random(
                        self.parameter_seed
                    ))
                    template = strategy.draw_template(
                        Random(self.templates[i]), parameter)
                    data.append(strategy.to_basic(template))

                new_record = (
                    strategy, data,
                )
                if i < len(self.record):
                    self.record[i] = new_record
                else:
                    self.record.append(new_record)

                strategy.from_basic(self.record[i][1][-1])
                value = strategy.reify(template)

                if print_steps:
                    state_machine.print_step(value)
                state_machine.execute_step(value)
        finally:
            state_machine.teardown()
Beispiel #3
0
 def simplifiers(self, random, template):
     yield self.cut_steps
     yield self.random_discards
     yield self.delete_elements
     for i in hrange(len(template.record)):
         if template.record[i] != TOMBSTONE:
             strategy, data = template.record[i]
             if strategy is None:
                 continue
             child_template = strategy.from_basic(data[-1])
             for simplifier in strategy.simplifiers(random, child_template):
                 yield self.convert_simplifier(strategy, simplifier, i)
Beispiel #4
0
 def simplifiers(self, random, template):
     yield self.cut_steps
     yield self.random_discards
     yield self.delete_elements
     for i in hrange(len(template.record)):
         if template.record[i] != TOMBSTONE:
             strategy, data = template.record[i]
             if strategy is None:
                 continue
             child_template = strategy.from_basic(data[-1])
             for simplifier in strategy.simplifiers(random, child_template):
                 yield self.convert_simplifier(strategy, simplifier, i)
Beispiel #5
0
        def accept(random, template):
            if i >= len(template.record):
                return
            if template.record[i][0] is not strategy:
                return

            reconstituted = strategy.from_basic(template.record[i][1][-1])

            for t in simplifier(random, reconstituted):
                new_record = list(template.record)
                existing = new_record[i]
                new_record[i] = (existing[0], list(existing[1]))
                new_record[i][1][-1] = strategy.to_basic(t)
                yield StateMachineRunner(
                    parameter_seed=template.parameter_seed,
                    template_seed=template.template_seed,
                    templates=template.templates,
                    n_steps=template.n_steps,
                    record=new_record,
                )
Beispiel #6
0
        def accept(random, template):
            if i >= len(template.record):
                return
            if template.record[i][0] is not strategy:
                return

            reconstituted = strategy.from_basic(template.record[i][1][-1])

            for t in simplifier(random, reconstituted):
                new_record = list(template.record)
                existing = new_record[i]
                new_record[i] = (existing[0], list(existing[1]))
                new_record[i][1][-1] = strategy.to_basic(t)
                yield StateMachineRunner(
                    parameter_seed=template.parameter_seed,
                    template_seed=template.template_seed,
                    templates=template.templates,
                    n_steps=template.n_steps,
                    record=new_record,
                )