def worked(self, work: float): assert_condition(self._state_stack, 'worked() method call is missing a current context') assert_condition(work > 0, 'work must be greater than zero') for s in reversed(self._state_stack): s.inc_work(work) work = s.to_super_work(work) self.emit_update()
def __init__(self, label: str, total_work: float): assert_given(label, 'label') assert_condition(total_work > 0, 'total_work must be greater than zero') self.label = label self.total_work = total_work self.state: Optional[ProgressState] = None
def __init__(self, **store_params): self._s3, store_params = S3Mixin.consume_s3fs_params(store_params) self._bucket_name, store_params = S3Mixin.consume_bucket_name_param( store_params) assert_given(self._bucket_name, 'bucket_name') assert_condition( not store_params, f'Unknown keyword arguments: {", ".join(store_params.keys())}')
def __init__(self, callback_config: CallbackConfig, minimum: float = 0, dt: float = 1, timeout: float = False): super().__init__(minimum=minimum, dt=dt, timeout=timeout) assert_condition( callback_config.api_uri and callback_config.access_token, "Both, api_uri and access_token must be given.") self.callback_config = callback_config
def __init__(self, store_id: str = None, opener_id: str = None, data_id: str = None, store_params: Mapping[str, Any] = None, open_params: Mapping[str, Any] = None): assert_condition(store_id or opener_id, 'One of store_id and opener_id must be given') assert_given(data_id, 'data_id') self.store_id = store_id self.opener_id = opener_id self.data_id = data_id self.store_params = store_params or {} self.open_params = open_params or {}
def __init__(self, label: str, total_work: float, interval: float = 0.1, initial_interval: float = 0): super().__init__() assert_given(label, 'label') assert_condition(total_work > 0, 'total_work must be greater than zero') self._label = label self._total_work = total_work self._state: Optional[ProgressState] = None self._initial_interval = initial_interval self._interval = interval self._last_worked = 0 self._running = False
def __init__(self, store_id: str = None, writer_id: str = None, data_id: str = None, store_params: Mapping[str, Any] = None, write_params: Mapping[str, Any] = None, replace: bool = None): assert_condition(store_id or writer_id, 'One of store_id and writer_id must be given') self.store_id = store_id self.writer_id = writer_id self.data_id = data_id self.store_params = store_params or {} self.write_params = write_params or {} self.replace = replace
def __init__(self, minimum: float = 0, dt: float = 1, timeout: float = None): """ :type dt: float :type minimum: float """ super().__init__() assert_condition(dt >= 0, "The timer's time step must be >=0") assert_condition(minimum >= 0, "The timer's minimum must be >=0") self._running = False self._start_time = None self._minimum = minimum self._dt = dt self._width = 100 self._current_sender = None self._state_stack: [ProgressState] = [] self._timeout = timeout
def __init__(self, input_config: InputConfig = None, input_configs: Sequence[InputConfig] = None, cube_config: CubeConfig = None, output_config: OutputConfig = None, callback_config: Optional[CallbackConfig] = None): assert_condition( input_config or input_configs, 'one of input_config and input_configs must be given') assert_condition( not (input_config and input_configs), 'input_config and input_configs cannot be given both') if input_config: input_configs = [input_config] assert_given(input_configs, 'input_configs') assert_given(cube_config, 'cube_config') assert_given(output_config, 'output_config') self.input_configs = input_configs self.cube_config = cube_config self.output_config = output_config self.callback_config = callback_config
def _assert_used_correctly(self): assert_condition(self._state is not None, 'observe_progress() must be used with "with" statement')
def will_work(self, work: float): assert_condition(self._state_stack, 'will_work() method call is missing a current context') # noinspection PyProtectedMember self._state_stack[-1].super_work_ahead = work
def inc_work(self, work: float): assert_condition(work > 0, 'work must be greater than zero') self._completed_work += work
def super_work_ahead(self, work: float): assert_condition(work > 0, 'work must be greater than zero') self._super_work_ahead = work
def __init__(self, api_uri: str = None, access_token: str = None): assert_condition(api_uri and access_token, 'Both, api_uri and access_token must be given') self.api_uri = api_uri self.access_token = access_token
def test_assert_condition(self): assert_condition(True, 'Should be true') with self.assertRaises(ValueError) as e: assert_condition(False, 'Should be true') self.assertEqual(('Should be true', ), e.exception.args)