Skip to content

Commit

Permalink
python: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianfreyer committed Jan 2, 2019
1 parent 97a09ec commit 64e5f2c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
6 changes: 5 additions & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ task:
PYPREFIX: py27
install_script: |
pkg install -y curl ${PYTHON_PKG} ${PYPREFIX}-pip
${PYTHON} -m pip install setuptools-rust
${PYTHON} -m pip install setuptools-rust pytest
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly
. $HOME/.cargo/env
build_script: |
export PYTHON_SYS_EXECUTABLE=$(which ${PYTHON})
. $HOME/.cargo/env
cd bindings/python
${PYTHON} setup.py install
test_script: |
. $HOME/.cargo/env
cd bindings/python
${PYTHON} setup.py test
2 changes: 1 addition & 1 deletion bindings/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def run(self):

import subprocess
import sys
errno = subprocess.call([sys.executable, '-m', 'pytest', 'tests'])
errno = subprocess.call(['pytest', '-v', 'tests'])
raise SystemExit(errno)

setup_requires = ['setuptools-rust>=0.10.1']
Expand Down
47 changes: 47 additions & 0 deletions bindings/python/tests/test_jail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import pytest

from jail import StoppedJail, RunningJail


def start_stop(s):
j = s.start()
j.stop()

def test_start_stop_jail(benchmark):
s = StoppedJail('/rescue')

benchmark(start_stop, s)


def get_hostname(j):
return j.parameters['host.hostname']

def test_get_parameter(benchmark):
s = StoppedJail('/rescue', parameters={'host.hostname': 'test'})
j = s.start()
hostname = benchmark(get_hostname, j)
assert hostname == 'test'
j.stop()


def spawn_hello_world(j):
child = j.spawn(['/echo', 'hello world'])
child.wait()

def test_spawn(benchmark):
s = StoppedJail('/rescue')
j = s.start()
benchmark(spawn_hello_world, j)
j.stop()


import subprocess
def popen_hello_world(j):
child = subprocess.Popen(['/echo', 'hello world'], preexec_fn=lambda: j.attach())
child.wait()

def test_popen(benchmark):
s = StoppedJail('/rescue')
j = s.start()
benchmark(popen_hello_world, j)
j.stop()
21 changes: 21 additions & 0 deletions bindings/python/tests/wqal
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest

from jail import StoppedJail, RunningJail

def test_start_stop_jail(benchmark):
s = StoppedJail('/rescue')

def start_stop():
j = s.start()
j.stop()

benchmark(start_stop)

def test_get_parameter(benchmark):
s = StoppedJail('/rescue', params=dict(hostname='test'))
j = s.start()

hostname = benchmark(lambda: j.params['hostname'])
assert hostname == 'test'

j.stop()

0 comments on commit 64e5f2c

Please sign in to comment.