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
commit dc4058ef16
11 changed files with 51 additions and 16 deletions

View File

@ -1345,6 +1345,7 @@ if test x$python_eggs = xtrue; then
else
AC_SUBST(PYTHONEGGINSTALLDIR, "--install-dir $pythoneggdir")
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])
fi
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_PYTHON_EGGS, test x$python_eggs = 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

View File

@ -157,7 +157,7 @@ all|coverage|sonarcloud)
libmysqlclient-dev libsqlite3-dev clearsilver-dev libfcgi-dev
libpcsclite-dev libpam0g-dev binutils-dev libunwind8-dev libnm-dev
libjson-c-dev iptables-dev python-pip libtspi-dev libsystemd-dev"
PYDEPS="pytest"
PYDEPS="tox"
if test "$1" = "deps"; then
build_botan
build_wolfssl

View File

@ -1,3 +1,4 @@
.tox
*.pyc
build
dist

View File

@ -1,2 +1,4 @@
include LICENSE
include README.rst
include tox.ini
recursive-include test *.py

View File

@ -1,7 +1,9 @@
EXTRA_DIST = LICENSE README.rst MANIFEST.in \
setup.py.in \
vici/test/__init__.py \
vici/test/test_protocol.py \
tox.ini \
tox.sh \
test/__init__.py \
test/test_protocol.py \
vici/__init__.py \
vici/command_wrappers.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
endif
if USE_TOX
TESTS_ENVIRONMENT = export TOX=$(TOX);
AM_TESTS_FD_REDIRECT = 1>&2
TESTS = tox.sh
endif
if USE_PY_TEST
TESTS = $(PY_TEST)
endif

View File

@ -24,6 +24,10 @@ setup(
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"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 :: Software Development :: Libraries",
)

View File

@ -1,7 +1,7 @@
import pytest
from ..protocol import Packet, Message, FiniteStream
from ..exception import DeserializationException
from vici.protocol import Packet, Message, FiniteStream
from vici.exception import DeserializationException
class TestPacket(object):
@ -70,17 +70,17 @@ class TestMessage(object):
ser_kv_zero = b"\x03\x0azerolength\x00\x00"
# deserialized messages holding a section
des_sec_single = { "section": {} }
des_sec_nested = { "outer": { "subsection": {} } }
des_sec_single = {"section": {}}
des_sec_nested = {"outer": {"subsection": {}}}
# deserialized messages holding a list
des_list_0_item = { "empty": [] }
des_list_1_item = { "l": [ b"e1" ] }
des_list_2_item = { "l": [ b"e1", b"e2" ] }
des_list_0_item = {"empty": []}
des_list_1_item = {"l": [b"e1"]}
des_list_2_item = {"l": [b"e1", b"e2"]}
# deserialized messages with key value pairs
des_kv_pair = { "key": b"value" }
des_kv_zero = { "zerolength": b"" }
des_kv_pair = {"key": b"value"}
des_kv_zero = {"zerolength": b""}
def test_section_serialization(self):
assert Message.serialize(self.des_sec_single) == self.ser_sec_single
@ -131,7 +131,7 @@ class TestMessage(object):
"sub-section": {
"key2": b"value2",
},
"list1": [ "item1", "item2" ],
"list1": ["item1", "item2"],
},
}
serialized_message = FiniteStream(Message.serialize(message))
@ -141,4 +141,4 @@ class TestMessage(object):
deserialized_section = deserialized_message["section1"]
assert deserialized_message["key1"] == b"value1"
assert deserialized_section["sub-section"]["key2"] == b"value2"
assert deserialized_section["list1"] == [ b"item1", b"item2" ]
assert deserialized_section["list1"] == [b"item1", b"item2"]

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

View File

@ -0,0 +1,3 @@
#!/bin/sh
${TOX} -c ${srcdir} --skip-missing-interpreters

View File

@ -232,7 +232,6 @@ class CommandWrappers(object):
"""
self.request("load-shared", secret)
def unload_shared(self, identifier):
"""Unload a previously loaded shared secret by its unique identifier.