No project description provided
Project description
Maltsev.Repeater
Usage Repeater.Next and returns string:
calls_count: int = 0
def action(multiplier: int) -> str | Repeater.Next:
global calls_count
calls_count += 1
if calls_count == 5:
return 'Hello World!'
else:
print(f'calls_count: {calls_count}, result: {multiplier * calls_count}')
return Repeater.Next()
repeater = Repeater(action=action)
repeater.configure(attempts=10, delay=0.2)
result = repeater.run(multiplier=2)
if result.is_success:
print(result.value)
# output:
# -> calls_count: 1, result: 2
# -> calls_count: 2, result: 4
# -> calls_count: 3, result: 6
# -> calls_count: 4, result: 8
# -> Hello World!
Usage Repeater.Next and Repeater.Fail:
calls_count: int = 0
def action(multiplier: int) -> Repeater.Next | Repeater.Fail:
global calls_count
calls_count += 1
if calls_count == 5:
return Repeater.Fail(message='failed abc')
else:
print(f'calls_count: {calls_count}, result: {multiplier * calls_count}')
return Repeater.Next()
repeater = Repeater(action=action)
repeater.configure(attempts=10, delay=0.2)
result = repeater.run(multiplier=2)
if result.is_success: # not success, because action returns Repeater.Fail
print('is success statement')
print(result.value)
if result.is_failed:
print('is failed statement')
print(result.error_message)
# output:
# -> calls_count: 1, result: 2
# -> calls_count: 2, result: 4
# -> calls_count: 3, result: 6
# -> calls_count: 4, result: 8
# -> is failed statement
# -> failed abc
Usage Repeater.Next and raise AssertionError:
calls_count: int = 0
def action(multiplier: int) -> Repeater.Next:
global calls_count
calls_count += 1
if calls_count == 5:
raise AssertionError('assertion error abc')
else:
print(f'calls_count: {calls_count}, result: {multiplier * calls_count}')
return Repeater.Next()
repeater = Repeater(action=action)
repeater.configure(attempts=10, delay=0.2)
try:
_ = repeater.run(multiplier=2)
except AssertionError as error:
print(error)
# output:
# -> calls_count: 1, result: 2
# -> calls_count: 2, result: 4
# -> calls_count: 3, result: 6
# -> calls_count: 4, result: 8
# -> assertion error abc
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file maltsev_repeater-1.0.1.tar.gz
.
File metadata
- Download URL: maltsev_repeater-1.0.1.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.6 Linux/5.19.0-32-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4eff2951b73513f87f6366e267012dc2eedd82860e39079de7cea25176ac7a59 |
|
MD5 | 656c8f85424e9d20b88f180484336665 |
|
BLAKE2b-256 | 8936a805e2f1bca80e99149868aee9655ded1f7136476d90f8d0139372dacef4 |
File details
Details for the file maltsev_repeater-1.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: maltsev_repeater-1.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.6 Linux/5.19.0-32-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f799485d2c5c6d654fc2838d2b7e5f51cc853c894866d8b65123257251932e9 |
|
MD5 | fa922148480f8e86893af0cfd65682e9 |
|
BLAKE2b-256 | fe09321734237ca5b9bd43f1ad6c2134541e7499a76e95eb1efb9277112ef7ca |