Skip to contentSkip to conversation

python3-ecdsa: Add ptest support

PATCH New [email protected] 1 participant 1 message Mar 10, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 python3-ecdsa: Add ptest support

From: Mingli Yu <[email protected]>

Backport a patch [1] to fix the test warning.

root@intel-x86-64:/usr/lib64/python3-ecdsa/ptest# ./run-ptest
============================= test session starts ==============================
platform linux -- Python 3.10.16, pytest-7.1.1, pluggy-1.0.0
rootdir: /usr/lib64/python3-ecdsa/ptest
plugins: hypothesis-6.39.5
collected 1601 items

PASS: tests/test_curves.py::TestParameterEncoding::test_compare_curves_with_different_generators
PASS: tests/test_curves.py::TestParameterEncoding::test_compare_with_different_object
PASS: tests/test_curves.py::TestParameterEncoding::test_decode_malformed_explicit_garbage_after_ECParam
PASS: tests/test_curves.py::TestParameterEncoding::test_decode_malformed_garbage_after_prime
PASS: tests/test_curves.py::TestParameterEncoding::test_decode_malformed_named_curve
PASS: tests/test_curves.py::TestParameterEncoding::test_decode_malformed_unknown_field_type
PASS: tests/test_curves.py::TestParameterEncoding::test_decode_malformed_unknown_version_number
PASS: tests/test_curves.py::TestParameterEncoding::test_decoding_explicit_from_openssl
PASS: tests/test_curves.py::TestParameterEncoding::test_decoding_well_known_from_explicit_params
PASS: tests/test_curves.py::TestParameterEncoding::test_decoding_with_incorrect_valid_encodings
PASS: tests/test_curves.py::TestParameterEncoding::test_default_encode_for_custom_curve
PASS: tests/test_curves.py::TestParameterEncoding::test_encoding_to_explicit_compressed_params
PASS: tests/test_curves.py::TestParameterEncoding::test_encoding_to_explicit_params
PASS: tests/test_curves.py::TestParameterEncoding::test_from_pem
[snip]
PASS: tests/test_pyecdsa.py::test_RFC4754_vectors[ECDSA-384]
PASS: tests/test_pyecdsa.py::test_RFC4754_vectors[ECDSA-521]
PASS: tests/test_rw_lock.py::RWLockTestCase::test_many_writers_priority
PASS: tests/test_rw_lock.py::RWLockTestCase::test_readers_nonexclusive_access
PASS: tests/test_rw_lock.py::RWLockTestCase::test_writer_priority
PASS: tests/test_rw_lock.py::RWLockTestCase::test_writers_exclusive_access

======================= 1601 passed in 270.57s (0:04:30) =======================

[1] https://github.com/tlsfuzzer/python-ecdsa/commit/50c1fa44f35b9d383ffbc3e045a94419f6c347d1

---
 ...convention-for-testing-that-no-warni.patch | 82 +++++++++++++++++++
 .../python/python3-ecdsa/run-ptest            |  3 +
 .../python/python3-ecdsa_0.17.0.bb            | 22 ++++-
 3 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 meta-python/recipes-devtools/python/python3-ecdsa/0001-use-recommended-convention-for-testing-that-no-warni.patch
 create mode 100755 meta-python/recipes-devtools/python/python3-ecdsa/run-ptest
