Browse Source

Rebuild and fix pytest based tests in new dir tests_new. To work with defined env for engine using separate process per test.

master
heck 5 years ago
parent
commit
e3c53a0d3c
  1. 3
      Makefile
  2. 8
      pyproject.toml
  3. 3
      setup.cfg
  4. 16
      tests_new/conftest.py
  5. 3
      tests_new/constants.py
  6. 0
      tests_new/data/README.md
  7. 0
      tests_new/data/alice@openpgp.example.pub.asc
  8. 0
      tests_new/data/alice@openpgp.example.sec.asc
  9. 0
      tests_new/data/bob@openpgp.example.pub.asc
  10. 0
      tests_new/data/bob@openpgp.example.sec.asc
  11. 8
      tests_new/test_identity.py
  12. 9
      tests_new/test_message.py
  13. 2
      tests_new/test_pep.py

3
Makefile

@ -57,8 +57,9 @@ envtest:
install-test: compile install-test: compile
pip3 install .[test] pip3 install .[test]
# TODO: maybe use setup.py test?
test: install-test test: install-test
pytest pytest --forked
# Development # Development

8
pyproject.toml

@ -1,3 +1,11 @@
[build-system] [build-system]
requires = ["setuptools >=39.2.0", "setuptools_scm >= 4.1.2", "wheel >= 0.35.1"] requires = ["setuptools >=39.2.0", "setuptools_scm >= 4.1.2", "wheel >= 0.35.1"]
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"
[tool.pytest.ini_options]
minversion = "6.0"
addopts = ""
testpaths = [
"tests_new",
]

3
setup.cfg

@ -28,7 +28,7 @@ classifiers =
zip_safe = false zip_safe = false
include_package_data = true include_package_data = true
python_requires = >= 3.6 python_requires = >= 3.6
test_suite = tests test_suite = tests_new
install_requires = install_requires =
# deprecated/redundant with pyproject.toml, but lets keep both ways around for now # deprecated/redundant with pyproject.toml, but lets keep both ways around for now
setup_requires = setup_requires =
@ -39,4 +39,5 @@ setup_requires =
# To install these dependencies, run pip install .[test] # To install these dependencies, run pip install .[test]
test = test =
pytest pytest
pytest-forked
doc = sphinx doc = sphinx

16
tests/conftest.py → tests_new/conftest.py

@ -1,4 +1,5 @@
"""pytest configuration for the unit tests.""" """pytest configuration for the unit tests."""
import os import os
import pytest import pytest
@ -28,14 +29,15 @@ def datadir(request):
return D(request.fspath.dirpath("data")) return D(request.fspath.dirpath("data"))
@pytest.fixture(scope='function') @pytest.fixture()
def tmpdir(tmpdir_factory, request): def ctx_init(tmpdir_factory, request):
"""Create a tmp dir for the tests""" """Create a tmp dir for the tests"""
base = str(hash(request.node.nodeid))[:3] base = str(abs(hash(request.node.nodeid)))[:3]
bn = tmpdir_factory.mktemp(base) bn = tmpdir_factory.mktemp(base)
print(bn)
import os import os
os.environ["PEP_HOME"] = str(bn)
os.environ["HOME"] = str(bn) os.environ["HOME"] = str(bn)
return bn
@pytest.fixture() @pytest.fixture()
@ -51,8 +53,7 @@ def bob_pub_key_data(datadir):
@pytest.fixture() @pytest.fixture()
def create_alice_identity(tmpdir, alice_sec_key_data, bob_pub_key_data): def create_alice_identity(ctx_init, alice_sec_key_data):
os.environ["HOME"] = str(tmpdir)
import pEp import pEp
pEp.import_key(alice_sec_key_data) pEp.import_key(alice_sec_key_data)
@ -65,8 +66,7 @@ def create_alice_identity(tmpdir, alice_sec_key_data, bob_pub_key_data):
@pytest.fixture() @pytest.fixture()
def create_bob_identity(tmpdir, bob_pub_key_data): def create_bob_identity(ctx_init, bob_pub_key_data):
os.environ["HOME"] = str(tmpdir)
import pEp import pEp
pEp.import_key(bob_pub_key_data) pEp.import_key(bob_pub_key_data)

3
tests/constants.py → tests_new/constants.py

@ -16,8 +16,7 @@ BOB_NAME_ADDR = NAME_ADDR.format(BOB_NAME, ANGLE_ADDR.format(BOB_ADDRESS))
ALICE_NAME = "Alice Lovelace" ALICE_NAME = "Alice Lovelace"
ALICE_ADDRESS = "alice@openpgp.example" ALICE_ADDRESS = "alice@openpgp.example"
ALICE_FP = "EB85BB5FA33A75E15E944E63F231550C4F47E38E" ALICE_FP = "EB85BB5FA33A75E15E944E63F231550C4F47E38E"
ALICE_NAME_ADDR = NAME_ADDR.format(ALICE_NAME, ALICE_NAME_ADDR = NAME_ADDR.format(ALICE_NAME, ANGLE_ADDR.format(ALICE_ADDRESS))
ANGLE_ADDR.format(ALICE_ADDRESS))
SUBJECT = "This is a subject" SUBJECT = "This is a subject"
BODY = "Hi world!\n" BODY = "Hi world!\n"

