Merge branch 'vici-pytest'

Adds tox.ini to test with tox (which is now used on Travis) and includes
the tests in the source distribution.
This commit is contained in:
Tobias Brunner
2020-01-14 16:53:53 +01:00
11 changed files with 51 additions and 16 deletions
+3 -1
View File
@@ -1345,6 +1345,7 @@ if test x$python_eggs = xtrue; then
else else
AC_SUBST(PYTHONEGGINSTALLDIR, "--install-dir $pythoneggdir") AC_SUBST(PYTHONEGGINSTALLDIR, "--install-dir $pythoneggdir")
fi fi
AC_PATH_PROG([TOX], [tox], [], [$PATH:/bin:/usr/bin:/usr/local/bin])
AC_PATH_PROG([PY_TEST], [py.test], [], [$PATH:/bin:/usr/bin:/usr/local/bin]) AC_PATH_PROG([PY_TEST], [py.test], [], [$PATH:/bin:/usr/bin:/usr/local/bin])
fi fi
AM_CONDITIONAL(PYTHON_EGGS_INSTALL, [test "x$python_eggs_install" = xtrue]) AM_CONDITIONAL(PYTHON_EGGS_INSTALL, [test "x$python_eggs_install" = xtrue])
@@ -1764,7 +1765,8 @@ AM_CONDITIONAL(USE_LEGACY_SYSTEMD, test -n "$systemdsystemunitdir" -a "x$systemd
AM_CONDITIONAL(USE_RUBY_GEMS, test x$ruby_gems = xtrue) AM_CONDITIONAL(USE_RUBY_GEMS, test x$ruby_gems = xtrue)
AM_CONDITIONAL(USE_PYTHON_EGGS, test x$python_eggs = xtrue) AM_CONDITIONAL(USE_PYTHON_EGGS, test x$python_eggs = xtrue)
AM_CONDITIONAL(USE_PERL_CPAN, test x$perl_cpan = xtrue) AM_CONDITIONAL(USE_PERL_CPAN, test x$perl_cpan = xtrue)
AM_CONDITIONAL(USE_PY_TEST, test "x$PY_TEST" != x) AM_CONDITIONAL(USE_TOX, test "x$TOX" != x)
AM_CONDITIONAL(USE_PY_TEST, test "x$PY_TEST" != x -a "x$TOX" = x)
# ======================== # ========================
# set global definitions # set global definitions
+1 -1
View File
@@ -157,7 +157,7 @@ all|coverage|sonarcloud)
libmysqlclient-dev libsqlite3-dev clearsilver-dev libfcgi-dev libmysqlclient-dev libsqlite3-dev clearsilver-dev libfcgi-dev
libpcsclite-dev libpam0g-dev binutils-dev libunwind8-dev libnm-dev libpcsclite-dev libpam0g-dev binutils-dev libunwind8-dev libnm-dev
libjson-c-dev iptables-dev python-pip libtspi-dev libsystemd-dev" libjson-c-dev iptables-dev python-pip libtspi-dev libsystemd-dev"
PYDEPS="pytest" PYDEPS="tox"
if test "$1" = "deps"; then if test "$1" = "deps"; then
build_botan build_botan
build_wolfssl build_wolfssl
@@ -1,3 +1,4 @@
.tox
*.pyc *.pyc
build build
dist dist
@@ -1,2 +1,4 @@
include LICENSE include LICENSE
include README.rst include README.rst
include tox.ini
recursive-include test *.py
+10 -2
View File
@@ -1,7 +1,9 @@
EXTRA_DIST = LICENSE README.rst MANIFEST.in \ EXTRA_DIST = LICENSE README.rst MANIFEST.in \
setup.py.in \ setup.py.in \
vici/test/__init__.py \ tox.ini \
vici/test/test_protocol.py \ tox.sh \
test/__init__.py \
test/test_protocol.py \
vici/__init__.py \ vici/__init__.py \
vici/command_wrappers.py \ vici/command_wrappers.py \
vici/compat.py \ vici/compat.py \
@@ -37,6 +39,12 @@ install-exec-local: dist/vici-$(PYTHON_PACKAGE_VERSION)-py$(PYTHON_VERSION).egg
dist/vici-$(PYTHON_PACKAGE_VERSION)-py$(PYTHON_VERSION).egg dist/vici-$(PYTHON_PACKAGE_VERSION)-py$(PYTHON_VERSION).egg
endif endif
if USE_TOX
TESTS_ENVIRONMENT = export TOX=$(TOX);
AM_TESTS_FD_REDIRECT = 1>&2
TESTS = tox.sh
endif
if USE_PY_TEST if USE_PY_TEST
TESTS = $(PY_TEST) TESTS = $(PY_TEST)
endif endif
@@ -24,6 +24,10 @@ setup(
"Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Security", "Topic :: Security",
"Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries",
) )
@@ -1,7 +1,7 @@
import pytest import pytest
from ..protocol import Packet, Message, FiniteStream from vici.protocol import Packet, Message, FiniteStream
from ..exception import DeserializationException from vici.exception import DeserializationException
class TestPacket(object): class TestPacket(object):
@@ -70,17 +70,17 @@ class TestMessage(object):
ser_kv_zero = b"\x03\x0azerolength\x00\x00" ser_kv_zero = b"\x03\x0azerolength\x00\x00"
# deserialized messages holding a section # deserialized messages holding a section
des_sec_single = { "section": {} } des_sec_single = {"section": {}}
des_sec_nested = { "outer": { "subsection": {} } } des_sec_nested = {"outer": {"subsection": {}}}
# deserialized messages holding a list # deserialized messages holding a list
des_list_0_item = { "empty": [] } des_list_0_item = {"empty": []}
des_list_1_item = { "l": [ b"e1" ] } des_list_1_item = {"l": [b"e1"]}
des_list_2_item = { "l": [ b"e1", b"e2" ] } des_list_2_item = {"l": [b"e1", b"e2"]}
# deserialized messages with key value pairs # deserialized messages with key value pairs
des_kv_pair = { "key": b"value" } des_kv_pair = {"key": b"value"}
des_kv_zero = { "zerolength": b"" } des_kv_zero = {"zerolength": b""}
def test_section_serialization(self): def test_section_serialization(self):
assert Message.serialize(self.des_sec_single) == self.ser_sec_single assert Message.serialize(self.des_sec_single) == self.ser_sec_single
@@ -131,7 +131,7 @@ class TestMessage(object):
"sub-section": { "sub-section": {
"key2": b"value2", "key2": b"value2",
}, },
"list1": [ "item1", "item2" ], "list1": ["item1", "item2"],
}, },
} }
serialized_message = FiniteStream(Message.serialize(message)) serialized_message = FiniteStream(Message.serialize(message))
@@ -141,4 +141,4 @@ class TestMessage(object):
deserialized_section = deserialized_message["section1"] deserialized_section = deserialized_message["section1"]
assert deserialized_message["key1"] == b"value1" assert deserialized_message["key1"] == b"value1"
assert deserialized_section["sub-section"]["key2"] == b"value2" assert deserialized_section["sub-section"]["key2"] == b"value2"
assert deserialized_section["list1"] == [ b"item1", b"item2" ] assert deserialized_section["list1"] == [b"item1", b"item2"]
+16
View File
@@ -0,0 +1,16 @@
[tox]
envlist = py27, py35, py36, py37, py38
[testenv]
deps =
pytest
pytest-pycodestyle
commands = pytest --pycodestyle
[testenv:py27]
deps = pytest
commands = pytest
[pycodestyle]
max-line-length = 80
show-source = True
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
${TOX} -c ${srcdir} --skip-missing-interpreters
@@ -232,7 +232,6 @@ class CommandWrappers(object):
""" """
self.request("load-shared", secret) self.request("load-shared", secret)
def unload_shared(self, identifier): def unload_shared(self, identifier):
"""Unload a previously loaded shared secret by its unique identifier. """Unload a previously loaded shared secret by its unique identifier.