예제 #1
0
 def from_basic(self, data):
     check_length(3, data)
     check_data_type(integer_types, data[0])
     check_data_type(integer_types, data[1])
     check_data_type(list, data[2])
     return Morpher(
         parameter_seed=data[0], template_seed=data[1], data=data[2])
예제 #2
0
 def from_basic(self, data):
     check_length(3, data)
     check_data_type(integer_types, data[0])
     check_data_type(integer_types, data[1])
     if data[1] < self.min_size or data[1] > self.max_size:
         raise BadData("Size %d out of range [%d, %r]" % (data[1], self.min_size, self.max_size))
     if data[0] == 0:
         check_data_type(list, data[2])
         return UniqueListTemplate(
             size=data[1],
             template_seed=0,
             parameter_seed=0,
             parameter=None,
             values=list(map(self.elements.from_basic, data[2])),
         )
     else:
         if data[0] != 1:
             raise BadData("Bad type tag %d" % (data[0],))
         check_length(2, data[2])
         check_data_type(integer_types, data[2][0])
         check_data_type(integer_types, data[2][1])
         parameter_seed = data[2][0]
         random = Random(parameter_seed)
         return UniqueListTemplate(
             size=data[1],
             parameter_seed=parameter_seed,
             template_seed=data[2][1],
             values=None,
             parameter=self.elements.draw_parameter(random),
         )
예제 #3
0
 def from_basic(self, data):
     check_length(3, data)
     check_data_type(integer_types, data[0])
     check_data_type(integer_types, data[1])
     if data[1] < self.min_size or data[1] > self.max_size:
         raise BadData('Size %d out of range [%d, %r]' %
                       (data[1], self.min_size, self.max_size))
     if data[0] == 0:
         check_data_type(list, data[2])
         return UniqueListTemplate(size=data[1],
                                   template_seed=0,
                                   parameter_seed=0,
                                   parameter=None,
                                   values=list(
                                       map(self.elements.from_basic,
                                           data[2])))
     else:
         if data[0] != 1:
             raise BadData('Bad type tag %d' % (data[0], ))
         check_length(2, data[2])
         check_data_type(integer_types, data[2][0])
         check_data_type(integer_types, data[2][1])
         parameter_seed = data[2][0]
         random = Random(parameter_seed)
         return UniqueListTemplate(
             size=data[1],
             parameter_seed=parameter_seed,
             template_seed=data[2][1],
             values=None,
             parameter=self.elements.draw_parameter(random))
예제 #4
0
 def from_basic(self, data):
     check_length(3, data)
     check_data_type(integer_types, data[0])
     check_data_type(integer_types, data[1])
     check_data_type(list, data[2])
     return Morpher(
         parameter_seed=data[0], template_seed=data[1], data=data[2])
예제 #5
0
    def from_basic(self, data):
        check_data_type(list, data)
        check_length(4, data)
        check_data_type(integer_types, data[0])
        check_data_type(integer_types, data[1])
        check_data_type(integer_types, data[2])
        check_data_type(list, data[3])

        if data[2] < 0:
            raise BadData(u'Invalid negative number of steps: %d' % (
                data[2],
            ))
        if data[2] > Settings.default.stateful_step_count * 1000:
            raise BadData(u'Implausibly large number of steps: %d' % (
                data[2],
            ))

        record = []

        for record_data in data[3]:
            if record_data is None:
                record.append(TOMBSTONE)
            else:
                check_data_type(list, record_data)
                check_length(1, record_data)
                record.append((None, record_data[0]))
        return StateMachineRunner(
            parameter_seed=data[0], template_seed=data[1],
            n_steps=data[2],
            record=record,
        )
예제 #6
0
    def from_basic(self, data):
        check_data_type(list, data)
        check_length(4, data)
        check_data_type(integer_types, data[0])
        check_data_type(integer_types, data[1])
        check_data_type(integer_types, data[2])
        check_data_type(list, data[3])

        if data[2] < 0:
            raise BadData('Invalid negative number of steps: %d' % (data[2], ))
        if data[2] > Settings.default.stateful_step_count * 1000:
            raise BadData('Implausibly large number of steps: %d' %
                          (data[2], ))

        record = []

        for record_data in data[3]:
            if record_data is None:
                record.append(TOMBSTONE)
            else:
                check_data_type(list, record_data)
                check_length(1, record_data)
                record.append((None, record_data[0]))
        return StateMachineRunner(
            parameter_seed=data[0],
            template_seed=data[1],
            n_steps=data[2],
            record=record,
        )