0
tests/data/README.md → tests_new/data/README.md

0
tests/data/alice@openpgp.example.pub.asc → tests_new/data/alice@openpgp.example.pub.asc

0
tests/data/alice@openpgp.example.sec.asc → tests_new/data/alice@openpgp.example.sec.asc

0
tests/data/bob@openpgp.example.pub.asc → tests_new/data/bob@openpgp.example.pub.asc

0
tests/data/bob@openpgp.example.sec.asc → tests_new/data/bob@openpgp.example.sec.asc

8
tests/test_identity.py → tests_new/test_identity.py

@ -4,7 +4,7 @@ import os
from . import constants from . import constants
def test_create_one_identity_succeed(tmpdir): def test_create_one_identity_succeed(ctx_init):
# It has to be imported here to get the management db initialized, # It has to be imported here to get the management db initialized,
import pEp import pEp
alice = pEp.Identity() alice = pEp.Identity()
@ -43,8 +43,7 @@ def test_create_one_identity_succeed(tmpdir):
assert alice.flags == expected_alice.flags assert alice.flags == expected_alice.flags
def test_two_identities_succeed(tmpdir, bob_pub_key_data): def test_two_identities_succeed(ctx_init, bob_pub_key_data):
os.environ["HOME"] = str(tmpdir)
import pEp import pEp
alice = pEp.Identity( alice = pEp.Identity(
@ -88,8 +87,7 @@ def test_two_identities_succeed(tmpdir, bob_pub_key_data):
assert bob.flags == 0 assert bob.flags == 0
def test_set_own_key(tmpdir, alice_sec_key_data): def test_set_own_key(ctx_init, alice_sec_key_data):
os.environ["HOME"] = str(tmpdir)
import pEp import pEp
pEp.import_key(alice_sec_key_data) pEp.import_key(alice_sec_key_data)

9
tests/test_message.py → tests_new/test_message.py

@ -30,8 +30,7 @@ def test_msg_enc_dec_roundtrip(create_alice_identity, create_bob_identity):
assert str(enc_msg.from_) == constants.ALICE_NAME_ADDR assert str(enc_msg.from_) == constants.ALICE_NAME_ADDR
assert str(enc_msg.to[0]) == constants.BOB_NAME_ADDR assert str(enc_msg.to[0]) == constants.BOB_NAME_ADDR
assert enc_msg.shortmsg == "p≡p" assert enc_msg.shortmsg == "p≡p"
assert enc_msg.longmsg == \ assert enc_msg.longmsg == "this message was encrypted with p≡p https://pEp-project.org"
"this message was encrypted with p≡p https://pEp-project.org"
# Decrypt message. # Decrypt message.
dec_msg, key_list, rating, r = enc_msg.decrypt() dec_msg, key_list, rating, r = enc_msg.decrypt()
@ -54,7 +53,8 @@ def test_msg_enc_dec_roundtrip(create_alice_identity, create_bob_identity):
# Content-Transfer-Encoding: doesn't print `quoted-printable` anymore. # Content-Transfer-Encoding: doesn't print `quoted-printable` anymore.
# Content-Disposition: is not present anymore. # Content-Disposition: is not present anymore.
# `!` is not replaced by `=21` anymore. # `!` is not replaced by `=21` anymore.
expected_dec_lines = """From: Alice Lovelace <alice@openpgp.example> expected_dec_lines = \
"""From: Alice Lovelace <alice@openpgp.example>
To: Bob Babagge <bob@openpgp.example> To: Bob Babagge <bob@openpgp.example>
Subject: This is a subject Subject: This is a subject
X-pEp-Version: 2.1 X-pEp-Version: 2.1
@ -129,7 +129,8 @@ def test_dec_msg_len(create_alice_identity, create_bob_identity):
dec_msg_len = len(str(dec_msg)) dec_msg_len = len(str(dec_msg))
assert dec_msg.longmsg.replace("\r", "") == constants.BODY # msg.longmsg assert dec_msg.longmsg.replace("\r", "") == constants.BODY # msg.longmsg
expected_dec_msg = """From: Alice Lovelace <alice@openpgp.example>\r expected_dec_msg = \
"""From: Alice Lovelace <alice@openpgp.example>\r
To: Bob Babagge <bob@openpgp.example>\r To: Bob Babagge <bob@openpgp.example>\r
Subject: This is a subject\r Subject: This is a subject\r
X-pEp-Version: 2.1\r X-pEp-Version: 2.1\r

2
tests/test_pep.py → tests_new/test_pep.py

@ -1,10 +1,10 @@
"""Unit test for pEp package, not for subpackages or modules.""" """Unit test for pEp package, not for subpackages or modules."""
from pEp import __version__
def test_pep_version(): def test_pep_version():
""" Test that __version__ is not None or empty and is not 0.0.0.""" """ Test that __version__ is not None or empty and is not 0.0.0."""
from pEp import __version__
# We could also test that match the regex, but that is already a test in # We could also test that match the regex, but that is already a test in
# setuptools_scm itself. # setuptools_scm itself.
assert __version__ assert __version__
Loading…
Cancel
Save