Sync from SUSE:SLFO:Main python-re-assert revision e4e487b0bd8a281203c6440822d79c54

This commit is contained in:
Adrian Schröter 2024-05-03 22:45:43 +02:00
commit 2a0a4c944f
5 changed files with 233 additions and 0 deletions

23
.gitattributes vendored Normal file
View File

@ -0,0 +1,23 @@
## Default LFS
*.7z filter=lfs diff=lfs merge=lfs -text
*.bsp filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.gem filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.jar filter=lfs diff=lfs merge=lfs -text
*.lz filter=lfs diff=lfs merge=lfs -text
*.lzma filter=lfs diff=lfs merge=lfs -text
*.obscpio filter=lfs diff=lfs merge=lfs -text
*.oxt filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.rpm filter=lfs diff=lfs merge=lfs -text
*.tbz filter=lfs diff=lfs merge=lfs -text
*.tbz2 filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.txz filter=lfs diff=lfs merge=lfs -text
*.whl filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text

27
python-re-assert.changes Normal file
View File

@ -0,0 +1,27 @@
-------------------------------------------------------------------
Fri Apr 21 12:32:42 UTC 2023 - Dirk Müller <dmueller@suse.com>
- add sle15_python_module_pythons (jsc#PED-68)
-------------------------------------------------------------------
Thu Apr 13 22:44:24 UTC 2023 - Matej Cepl <mcepl@suse.com>
- Make calling of %{sle15modernpython} optional.
-------------------------------------------------------------------
Thu Oct 29 12:43:29 UTC 2020 - John Vandenberg <jayvdb@gmail.com>
- Disable building on Python 2
- Use LICENSE from PyPI sdist
- Update to v1.1.0
-------------------------------------------------------------------
Thu Oct 29 00:58:23 UTC 2020 - John Vandenberg <jayvdb@gmail.com>
- Add test suite and LICENSE from upstream
- Activate test suite
-------------------------------------------------------------------
Sat Feb 15 03:48:46 AM UTC 2020 - John Vandenberg <jayvdb@gmail.com>
- Initial spec for v1.0.0

64
python-re-assert.spec Normal file
View File

@ -0,0 +1,64 @@
#
# spec file for package python-re-assert
#
# Copyright (c) 2023 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%define skip_python2 1
%{?sle15_python_module_pythons}
Name: python-re-assert
Version: 1.1.0
Release: 0
Summary: Show Python regex match assertion failures
License: MIT
Group: Development/Languages/Python
URL: https://github.com/asottile/re-assert
Source: https://files.pythonhosted.org/packages/source/r/re_assert/re_assert-%{version}.tar.gz
Source1: https://raw.githubusercontent.com/asottile/re-assert/master/tests/re_assert_test.py
BuildRequires: %{python_module setuptools}
BuildRequires: fdupes
BuildRequires: python-rpm-macros
Requires: python-regex
BuildArch: noarch
# SECTION test requirements
BuildRequires: %{python_module pytest}
BuildRequires: %{python_module regex}
# /SECTION
%python_subpackages
%description
Show where your regex match assertion failed.
%prep
%setup -q -n re_assert-%{version}
cp %{SOURCE1} .
%build
%python_build
%install
%python_install
%python_expand %fdupes %{buildroot}%{$python_sitelib}
%check
%pytest
%files %{python_files}
%doc README.md
%license LICENSE
%{python_sitelib}/*
%changelog

BIN
re_assert-1.1.0.tar.gz (Stored with Git LFS) Normal file

Binary file not shown.

116
re_assert_test.py Normal file
View File

@ -0,0 +1,116 @@
import re
import pytest
from re_assert import Matches
def test_typeerror_equality_different_type():
with pytest.raises(TypeError):
Matches('foo') == b'foo'
def test_matches_repr_plain():
assert repr(Matches('^foo')) == "Matches('^foo')"
def test_matches_repr_with_flags():
ret = repr(Matches('^foo', re.I))
assert ret == "Matches('^foo', flags=regex.I | regex.V0)"
def test_repr_with_failure():
obj = Matches('^foo')
assert obj != 'fa'
assert repr(obj) == (
"Matches('^foo')\n"
' # regex failed to match at:\n'
' #\n'
' #> fa\n'
' # ^'
)
def test_assert_success():
obj = Matches('foo')
assert obj == 'food'
obj.assert_matches('food')
def test_fail_at_beginning():
with pytest.raises(AssertionError) as excinfo:
Matches('foo').assert_matches('bar')
msg, = excinfo.value.args
assert msg == (
' regex failed to match at:\n'
'\n'
'> bar\n'
' ^'
)
def test_fail_at_end_of_line():
with pytest.raises(AssertionError) as excinfo:
Matches('foo').assert_matches('fo')
msg, = excinfo.value.args
assert msg == (
' regex failed to match at:\n'
'\n'
'> fo\n'
' ^'
)
def test_fail_multiple_lines():
with pytest.raises(AssertionError) as excinfo:
Matches('foo.bar', re.DOTALL).assert_matches('foo\nbr')
msg, = excinfo.value.args
assert msg == (
' regex failed to match at:\n'
'\n'
'> foo\n'
'> br\n'
' ^'
)
def test_fail_end_of_line_with_newline():
with pytest.raises(AssertionError) as excinfo:
Matches('foo.bar', re.DOTALL).assert_matches('foo\n')
msg, = excinfo.value.args
assert msg == (
' regex failed to match at:\n'
'\n'
'> foo\n'
'>\n'
' ^'
)
def test_fail_at_end_of_line_mismatching_newline():
with pytest.raises(AssertionError) as excinfo:
Matches('foo.', re.DOTALL).assert_matches('foo')
msg, = excinfo.value.args
assert msg == (
' regex failed to match at:\n'
'\n'
'> foo\n'
' ^'
)
def test_match_with_tabs():
with pytest.raises(AssertionError) as excinfo:
Matches('f.o.o').assert_matches('f\to\tx\n')
msg, = excinfo.value.args
assert msg == (
' regex failed to match at:\n'
'\n'
'> f\to\tx\n'
' \t \t^'
)
def test_from_pattern():
pattern = re.compile('^foo', flags=re.I)
assert Matches.from_pattern(pattern) == 'FOO'