예제 #7
0
 def from_basic(self, values):
     check_data_type(list, values)
     check_length(8, values)
     for d in values[:-1]:
         check_data_type(int, d)
     if values[-1] is not None:
         check_data_type(text_type, values[-1])
     return tuple(values)
예제 #8
0
 def from_basic(self, values):
     check_data_type(list, values)
     check_length(8, values)
     for d in values[:-1]:
         check_data_type(int, d)
     if values[-1] is not None:
         check_data_type(text_type, values[-1])
     return tuple(values)
예제 #9
0
 def from_basic(self, data):
     check_data_type(list, data)
     check_length(3, data)
     specifier, random, template = data
     dt = self.specifier_strategy.from_basic(specifier)
     d = self.specifier_strategy.reify(dt)
     vt = self.strategy(d).from_basic(template)
     return DescriptorWithValue(
         random=random, specifier=dt, template=vt, value=None
     )
예제 #10
0
 def from_basic(self, data):
     check_data_type(list, data)
     check_length(3, data)
     specifier, random, template = data
     dt = self.specifier_strategy.from_basic(specifier)
     d = self.specifier_strategy.reify(dt)
     vt = self.strategy(d).from_basic(template)
     return DescriptorWithValue(
         random=random, specifier=dt, template=vt, value=None
     )
예제 #11
0
 def from_basic(self, values):
     check_data_type(list, values)
     check_length(8, values)
     for d in values[:-1]:
         check_data_type(int, d)
     if values[-1] is not None:
         check_data_type(text_type, values[-1])
     template = tuple(values)
     if not self.is_valid_template(template):
         raise BadData('Invalid template %r' % (template, ))
     return template
예제 #12
0
 def from_basic(self, values):
     check_data_type(list, values)
     check_length(8, values)
     for d in values[:-1]:
         check_data_type(int, d)
     if values[-1] is not None:
         check_data_type(text_type, values[-1])
     template = tuple(values)
     if not self.is_valid_template(template):
         raise BadData(u("Invalid template %r") % (template,))
     return template
예제 #13
0
 def from_basic(self, data):
     check_data_type(list, data)
     check_length(3, data)
     check_data_type(integer_types, data[0])
     check_data_type(integer_types, data[1])
     template = self.new_template(data[0], data[1])
     check_data_type(list, data[2])
     changed = list(map(self.source_strategy.from_basic, data[2]))
     template.stream._thunk_to(len(changed))
     assert len(template.stream.fetched) == len(changed)
     template.stream.fetched = changed
     return template
예제 #14
0
 def from_basic(self, data):
     check_data_type(list, data)
     check_length(3, data)
     check_data_type(integer_types, data[0])
     check_data_type(integer_types, data[1])
     template = self.new_template(data[0], data[1])
     check_data_type(list, data[2])
     changed = list(map(self.source_strategy.from_basic, data[2]))
     template.stream._thunk_to(len(changed))
     assert len(template.stream.fetched) == len(changed)
     template.stream.fetched = changed
     return template
예제 #15
0
 def from_basic(self, values):
     check_data_type(list, values)
     values = list(values)
     check_length(8, values)
     for d in values[:-1]:
         check_data_type(int, d)
     if values[-1] is not None:
         check_data_type(text_type, values[-1])
         try:
             values[-1] = pytz.timezone(values[-1])
         except pytz.UnknownTimeZoneError as e:
             raise BadData(*e.args)
     return DateTimeTemplate(*values)
 def from_basic(self, values):
     check_data_type(list, values)
     values = list(values)
     check_length(8, values)
     for d in values[:-1]:
         check_data_type(int, d)
     if values[-1] is not None:
         check_data_type(text_type, values[-1])
         try:
             values[-1] = pytz.timezone(values[-1])
         except pytz.UnknownTimeZoneError as e:
             raise BadData(*e.args)
     return DateTimeTemplate(*values)
