14
0
forked from pool/python-loguru

Accepting request 886445 from home:bnavigator:branches:devel:languages:python

- Add loguru-exception-formatting-py39.patch
  https://github.com/Delgan/loguru/commit/19f518c5 for changed
  exception formatting in Python 3.9

OBS-URL: https://build.opensuse.org/request/show/886445
OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-loguru?expand=0&rev=12
This commit is contained in:
2021-04-19 08:07:56 +00:00
committed by Git OBS Bridge
parent 167d279f3c
commit 53a87b62f2
3 changed files with 173 additions and 3 deletions

View File

@@ -0,0 +1,161 @@
From 19f518c5f1f355703ffc4ee62f0e1e397605863e Mon Sep 17 00:00:00 2001
From: Delgan <delgan.py@gmail.com>
Date: Sat, 13 Mar 2021 12:47:47 +0100
Subject: [PATCH] Fix unit tests for exception formatting for Python 3.9
Formatting changed, notably because absolute instead of relative paths
are used in traceback: https://bugs.python.org/issue20443
---
.../output/diagnose/indentation_error.txt | 1 -
.../output/diagnose/syntax_error.txt | 2 +-
.../others/syntaxerror_without_traceback.txt | 8 ++---
.../output/ownership/syntaxerror.txt | 10 +++---
tests/test_exceptions_formatting.py | 31 ++++++++++++++++++-
5 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/tests/exceptions/output/diagnose/indentation_error.txt b/tests/exceptions/output/diagnose/indentation_error.txt
index b2faa4d..d5b950a 100644
--- a/tests/exceptions/output/diagnose/indentation_error.txt
+++ b/tests/exceptions/output/diagnose/indentation_error.txt
@@ -7,6 +7,5 @@
File "<string>", line 4
print("foobar") #intentional faulty indentation here.
- ^
IndentationError: unexpected indent
diff --git a/tests/exceptions/output/diagnose/syntax_error.txt b/tests/exceptions/output/diagnose/syntax_error.txt
index 6e1f612..c8b0761 100644
--- a/tests/exceptions/output/diagnose/syntax_error.txt
+++ b/tests/exceptions/output/diagnose/syntax_error.txt
@@ -7,6 +7,6 @@
File "<string>", line 4
b = 7 *
- ^
+ ^
SyntaxError: invalid syntax
diff --git a/tests/exceptions/output/others/syntaxerror_without_traceback.txt b/tests/exceptions/output/others/syntaxerror_without_traceback.txt
index a4747ee..d798ba1 100644
--- a/tests/exceptions/output/others/syntaxerror_without_traceback.txt
+++ b/tests/exceptions/output/others/syntaxerror_without_traceback.txt
@@ -1,20 +1,20 @@
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
diff --git a/tests/exceptions/output/ownership/syntaxerror.txt b/tests/exceptions/output/ownership/syntaxerror.txt
index 1dc88ef..00763f6 100644
--- a/tests/exceptions/output/ownership/syntaxerror.txt
+++ b/tests/exceptions/output/ownership/syntaxerror.txt
@@ -13,7 +13,7 @@
exec("foo =")
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
@@ -27,7 +27,7 @@
exec("foo =")
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
@@ -40,7 +40,7 @@
exec("foo =")
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
Traceback (most recent call last):
@@ -50,7 +50,7 @@
exec("foo =")
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
Traceback (most recent call last):
@@ -60,5 +60,5 @@ Traceback (most recent call last):
exec("foo =")
File "<string>", line 1
foo =
- ^
+ ^
SyntaxError: invalid syntax
diff --git a/tests/test_exceptions_formatting.py b/tests/test_exceptions_formatting.py
index 79c41f6..cad2dba 100644
--- a/tests/test_exceptions_formatting.py
+++ b/tests/test_exceptions_formatting.py
@@ -9,12 +9,41 @@
def normalize(exception):
"""Normalize exception output for reproducible test cases"""
- if os.name:
+ if os.name == "nt":
exception = re.sub(
r'File[^"]+"[^"]+\.py[^"]*"', lambda m: m.group().replace("\\", "/"), exception
)
exception = re.sub(r"(\r\n|\r|\n)", "\n", exception)
+ if sys.version_info >= (3, 9, 0):
+
+ def fix_filepath(match):
+ filepath = match.group(1)
+ pattern = (
+ r'((?:\x1b\[[0-9]*m)+)([^"]+?)((?:\x1b\[[0-9]*m)+)([^"]+?)((?:\x1b\[[0-9]*m)+)'
+ )
+ match = re.match(pattern, filepath)
+ start_directory = os.path.dirname(os.path.dirname(__file__))
+ if match:
+ groups = list(match.groups())
+ groups[1] = os.path.relpath(os.path.abspath(groups[1]), start_directory) + "/"
+ relpath = "".join(groups)
+ else:
+ relpath = os.path.relpath(os.path.abspath(filepath), start_directory)
+ return 'File "%s"' % relpath
+
+ exception = re.sub(
+ r'File "([^"]+\.py[^"]*)"',
+ fix_filepath,
+ exception,
+ )
+
+ if sys.version_info < (3, 9, 0):
+ if "SyntaxError" in exception:
+ exception = re.sub(r"(\n *)(\^ *\n)", r"\1 \2", exception)
+ elif "IndentationError" in exception:
+ exception = re.sub(r"\n *\^ *\n", "\n", exception)
+
exception = re.sub(
r'"[^"]*/somelib/__init__.py"', '"/usr/lib/python/somelib/__init__.py"', exception
)

