Skip to content

Commit

Permalink
Merge pull request #1 from pomponchik/develop
Browse files Browse the repository at this point in the history
0.0.1
  • Loading branch information
pomponchik committed Feb 4, 2024
2 parents b40479e + dd58850 commit df360a8
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 1 deletion.
36 changes: 36 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Lint

on:
push

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7']

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
shell: bash
run: pip install -r requirements_dev.txt

- name: Install the library
shell: bash
run: pip install .

- name: Run mypy
shell: bash
run: mypy full_match --strict

- name: Run ruff
shell: bash
run: ruff full_match
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
push:
branches:
- main

jobs:
pypi-publish:
name: upload release to PyPI
runs-on: ubuntu-latest
# Specifying a GitHub environment is optional, but strongly encouraged
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
shell: bash
run: pip install -r requirements_dev.txt

- name: Build the project
shell: bash
run: python -m build .

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
45 changes: 45 additions & 0 deletions .github/workflows/tests_and_coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Tests

on:
push

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install the library
shell: bash
run: pip install .

- name: Install dependencies
shell: bash
run: pip install -r requirements_dev.txt

- name: Print all libs
shell: bash
run: pip list

- name: Run tests and show coverage on the command line
run: coverage run --source=full_match --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m

- name: Upload reports to codecov
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
if: runner.os == 'Linux'
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
find . -iregex "codecov.*"
chmod +x codecov
./codecov -t ${CODECOV_TOKEN}
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.DS_Store
venv
__pycache__
.pytest_cache
*.egg-info
dist
build
.ruff_cache
.mypy_cache
.mutmut-cache
html
.coverage
htmlcov
1 change: 1 addition & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignore = ['E501', 'E712']
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
# full_match
# full_match

[![Downloads](https://static.pepy.tech/badge/full_match/month)](https://pepy.tech/project/full_match)
[![Downloads](https://static.pepy.tech/badge/full_match)](https://pepy.tech/project/full_match)
[![codecov](https://codecov.io/gh/pomponchik/full_match/graph/badge.svg?token=a4c3RY9wo8)](https://codecov.io/gh/pomponchik/full_match)
[![Lines of code](https://sloc.xyz/github/pomponchik/full_match/?category=code)](https://github.com/boyter/scc/)
[![Hits-of-Code](https://hitsofcode.com/github/pomponchik/full_match?branch=main)](https://hitsofcode.com/github/pomponchik/full_match/view?branch=main)
[![Test-Package](https://github.com/pomponchik/full_match/actions/workflows/tests_and_coverage.yml/badge.svg)](https://github.com/pomponchik/full_match/actions/workflows/tests_and_coverage.yml)
[![Python versions](https://img.shields.io/pypi/pyversions/full_match.svg)](https://pypi.python.org/pypi/full_match)
[![PyPI version](https://badge.fury.io/py/full_match.svg)](https://badge.fury.io/py/full_match)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
[![Ruff](https://img.shields.io/endpoint?url=https://github.com/raw/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)


When catching exceptions in [Pytest](https://docs.pytest.org/en/latest/), sometimes you need to check messages. Since the user sends a pattern for searching, and not a message for exact matching, sometimes similar, but not identical messages pass through the filter. This micro-library contains a function that makes Pytest check exception messages accurately.

It may also be useful to you if you use mutation testing tools such as [mutmut](https://github.com/boxed/mutmut).

Install it:

```bash
pip install full_match
```

And use:

```python
import pytest
import full_match

def test_something():
with pytest.raises(AssertionError, match='Regex pattern did not match.'):
with pytest.raises(ValueError, match=full_match('Some message.')):
raise ValueError('XXSome message.XX')
```

The message in the inner `with` block does not match the pattern exactly, so an `AssertionError` exception will occur in this example.
6 changes: 6 additions & 0 deletions full_match/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys

from full_match.proxy_module import ProxyModule as ProxyModule


sys.modules[__name__].__class__ = ProxyModule
7 changes: 7 additions & 0 deletions full_match/proxy_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sys
from re import escape


class ProxyModule(sys.modules[__name__].__class__): # type: ignore[misc]
def __call__(self, string: str) -> str:
return f'^{escape(string)}$'
Empty file added full_match/py.typed
Empty file.
42 changes: 42 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[build-system]
requires = ['setuptools==68.0.0']
build-backend = 'setuptools.build_meta'

[project]
name = 'full_match'
version = '0.0.1'
authors = [
{ name='Evgeniy Blinov', email='zheni-b@yandex.ru' },
]
description = 'One function that makes the string matchable'
readme = 'README.md'
requires-python = '>=3.7'
classifiers = [
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'License :: OSI Approved :: MIT License',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Testing',
'Topic :: Software Development :: Testing :: Unit',
'Intended Audience :: Developers',
'Framework :: Pytest',
]

[tool.setuptools.package-data]
"full_match" = ["py.typed"]

[tool.mutmut]
paths_to_mutate="full_match"
runner="pytest"

[project.urls]
'Source' = 'https://github.com/pomponchik/full_match'
'Tracker' = 'https://github.com/pomponchik/full_match/issues'
8 changes: 8 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pytest==7.4.3
coverage==7.2.7
twine==4.0.2
wheel==0.41.2
build==0.9.0
ruff==0.0.290
mypy==1.4.1
mutmut==2.4.4
Empty file added tests/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions tests/test_proxy_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import re

import pytest

import full_match


def test_simple_match():
assert re.search(full_match('kek'), 'XXkekXX') is None
assert re.search(full_match('kek'), '++kek++') is None


@pytest.mark.parametrize(
'addictional_string', [
'XX',
'XXX',
'kek',
'ogogo',
],
)
def test_exception_message(addictional_string):
with pytest.raises(AssertionError, match='Regex pattern did not match.'):
with pytest.raises(ValueError, match=full_match('kek')):
raise ValueError(f'{addictional_string}kek{addictional_string}')


def test_exception_message_like_in_readme():
with pytest.raises(AssertionError, match='Regex pattern did not match.'):
with pytest.raises(ValueError, match=full_match('Some message.')):
raise ValueError('XXSome message.XX')

0 comments on commit df360a8

Please sign in to comment.