From 5ec75ac77221ff5a53fac71cbad69d7e456f4120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20F=C3=A9lizard?= Date: Thu, 29 Aug 2024 07:02:17 +0000 Subject: [PATCH] Fix GitHub workflow --- .github/workflows/zeyple.yml | 16 ++++++++-------- CONTRIBUTING.md | 7 +++---- requirements.txt | 9 --------- tests/test_zeyple.py | 19 +++++++++++-------- tox.ini | 13 +++++++++---- 5 files changed, 31 insertions(+), 33 deletions(-) delete mode 100644 requirements.txt diff --git a/.github/workflows/zeyple.yml b/.github/workflows/zeyple.yml index 0070995..3054399 100644 --- a/.github/workflows/zeyple.yml +++ b/.github/workflows/zeyple.yml @@ -13,13 +13,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [2.7, 3.7] + python-version: [3.11, 3.12] fail-fast: false steps: - name: Checkout repository - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install dependencies @@ -28,16 +28,16 @@ jobs: sudo apt-get install debconf-utils sudo debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Local only'" sudo debconf-set-selections <<< "postfix postfix/mailname string localhost" - sudo apt-get install -y mailutils ruby ruby-dev rubygems build-essential sudo gnupg python-gpg libgpgme-dev swig - python -m pip install --upgrade pip - pip install -r requirements_gpg.txt + sudo apt-get install -y mailutils ruby ruby-dev rubygems build-essential sudo gnupg python3-gpg sudo gem install --no-document fpm - - name: Test - run: python -m pytest tests/ + python -m pip install --upgrade pip setuptools wheel + python -m pip install --upgrade tox - name: Build deb package run: ./fpm/create - name: End to end test using deb package run: sudo bash -ex ./tests/e2e.sh + - name: Test with tox + run: env CI=0 tox - name: Upload deb package uses: actions/upload-artifact@v1 with: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0dec8d8..bdacd80 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,10 +12,9 @@ If you want to contribute, please: You will need the following development dependencies. * Packages: - * Arch Linux: `pacman -S python-gpgme` - * Debian/Ubuntu: `apt-get install libgpgme-dev` - * Fedora: `yum install gpgme-devel python-devel python3-devel` -* Python eggs: `pip install -r requirements.txt` + * Arch Linux: `pacman -S python-gpgme python-tox` + * Debian/Ubuntu: `apt-get install python3-gpg tox` + * Fedora: `yum install python3-devel gpgme-devel tox` ## Testing diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 04b367f..0000000 --- a/requirements.txt +++ /dev/null @@ -1,9 +0,0 @@ -pygpgme -six>=1.12.0 -pytest>=4.1.0 -pytest-cov>=2.6.1 -mock>=2.0.0 -coverage>=4.5.2 -tox>=3.6.1 -pycodestyle>=2.4.0 -pylint>=1.6.4 diff --git a/tests/test_zeyple.py b/tests/test_zeyple.py index 72d0f6e..a724d41 100644 --- a/tests/test_zeyple.py +++ b/tests/test_zeyple.py @@ -1,10 +1,9 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from six.moves.configparser import ConfigParser +from configparser import ConfigParser from textwrap import dedent from unittest.mock import Mock -from zeyple import zeyple import gpg import os import re @@ -13,6 +12,8 @@ import tempfile import unittest +from zeyple import zeyple as z + KEYS_FNAME = os.path.join(os.path.dirname(__file__), 'keys.gpg') TEST1_ID = 'D6513C04E24C1F83' TEST1_EMAIL = 'test1@zeyple.example.com' @@ -22,6 +23,7 @@ TEST_EXPIRED_ID = 'ED97E21F1C7F1AC6' TEST_EXPIRED_EMAIL = 'test_expired@zeyple.example.com' + class ZeypleTest(unittest.TestCase): def setUp(self): self.tmpdir = tempfile.mkdtemp() @@ -52,7 +54,7 @@ def setUp(self): stderr=open('/dev/null'), ) - self.zeyple = zeyple.Zeyple(self.conffile) + self.zeyple = z.Zeyple(self.conffile) self.zeyple._send_message = Mock() # don't try to send emails def tearDown(self): @@ -71,18 +73,19 @@ def assertValidMimeMessage(self, cipher_message, mime_message): plain_payload = cipher_message.get_payload() encrypted_envelope = plain_payload[1] - assert encrypted_envelope["Content-Type"] == 'application/octet-stream; name="encrypted.asc"' + assert (encrypted_envelope["Content-Type"] == + 'application/octet-stream; name="encrypted.asc"') encrypted_payload = encrypted_envelope.get_payload().encode('utf-8') decrypted_envelope = self.decrypt(encrypted_payload).decode('utf-8').strip() - boundary = re.match(r'.+boundary="([^"]+)"', decrypted_envelope, re.MULTILINE | re.DOTALL).group(1) + boundary = re.match(r'.+boundary="([^"]+)"', + decrypted_envelope, re.MULTILINE | re.DOTALL).group(1) # replace auto-generated boundary with one we know mime_message = mime_message.replace("BOUNDARY", boundary) prefix = dedent("""\ - Content-Type: multipart/mixed; boundary=\"""" + \ - boundary + """\" + Content-Type: multipart/mixed; boundary=\"""" + boundary + """\" """) mime_message = prefix + mime_message @@ -237,7 +240,7 @@ def test_process_message_with_complex_message(self): with open(filename, 'r') as test_file: contents = test_file.read() - self.zeyple.process_message(contents, [TEST1_EMAIL]) # should not raise + self.zeyple.process_message(contents, [TEST1_EMAIL]) # should not raise def test_force_encryption(self): """Tries to encrypt without key""" diff --git a/tox.ini b/tox.ini index 3796438..f7b40f4 100644 --- a/tox.ini +++ b/tox.ini @@ -4,9 +4,14 @@ skip_missing_interpreters = True skipsdist = True [testenv] -deps = -rrequirements.txt +deps = + mock + pycodestyle + pytest + pytest-cov setenv = - PYTHONPATH = {toxinidir} + PYTHONPATH = {toxinidir}:/usr/lib/python3.12/site-packages/:/usr/lib/python3/dist-packages/ +#list_dependencies_command = python -m pip list commands = - pycodestyle --show-pep8 zeyple - py.test {posargs:--cov-report=html --cov=zeyple/} + python -m pytest --cov=zeyple/ --cov-report=html + pycodestyle --show-pep8 --max-line-length=100