Library containing various Python support classes and functions.
Project description
webkitcorepy
Provides a number of utilities intended to support intermediate to advanced Python programming.
Requirements
The requests, six, and tblib libraries.
Usage
Version representation
from webkitcorepy import Version
version = Version(1, 2, 3)
Unicode stream management, designed to ease transition to Python 3
from webkitcorepy import BytesIO, StringIO, UnicodeIO, unicode
Encoding and decoding byte strings and unicode strings
from webkitcorepy import string_utils
string_utils.encode(...)
string_utils.decode(...)
Automatically install libraries on import.
from webkitcorepy import AutoInstall
AutoInstall.register(Package('requests', Version(2, 24)))
import requests
Mocking basic time and sleep calls
import time
from webkitcorepy import mocks
with mocks.Time:
stamp = time.time()
time.sleep(5)
Capturing stdout, stderr and logging output for testing
capturer = OutputCapture()
with capturer:
print('data\n')
assert capturer.stdout.getvalue() == 'data\n'
Capturing stdout, stderr and logging output for testing
capturer = OutputCapture()
with capturer:
print('data\n')
assert capturer.stdout.getvalue() == 'data\n'
Timeout context:
import time
from webkitcorepy import Timeout
with Timeout(5, handler=RuntimeError('Exceeded 5 second timeout')):
time.sleep(4)
subprocess.run replacement:
import sys
from webkitcorepy import run
result = run([sys.executable, '-c', 'print("message")'], capture_output=True, encoding='utf-8')
Mocking of subprocess commands:
from webkitcorepy import mocks, run
with mocks.Subprocess(
'ls', completion=mocks.ProcessCompletion(returncode=0, stdout='file1.txt\nfile2.txt\n'),
):
result = run(['ls'], capture_output=True, encoding='utf-8')
assert result.returncode == 0
assert result.stdout == 'file1.txt\nfile2.txt\n'
The mocking system for subprocess also supports other subprocess APIs based on Popen:
with mocks.Subprocess(
'ls', completion=mocks.ProcessCompletion(returncode=0, stdout='file1.txt\nfile2.txt\n'),
):
assert subprocess.check_output(['ls']) == b'file1.txt\nfile2.txt\n'
assert subprocess.check_call(['ls']) == 0
For writing integration tests, the mocking system for subprocess supports mocking multiple process calls at the same time:
with mocks.Subprocess(
mocks.Subprocess.CommandRoute('command-a', 'argument', completion=mocks.ProcessCompletion(returncode=0)),
mocks.Subprocess.CommandRoute('command-b', completion=mocks.ProcessCompletion(returncode=-1)),
):
result = run(['command-a', 'argument'])
assert result.returncode == 0
result = run(['command-b'])
assert result.returncode == -1
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file webkitcorepy-1.0.2.tar.gz.
File metadata
- Download URL: webkitcorepy-1.0.2.tar.gz
- Upload date:
- Size: 64.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97ebfddff614a88dad9f3dc7f140a3c58c75e7aa85dc6b7d951fe55f9bcc8579
|
|
| MD5 |
8a0ada62ad98996ffc4633aed2359657
|
|
| BLAKE2b-256 |
e2b05f4b602564b264408139cb9b6d730813032b7f74a65b8acc46d0ce8b9400
|
File details
Details for the file webkitcorepy-1.0.2-py3-none-any.whl.
File metadata
- Download URL: webkitcorepy-1.0.2-py3-none-any.whl
- Upload date:
- Size: 116.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7e8faa2b333e2816b7411f16e47b0c3cc4adb4bafaf75bd02694d7e7ea9500e
|
|
| MD5 |
4b0aa51891a7f099d93078d7d27aba29
|
|
| BLAKE2b-256 |
52346f34cd92baf887c635e0754999fc4d03ac394c2f662b7c00b8ee91b8b717
|