View File

@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Sun Apr 18 12:17:42 UTC 2021 - Ben Greiner <code@bnavigator.de>
- Add loguru-exception-formatting-py39.patch
https://github.com/Delgan/loguru/commit/19f518c5 for changed
exception formatting in Python 3.9
------------------------------------------------------------------- -------------------------------------------------------------------
Fri Feb 19 01:51:00 UTC 2021 - John Vandenberg <jayvdb@gmail.com> Fri Feb 19 01:51:00 UTC 2021 - John Vandenberg <jayvdb@gmail.com>

View File

@@ -26,13 +26,16 @@ License: MIT
Group: Development/Languages/Python Group: Development/Languages/Python
URL: https://github.com/Delgan/loguru URL: https://github.com/Delgan/loguru
Source: https://files.pythonhosted.org/packages/source/l/loguru/loguru-%{version}.tar.gz Source: https://files.pythonhosted.org/packages/source/l/loguru/loguru-%{version}.tar.gz
# PATCH-FIX-UPSTREAM pytest-6.2-excepthooks.patch
Patch0: https://github.com/Delgan/loguru/commit/31cf758ee9d22dbfa125f38153782fe20ac9dce5.patch#/pytest-6.2-excepthooks.patch Patch0: https://github.com/Delgan/loguru/commit/31cf758ee9d22dbfa125f38153782fe20ac9dce5.patch#/pytest-6.2-excepthooks.patch
# PATCH-FIX-UPSTREAM loguru-exception-formatting-py39.patch
Patch1: https://github.com/Delgan/loguru/commit/19f518c5f1f355703ffc4ee62f0e1e397605863e.patch#/loguru-exception-formatting-py39.patch
BuildRequires: %{python_module aiocontextvars if %python-base < 3.7}
BuildRequires: %{python_module colorama} BuildRequires: %{python_module colorama}
BuildRequires: %{python_module pytest} BuildRequires: %{python_module pytest}
BuildRequires: %{python_module setuptools} BuildRequires: %{python_module setuptools}
BuildRequires: fdupes BuildRequires: fdupes
BuildRequires: python-rpm-macros BuildRequires: python-rpm-macros
BuildRequires: ((python3-aiocontextvars and python3-base < 3.7) or (python36-aiocontextvars and python36-base))
%if 0%{?python_version_nodots} < 37 %if 0%{?python_version_nodots} < 37
Requires: python-aiocontextvars Requires: python-aiocontextvars
%endif %endif
@@ -46,8 +49,7 @@ Python logging component providing a single object
which dispatches log messages to configured handlers. which dispatches log messages to configured handlers.
%prep %prep
%setup -q -n loguru-%{version} %autosetup -p1 -n loguru-%{version}
%patch0 -p1
%build %build
%python_build %python_build