From 2a0a4c944f8efa658ddb4285e45f8b404ba1ad3274fe14d1b9fb18ac402336a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Schr=C3=B6ter?= Date: Fri, 3 May 2024 22:45:43 +0200 Subject: [PATCH] Sync from SUSE:SLFO:Main python-re-assert revision e4e487b0bd8a281203c6440822d79c54 --- .gitattributes | 23 ++++++++ python-re-assert.changes | 27 +++++++++ python-re-assert.spec | 64 +++++++++++++++++++++ re_assert-1.1.0.tar.gz | 3 + re_assert_test.py | 116 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 233 insertions(+) create mode 100644 .gitattributes create mode 100644 python-re-assert.changes create mode 100644 python-re-assert.spec create mode 100644 re_assert-1.1.0.tar.gz create mode 100644 re_assert_test.py diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9b03811 --- /dev/null +++ b/.gitattributes @@ -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 diff --git a/python-re-assert.changes b/python-re-assert.changes new file mode 100644 index 0000000..42841b8 --- /dev/null +++ b/python-re-assert.changes @@ -0,0 +1,27 @@ +------------------------------------------------------------------- +Fri Apr 21 12:32:42 UTC 2023 - Dirk Müller + +- add sle15_python_module_pythons (jsc#PED-68) + +------------------------------------------------------------------- +Thu Apr 13 22:44:24 UTC 2023 - Matej Cepl + +- Make calling of %{sle15modernpython} optional. + +------------------------------------------------------------------- +Thu Oct 29 12:43:29 UTC 2020 - John Vandenberg + +- 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 + +- Add test suite and LICENSE from upstream +- Activate test suite + +------------------------------------------------------------------- +Sat Feb 15 03:48:46 AM UTC 2020 - John Vandenberg + +- Initial spec for v1.0.0 diff --git a/python-re-assert.spec b/python-re-assert.spec new file mode 100644 index 0000000..9021776 --- /dev/null +++ b/python-re-assert.spec @@ -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 diff --git a/re_assert-1.1.0.tar.gz b/re_assert-1.1.0.tar.gz new file mode 100644 index 0000000..46c71eb --- /dev/null +++ b/re_assert-1.1.0.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5172dfbd2047a15dff2347735dea7e495479cc7e58841199a4a4973256b20464 +size 3869 diff --git a/re_assert_test.py b/re_assert_test.py new file mode 100644 index 0000000..7a1a45b --- /dev/null +++ b/re_assert_test.py @@ -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'