Skip to main content

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 mock, requests and six libraries.

Usage

Version representation

from webkitcorepy import Version
version = Version(1, 2, 3)

Unicode stream management across Python 2 and 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

webkitcorepy-1.0.0.tar.gz (58.6 kB view details)

Uploaded Source

Built Distribution

webkitcorepy-1.0.0-py3-none-any.whl (110.7 kB view details)

Uploaded Python 3

File details

Details for the file webkitcorepy-1.0.0.tar.gz.

File metadata

  • Download URL: webkitcorepy-1.0.0.tar.gz
  • Upload date:
  • Size: 58.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.6

File hashes

Hashes for webkitcorepy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 881512adff9c11f5d0f40f07115e2e0adcd4a50ffd5342d9c2c2085d9bfb5173
MD5 21de449a07aebd1f8cb4dadd48f0e186
BLAKE2b-256 26751401e3da65f927716be5edc812cb033e1f660ae457e3ef479c9b6ff53e8e

See more details on using hashes here.

File details

Details for the file webkitcorepy-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: webkitcorepy-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 110.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.6

File hashes

Hashes for webkitcorepy-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4aaea1bb7ce9e23df8463be9f601d6c0472b735d63436af6a9fbe25c8c858f1
MD5 c62aec8480a110b0ec9edce858ca8df6
BLAKE2b-256 1e2c4cf039728aa24e4b8e3b2b7370ffc4deab309c93765eaf15208558b171e7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page