[packages/python-asn1crypto] Fix tests (from upstream)
arekm
arekm at pld-linux.org
Tue Sep 1 23:37:22 CEST 2026
commit ad659bc18f4c09f377d7efc2250121538137746c
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Tue Sep 1 23:36:40 2026 +0200
Fix tests (from upstream)
python-asn1crypto-tests-imp.patch | 120 ++++++++++++++++++++++++++++++++++++++
python-asn1crypto.spec | 8 +++
2 files changed, 128 insertions(+)
---
diff --git a/python-asn1crypto.spec b/python-asn1crypto.spec
index 5a026e6..f41273e 100644
--- a/python-asn1crypto.spec
+++ b/python-asn1crypto.spec
@@ -19,16 +19,23 @@ Source0: https://files.pythonhosted.org/packages/source/a/asn1crypto/%{pypi_name
# Source0-md5: f7a5271af9b81246fbdf57d703afce2f
Source1: https://files.pythonhosted.org/packages/source/a/asn1crypto_tests/asn1crypto_tests-%{version}.tar.gz
# Source1-md5: 07adf2c937fb90adbecc125b17eeaa1a
+Patch0: %{name}-tests-imp.patch
URL: https://pypi.org/project/asn1crypto/
BuildRequires: rpm-pythonprov
BuildRequires: rpmbuild(macros) >= 1.714
%if %{with python2}
BuildRequires: python-modules >= 1:2.6
BuildRequires: python-setuptools
+%if %{with tests}
+BuildRequires: python-pytest
+%endif
%endif
%if %{with python3}
BuildRequires: python3-modules >= 1:3.2
BuildRequires: python3-setuptools
+%if %{with tests}
+BuildRequires: python3-pytest
+%endif
%endif
Requires: python-modules >= 1:2.6
BuildArch: noarch
@@ -65,6 +72,7 @@ PKCS#8, PKCS#12, PKCS#5, X.509 i TSP.
%if %{with tests}
%{__mv} asn1crypto_tests-%{version} tests
+%patch -P0 -p1
%endif
%build
diff --git a/python-asn1crypto-tests-imp.patch b/python-asn1crypto-tests-imp.patch
new file mode 100644
index 0000000..f4a8939
--- /dev/null
+++ b/python-asn1crypto-tests-imp.patch
@@ -0,0 +1,120 @@
+The asn1crypto_tests sdist loads asn1crypto from the source tree with imp,
+gone since Python 3.12. Upstream's replacement, never released:
+https://github.com/wbond/asn1crypto/blob/master/tests/__init__.py
+
+--- a/tests/__init__.py
++++ b/tests/__init__.py
+@@ -1,15 +1,63 @@
+ # coding: utf-8
+ from __future__ import unicode_literals, division, absolute_import, print_function
+
+-import imp
+ import os
++import sys
+ import unittest
+
++if sys.version_info < (3, 5):
++ import imp
++else:
++ import importlib
++ import importlib.abc
++ import importlib.util
++
+
+ __version__ = '1.5.1'
+ __version_info__ = (1, 5, 1)
+
+
++if sys.version_info >= (3, 5):
++ class ModCryptoMetaFinder(importlib.abc.MetaPathFinder):
++ def setup(self):
++ self.modules = {}
++ sys.meta_path.insert(0, self)
++
++ def add_module(self, package_name, package_path):
++ if package_name not in self.modules:
++ self.modules[package_name] = package_path
++
++ def find_spec(self, fullname, path, target=None):
++ name_parts = fullname.split('.')
++ if name_parts[0] not in self.modules:
++ return None
++
++ package = name_parts[0]
++ package_path = self.modules[package]
++
++ fullpath = os.path.join(package_path, *name_parts[1:])
++
++ if os.path.isdir(fullpath):
++ filename = os.path.join(fullpath, "__init__.py")
++ submodule_locations = [fullpath]
++ else:
++ filename = fullpath + ".py"
++ submodule_locations = None
++
++ if not os.path.exists(filename):
++ return None
++
++ return importlib.util.spec_from_file_location(
++ fullname,
++ filename,
++ loader=None,
++ submodule_search_locations=submodule_locations
++ )
++
++ CUSTOM_FINDER = ModCryptoMetaFinder()
++ CUSTOM_FINDER.setup()
++
++
+ def _import_from(mod, path, mod_dir=None):
+ """
+ Imports a module from a specific path
+@@ -28,18 +76,44 @@
+ None if not loaded, otherwise the module
+ """
+
++ if mod in sys.modules:
++ return sys.modules[mod]
++
+ if mod_dir is None:
+- mod_dir = mod
++ full_mod = mod
++ else:
++ full_mod = mod_dir.replace(os.sep, '.')
++
++ if mod_dir is None:
++ mod_dir = mod.replace('.', os.sep)
+
+ if not os.path.exists(path):
+ return None
+
+- if not os.path.exists(os.path.join(path, mod_dir)):
++ source_path = os.path.join(path, mod_dir, '__init__.py')
++ if not os.path.exists(source_path):
++ source_path = os.path.join(path, mod_dir + '.py')
++
++ if not os.path.exists(source_path):
+ return None
+
++ if os.sep in mod_dir:
++ append, mod_dir = mod_dir.rsplit(os.sep, 1)
++ path = os.path.join(path, append)
++
+ try:
+- mod_info = imp.find_module(mod_dir, [path])
+- return imp.load_module(mod, *mod_info)
++ if sys.version_info < (3, 5):
++ mod_info = imp.find_module(mod_dir, [path])
++ return imp.load_module(mod, *mod_info)
++
++ else:
++ package = mod.split('.', 1)[0]
++ package_dir = full_mod.split('.', 1)[0]
++ package_path = os.path.join(path, package_dir)
++ CUSTOM_FINDER.add_module(package, package_path)
++
++ return importlib.import_module(mod)
++
+ except ImportError:
+ return None
+
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/python-asn1crypto.git/commitdiff/ad659bc18f4c09f377d7efc2250121538137746c
More information about the pld-cvs-commit
mailing list