Browse Source

Merge in PYADPT-100 - "pytest: subprocess per test required"

master
heck 5 years ago
parent
commit
aeb802540a
  1. 3
      Makefile
  2. 8
      pyproject.toml
  3. 1
      setup.cfg
  4. 16
      tests/conftest.py
  5. 3
      tests/constants.py
  6. 8
      tests/test_identity.py
  7. 9
      tests/test_message.py
  8. 2
      tests/test_pep.py

3
Makefile

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

8
pyproject.toml

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

1
setup.cfg

@ -39,4 +39,5 @@ setup_requires =
# To install these dependencies, run pip install .[test]
test =
pytest
pytest-forked
doc = sphinx

16
tests/conftest.py

@ -1,4 +1,5 @@
"""pytest configuration for the unit tests."""
import os
import pytest
@ -28,14 +29,15 @@ def datadir(request):
return D(request.fspath.dirpath("data"))
@pytest.fixture(scope='function')
def tmpdir(tmpdir_factory, request):
@pytest.fixture()
def ctx_init(tmpdir_factory, request):
"""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)
print(bn)
import os
os.environ["PEP_HOME"] = str(bn)
os.environ["HOME"] = str(bn)
return bn
@pytest.fixture()
@ -51,8 +53,7 @@ def bob_pub_key_data(datadir):
@pytest.fixture()
def create_alice_identity(tmpdir, alice_sec_key_data, bob_pub_key_data):
os.environ["HOME"] = str(tmpdir)
def create_alice_identity(ctx_init, alice_sec_key_data):
import pEp
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()
def create_bob_identity(tmpdir, bob_pub_key_data):
os.environ["HOME"] = str(tmpdir)
def create_bob_identity(ctx_init, bob_pub_key_data):
import pEp
pEp.import_key(bob_pub_key_data)

3
tests/constants.py

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

8
tests/test_identity.py

@ -4,7 +4,7 @@ import os
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,
import pEp
alice = pEp.Identity()
@ -43,8 +43,7 @@ def test_create_one_identity_succeed(tmpdir):
assert alice.flags == expected_alice.flags
def test_two_identities_succeed(tmpdir, bob_pub_key_data):
os.environ["HOME"] = str(tmpdir)
def test_two_identities_succeed(ctx_init, bob_pub_key_data):
import pEp
alice = pEp.Identity(
@ -88,8 +87,7 @@ def test_two_identities_succeed(tmpdir, bob_pub_key_data):
assert bob.flags == 0
def test_set_own_key(tmpdir, alice_sec_key_data):
os.environ["HOME"] = str(tmpdir)
def test_set_own_key(ctx_init, alice_sec_key_data):
import pEp
pEp.import_key(alice_sec_key_data)

9
tests/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.to[0]) == constants.BOB_NAME_ADDR
assert enc_msg.shortmsg == "p≡p"
assert enc_msg.longmsg == \
"this message was encrypted with p≡p https://pEp-project.org"
assert enc_msg.longmsg == "this message was encrypted with p≡p https://pEp-project.org"
# Decrypt message.
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-Disposition: is not present 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>
Subject: This is a subject
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))
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
Subject: This is a subject\r
X-pEp-Version: 2.1\r

2
tests/test_pep.py

@ -1,10 +1,10 @@
"""Unit test for pEp package, not for subpackages or modules."""
from pEp import __version__
def test_pep_version():
""" 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
# setuptools_scm itself.
assert __version__

Loading…
Cancel
Save