def test_bad_calls(self): bad_args = [[], [1], [1, 2], [None, 1, .1], [1, None, .1], [1, 2, 'not too far']] for args in bad_args: with self.assertRaises(Exception): permissive_range(*args)
def _add_slice(self, slice_: slice) -> None: if slice_.start is None or slice_.stop is None or slice_.step is None: raise TypeError( "all 3 slice parameters are required, " + f"{slice_} is missing some" ) p_range = permissive_range(slice_.start, slice_.stop, slice_.step) self._values.extend(p_range)
def test_good_calls(self): good_args = { (1, 7, 2): [1, 3, 5], (1, 7, 4): [1, 5], (1, 7, 7): [1], (1.0, 7, 2): [1.0, 3.0, 5.0], (1, 7.0, 2): [1.0, 3.0, 5.0], (1, 7, 2.0): [1.0, 3.0, 5.0], (1.0, 7.0, 2.0): [1.0, 3.0, 5.0], (1.0, 7.000000001, 2.0): [1.0, 3.0, 5.0, 7.0], (1, 7, -2): [1, 3, 5], (7, 1, 2): [7, 5, 3], (1.0, 7.0, -2.0): [1.0, 3.0, 5.0], (7.0, 1.0, 2.0): [7.0, 5.0, 3.0], (7.0, 1.0, -2.0): [7.0, 5.0, 3.0], (1.5, 1.8, 0.1): [1.5, 1.6, 1.7] } for args, result in good_args.items(): self.assertEqual(permissive_range(*args), result)
def _sweep_steps(self, value): oldest_ok_val = datetime.now() - timedelta(seconds=self._max_val_age) state = self._latest() if state['ts'] is None or state['ts'] < oldest_ok_val: start_value = self.get() else: start_value = state['value'] self.validate(start_value) if not (isinstance(start_value, (int, float)) and isinstance(value, (int, float))): # something weird... parameter is numeric but one of the ends # isn't, even though it's valid. # probably a MultiType with a mix of numeric and non-numeric types # just set the endpoint and move on logging.warning('cannot sweep {} from {} to {} - jumping.'.format( self.name, start_value, value)) return [] # drop the initial value, we're already there return permissive_range(start_value, value, self._step)[1:]
def test_good_calls(self): # TODO(giulioungaretti) # not sure what we are testing here. # in pyhton 1.0 and 1 are actually the same # https://docs.python.org/3.5/library/functions.html#hash good_args = { (1, 7, 2): [1, 3, 5], (1, 7, 4): [1, 5], (1, 7, 7): [1], (1.0, 7, 2): [1.0, 3.0, 5.0], (1, 7.0, 2): [1.0, 3.0, 5.0], (1, 7, 2.0): [1.0, 3.0, 5.0], (1.0, 7.0, 2.0): [1.0, 3.0, 5.0], (1.0, 7.000000001, 2.0): [1.0, 3.0, 5.0, 7.0], (1, 7, -2): [1, 3, 5], (7, 1, 2): [7, 5, 3], (1.0, 7.0, -2.0): [1.0, 3.0, 5.0], (7.0, 1.0, 2.0): [7.0, 5.0, 3.0], (7.0, 1.0, -2.0): [7.0, 5.0, 3.0], (1.5, 1.8, 0.1): [1.5, 1.6, 1.7] } for args, result in good_args.items(): self.assertEqual(permissive_range(*args), result)
def _add_slice(self, slice_): if slice_.start is None or slice_.stop is None or slice_.step is None: raise TypeError('all 3 slice parameters are required, ' + '{} is missing some'.format(slice_)) p_range = permissive_range(slice_.start, slice_.stop, slice_.step) self._values.extend(p_range)
def test_good_calls(args, result): # TODO(giulioungaretti) # not sure what we are testing here. # in python 1.0 and 1 are actually the same # https://docs.python.org/3.5/library/functions.html#hash assert permissive_range(*args) == result
def test_bad_calls(args): with pytest.raises(Exception): permissive_range(*args)