meta-python/recipes-devtools/python/python3-ecdsa/0001-use-recommended-convention-for-testing-that-no-warni.patch new file +82 -0
new file mode 100644
index 0000000000..3dae4b06fe
@@ -0,0 +1,82 @@
+From 50c1fa44f35b9d383ffbc3e045a94419f6c347d1 Mon Sep 17 00:00:00 2001
+From: Hubert Kario <[email protected]>
+Date: Thu, 23 Feb 2023 23:03:24 +0100
+Subject: [PATCH] use recommended convention for testing that no warnings were
+ raised
+
+Upstream-Status: Backport [https://github.com/tlsfuzzer/python-ecdsa/commit/50c1fa44f35b9d383ffbc3e045a94419f6c347d1]
+
+Signed-off-by: Mingli Yu <[email protected]>
+---
+ src/ecdsa/test_der.py | 30 ++++++++++++------------------
+ 1 file changed, 12 insertions(+), 18 deletions(-)
+
+diff --git a/src/ecdsa/test_der.py b/src/ecdsa/test_der.py
+index 0ca5bd7..833d12d 100644
+--- a/src/ecdsa/test_der.py
++++ b/src/ecdsa/test_der.py
+@@ -144,26 +144,22 @@ class TestEncodeBitstring(unittest.TestCase):
+ 
+     def test_new_call_convention(self):
+         """This is how it should be called now."""
+-        warnings.simplefilter("always")
+-        with pytest.warns(None) as warns:
++        # make sure no warnings are raised
++        with warnings.catch_warnings():
++            warnings.simplefilter("error")
+             der = encode_bitstring(b"\xff", 0)
+ 
+-        # verify that new call convention doesn't raise Warnings
+-        self.assertEqual(len(warns), 0)
+-
+         self.assertEqual(der, b"\x03\x02\x00\xff")
+ 
+     def test_implicit_unused_bits(self):
+         """
+         Writing bit string with already included the number of unused bits.
+         """
+-        warnings.simplefilter("always")
+-        with pytest.warns(None) as warns:
++        # make sure no warnings are raised
++        with warnings.catch_warnings():
++            warnings.simplefilter("error")
+             der = encode_bitstring(b"\x00\xff", None)
+ 
+-        # verify that new call convention doesn't raise Warnings
+-        self.assertEqual(len(warns), 0)
+-
+         self.assertEqual(der, b"\x03\x02\x00\xff")
+ 
+     def test_explicit_unused_bits(self):
+@@ -203,22 +199,20 @@ class TestRemoveBitstring(unittest.TestCase):
+         self.assertEqual(rest, b"")
+ 
+     def test_new_call_convention(self):
+-        warnings.simplefilter("always")
+-        with pytest.warns(None) as warns:
++        # make sure no warnings are raised
++        with warnings.catch_warnings():
++            warnings.simplefilter("error")
+             bits, rest = remove_bitstring(b"\x03\x02\x00\xff", 0)
+ 
+-        self.assertEqual(len(warns), 0)
+-
+         self.assertEqual(bits, b"\xff")
+         self.assertEqual(rest, b"")
+ 
+     def test_implicit_unexpected_unused(self):
+-        warnings.simplefilter("always")
+-        with pytest.warns(None) as warns:
++        # make sure no warnings are raised
++        with warnings.catch_warnings():
++            warnings.simplefilter("error")
+             bits, rest = remove_bitstring(b"\x03\x02\x00\xff", None)
+ 
+-        self.assertEqual(len(warns), 0)
+-
+         self.assertEqual(bits, (b"\xff", 0))
+         self.assertEqual(rest, b"")
+ 
+-- 
+2.34.1
+
meta-python/recipes-devtools/python/python3-ecdsa/run-ptest new file +3 -0
new file mode 100755
index 0000000000..3385d68939
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+pytest -o log_cli=true -o log_cli_level=INFO | sed -e 's/\[...%\]//g'| sed -e 's/PASSED/PASS/g'| sed -e 's/FAILED/FAIL/g'|sed -e 's/SKIPED/SKIP/g'| awk '{if ($NF=="PASS" || $NF=="FAIL" || $NF=="SKIP" || $NF=="XFAIL" || $NF=="XPASS"){printf "%s: %s\n", $NF, $0}else{print}}'| awk '{if ($NF=="PASS" || $NF=="FAIL" || $NF=="SKIP" || $NF=="XFAIL" || $NF=="XPASS") {$NF="";print $0}else{print}}'
meta-python/recipes-devtools/python/python3-ecdsa_0.17.0.bb +21 -1
index 177019ccc2..5d407b513e 100644
@@ -3,13 +3,33 @@ SECTION = "devel/python"
 LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=66ffc5e30f76cbb5358fe54b645e5a1d"
 
+SRC_URI += "\
+           file://0001-use-recommended-convention-for-testing-that-no-warni.patch \
+           file://run-ptest \
+"
+
 DEPENDS += "python3-pip python3-pbr"
 
 PYPI_PACKAGE = "ecdsa"
 SRC_URI[sha256sum] = "b9f500bb439e4153d0330610f5d26baaf18d17b8ced1bc54410d189385ea68aa"
 
-inherit pypi setuptools3 python3native
+inherit pypi setuptools3 python3native ptest
+
+do_install_ptest() {
+    install -d ${D}${PTEST_PATH}/tests
+    cp -rf ${S}/src/ecdsa/* ${D}${PTEST_PATH}/tests/
+}
 
 RDEPENDS:${PN} += "python3-six python3-gmpy2 python3-pbr"
 
+RDEPENDS:${PN}-ptest += " \
+    python3-hypothesis \
+    python3-pytest \
+"
+
+do_install:append() {
+	rm -fr ${D}${libdir}/python*/site-packages/ecdsa/__pycache__
+	rm ${D}${PYTHON_SITEPACKAGES_DIR}/ecdsa/test_*.py
+}
+
 BBCLASSEXTEND = "native nativesdk"
Signature · 1 line
2.34.1