From a82491e20bb9a3cd7378d1c77a5994144b5f8bdf Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Thu, 3 Oct 2019 13:26:12 +0200 Subject: [PATCH] Add hack to remove build dependency on python2-pytest Since this package deals with strings, it should be tested on Python 2 if we ship it. However, pytest has very many dependencies, and chardet's tests are very simple. It's not hard to run the tests without pytest. I assume that python2-chardet will be removed from Fedora before upstream chanes the testing mechanism, so it's OK to use this crude hack to get rid of the python2-pytest debendency. --- hack-pytest.patch | 41 +++++++++++++++++++++++++++++++++++++++++ python-chardet.spec | 11 ++++++++--- 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 hack-pytest.patch diff --git a/hack-pytest.patch b/hack-pytest.patch new file mode 100644 index 0000000..dce5c5a --- /dev/null +++ b/hack-pytest.patch @@ -0,0 +1,41 @@ +diff -rU3 chardet-3.0.4-orig/test.py chardet-3.0.4/test.py +--- chardet-3.0.4-orig/test.py 2019-10-03 13:29:21.914988914 +0200 ++++ chardet-3.0.4/test.py 2019-10-03 13:51:34.783256817 +0200 +@@ -19,7 +19,27 @@ + HAVE_HYPOTHESIS = True + except ImportError: + HAVE_HYPOTHESIS = False +-import pytest ++try: ++ import pytest ++except ImportError: ++ class pytest: ++ """Just enough pytest API to run the tests""" ++ class mark: ++ @staticmethod ++ def parametrize(name_string, cases): ++ """Run all given tests""" ++ def decorator(func): ++ names = name_string.split(', ') ++ for case in cases: ++ print(case) ++ func(**{name: val for name, val in zip(names, case)}) ++ return decorator ++ ++ @staticmethod ++ def xfail(): ++ """Don't run this test""" ++ pass ++ + + import chardet + +@@ -59,7 +79,7 @@ + full_path = join(path, file_name) + test_case = full_path, encoding + if full_path in EXPECTED_FAILURES: +- test_case = pytest.param(*test_case, marks=pytest.mark.xfail) ++ continue + yield test_case + + diff --git a/python-chardet.spec b/python-chardet.spec index 4ba90ec..341c4e5 100644 --- a/python-chardet.spec +++ b/python-chardet.spec @@ -1,7 +1,7 @@ %global pypi_name chardet Name: python-%{pypi_name} Version: 3.0.4 -Release: 12%{?dist} +Release: 13%{?dist} Summary: Character encoding auto-detection in Python License: LGPLv2 URL: https://github.com/%{pypi_name}/%{pypi_name} @@ -10,6 +10,9 @@ Source0: %pypi_source # pytest 4 support Patch1: https://github.com/chardet/chardet/pull/174.patch +# Don't require python2-pytest +Patch2: hack-pytest.patch + BuildArch: noarch BuildRequires: python2-devel BuildRequires: python2-setuptools @@ -20,7 +23,6 @@ BuildRequires: python3-setuptools # Circular dependency on pytest %bcond_without tests %if %{with tests} -BuildRequires: python2-pytest BuildRequires: python3-pytest %endif @@ -62,7 +64,7 @@ rm %{buildroot}%{_bindir}/* %if %{with tests} %check -%{__python2} -m pytest -v +%{__python2} test.py %{__python3} -m pytest -v %endif @@ -81,6 +83,9 @@ rm %{buildroot}%{_bindir}/* %changelog +* Thu Oct 03 2019 Petr Viktorin - 3.0.4-13 +- Add hack to remove build dependency on python2-pytest + * Thu Aug 15 2019 Miro HronĨok - 3.0.4-12 - Rebuilt for Python 3.8