예제 #17
0
    def from_basic(self, data):
        check_data_type(list, data)
        if not (1 <= len(data) <= 2):
            raise BadData(u'Expected list of length 1 or 2 but got %r' %
                          (data, ))

        if len(data) == 1:
            return Leaf(self.leaf_strategy.from_basic(data[0]))
        else:
            check_length(2, data)
            check_data_type(list, data[1])
            for v in data[1]:
                check_length(2, v)
            return Branch(label=self.branch_label_strategy.from_basic(data[0]),
                          keyed_children=tuple(
                              (self.branch_key_strategy.from_basic(k),
                               self.from_basic(v)) for k, v in data[1]))
예제 #18
0
    def from_basic(self, data):
        check_data_type(list, data)
        if not (1 <= len(data) <= 2):
            raise BadData(
                'Expected list of length 1 or 2 but got %r' % (data,))

        if len(data) == 1:
            return Leaf(self.leaf_strategy.from_basic(data[0]))
        else:
            check_length(2, data)
            check_data_type(list, data[1])
            for v in data[1]:
                check_length(2, v)
            return Branch(
                label=self.branch_label_strategy.from_basic(data[0]),
                keyed_children=tuple(
                    (self.branch_key_strategy.from_basic(k),
                     self.from_basic(v))
                    for k, v in data[1]))
예제 #19
0
파일: bintree.py 프로젝트: jwg4/hypothesis
    def from_basic(self, data):
        """
        from_basic simply undoes to_basic, but it must satisfy an important
        invariant: It either returns a valid template or it raises BadData.
        Any other exception is a bug in your implementation, as is returning a
        template that can't be used correctly.

        This is important because it maintains the invariant that you can use
        any Hypothesis database without worry about its age or whether the
        strategy implementation has changed since the examples were saved: The
        worst case scenario is that it won't help you, not that it will cause
        problems.
        """
        # check_data_type is a convenience function that raises BadData if the
        # data is not of the specified type.
        check_data_type(list, data)

        if len(data) == 1:
            return (self.leaf_strategy.from_basic(data[0]),)
        else:
            # Same deal: If the length is not 2, raise BadData.
            check_length(2, data)
            return self._make_split(*map(self.from_basic, data))
예제 #20
0
    def from_basic(self, data):
        """
        from_basic simply undoes to_basic, but it must satisfy an important
        invariant: It either returns a valid template or it raises BadData.
        Any other exception is a bug in your implementation, as is returning a
        template that can't be used correctly.

        This is important because it maintains the invariant that you can use
        any Hypothesis database without worry about its age or whether the
        strategy implementation has changed since the examples were saved: The
        worst case scenario is that it won't help you, not that it will cause
        problems.
        """
        # check_data_type is a convenience function that raises BadData if the
        # data is not of the specified type.
        check_data_type(list, data)

        if len(data) == 1:
            return (self.leaf_strategy.from_basic(data[0]),)
        else:
            # Same deal: If the length is not 2, raise BadData.
            check_length(2, data)
            return self._make_split(*map(self.from_basic, data))
예제 #21
0
 def from_basic(self, value):
     check_length(len(self.element_strategies), value)
     return self.newtuple(
         f.from_basic(v)
         for f, v in zip(self.element_strategies, value)
     )
예제 #22
0
 def from_basic(self, value):
     check_length(len(self.element_strategies), value)
     return self.newtuple(
         f.from_basic(v) for f, v in zip(self.element_strategies, value))
예제 #23
0
 def from_basic(self, data):
     check_data_type(text_type, data)
     check_length(1, data)
     return data
예제 #24
0
파일: numpy.py 프로젝트: trowt/hypothesis
 def from_basic(self, data):
     check_data_type(list, data)
     check_length(self.array_size, data)
     return (tuple(map(self.element_strategy.from_basic, data)))
예제 #25
0
파일: numpy.py 프로젝트: jwg4/hypothesis
 def from_basic(self, data):
     check_data_type(list, data)
     check_length(self.array_size, data)
     return (
         tuple(map(self.element_strategy.from_basic, data))
     )