No project description provided
Project description
PyCodeCage
PyCodeCage is a Python library for running code in a sandboxed environment.
Installation
Use the package manager pip to install PyCodeCage.
pip install PyCodeCage
Example
from pycodecage import TestCase, TrustedEnvironment, run_tests
code = """
a = int(input("Enter an integer:"))
if a % 2 != 0 and a > 20:
print("Not Weird")
elif a % 2 != 0:
print("Weird")
elif a % 2 == 0 and 2 <= a <= 5:
print("Not Weird")
elif a % 2 == 0 and 6 <= a <= 20:
print("Weird")
"""
env = TrustedEnvironment(code)
tests = [
TestCase('test1', [1], ['Weird']),
TestCase('test2', [3], ['Weird']),
TestCase('test3', [2], ['Not Weird']),
TestCase('test4', [4], ['Not Weird']),
TestCase('test5', [6], ['Weird']),
TestCase('test6', [8], ['Weird']),
TestCase('test7', [20], ['Weird']),
TestCase('test8', [39], ['Not Weird']),
]
run_tests(tests, env)
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
pycodecage-0.1.1.tar.gz
(3.3 kB
view hashes)
Built Distribution
Close
Hashes for pycodecage-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ccacbd861c30c844b0a64070caec268bca7c9c7490db89b936c53e8c5b1ef4b |
|
MD5 | d3fae87276c174aac3c9cc17a4d298f7 |
|
BLAKE2b-256 | 4d7594567947a1421a1b681906a6f2da617e78d4fcb05201b908739c3f75e44d |