semvec/pypi-packages huggingface dataset:
pytest-regex 0.2.0
Select pytest tests with regular expressions
License: MIT
Requires Python: >=3.8

pytest-regex
------------

Use Python Standard Library Regular Expressions to Specify Tests to Run
-----------------------------------------------------------------------

After installing locally with i.e., `python -m pip install .` you can
compare it with more conventional test selection techniques as follows.

Consider working with SciPy development. Let's start off by selecting
all tests with `test_3d` anywhere in their node id, using the conventional/
built-in `-k` flag:

`python dev.py test -- -v -k "test_3d"`

This runs a bunch of tests with string matches as you might expect:

    scipy/io/tests/test_idl.py::TestArrayDimensions::test_3d PASSED
    scipy/io/tests/test_idl.py::TestPointerArray::test_3d PASSED
    scipy/optimize/_trustregion_constr/tests/test_qp_subproblem.py::TestBoxBoundariesIntersections::test_3d_box_constraints PASSED
    scipy/optimize/_trustregion_constr/tests/test_qp_subproblem.py::TestBoxBoundariesIntersections::test_3d_box_constraints_entire_line PASSED
    scipy/optimize/_trustregion_constr/tests/test_qp_subproblem.py::TestModifiedDogleg::test_3d_example PASSED
    scipy/stats/tests/test_stats.py::TestGeometricStandardDeviation::test_3d_array PASSED
    scipy/stats/tests/test_stats.py::TestGeometricStandardDeviation::test_3d_array_axis_type_tuple PASSED
    scipy/stats/tests/test_stats.py::TestGeometricStandardDeviation::test_3d_array_axis_0 PASSED
    scipy/stats/tests/test_stats.py::TestGeometricStandardDeviation::test_3d_array_axis_1 PASSED
    scipy/stats/tests/test_stats.py::TestGeometricStandardDeviation::test_3d_array_axis_2 PASSED
    scipy/stats/tests/test_stats.py::TestFOneWay::test_3d_inputs PASSED

What if you want to run only tests with an exact match to `test_3d` or
`test_3d_example`?

Try `pytest-regex` with:
    python dev.py test -- -v --regex "(.*test_3d$|.*test_3d_example$)"


    scipy/io/tests/test_idl.py::TestArrayDimensions::test_3d PASSED
    scipy/io/tests/test_idl.py::TestPointerArray::test_3d PASSED
    scipy/optimize/_trustregion_constr/tests/test_qp_subproblem.py::TestModifiedDogleg::test_3d_example PASSED

This does what we want, and is probably more concise than the `-k` alternative. In fact,
I'm not entirely sure how one would do this with `-k` in its current form.

How it Works
------------

`pytest-regex` simply passes the Python regular expression through
to the list of node ids, where a node id is structured as follows:

`path/to/test_module.py::TestClass::test_name[parameter_value]`

If the regex matches the node id, the test is retained and executed.
tipsy 0.7.1
tiny type narrowing library
License: MIT
Requires Python: >=3.10

# tipsy

python3.10 introduced user-defined TypeGuards. Finally giving users the ability to actually code type narrowing functions themselves and avoid shortfalls of mypy. However, for most builtin basic types automatic TypeGuards are still missing. Writing these TypeGuards yourself for each of your types from scratch can feel redundant and frustrating. tipsy generates these TypeGuards automatically for you based solely on the type annotations.

## Example 1: TypeGuards

Here's an example of how you can use tipsy to generate TypeGuards for a TypedDict. Let's suppose you have a TypedDict like this:

```python
class Person(TypedDict):
    uid: int
    name: str
```

You might already have observed that you can not use `isinstance` to check whether a variable is of that type.

```python
isinstance({"uid": 5, "name": "jeeves"}, Person)
# TypeError: TypedDict does not support instance and class checks
```

So how can you do type narrowing in that case? Well, you need to write a TypeGuard yourself.

```python
def is_person(data: Any) -> TypeGuard[Person]:
    return (isinstance(data, dict)
        and set(data.keys()) == {"uid", "name"}
        and isinstance(data["uid"], int)
        and isinstance(data["name"], str)
    )

is_person({"uid": 5, "name": "jeeves"}) # True
is_person({"name": "jeeves"}) # False
is_person({"uid": 5.0, "name": "jeeves"}) # False
is_person({"uid": 5, "name": b"jeeves"}) # False
```

As you can see this works perfectly, but these TypeGuards really feel like you are just duplicating the information that is already contained in the type, just to make mypy happy. Well, it's because it is actually duplicated. And even worse, for more complex nested types this gets out of hand quickly. tipsy's `is_type` uses just the information from the type to automatically generate such TypeGuards for you.

```python
is_type({"uid": 5, "name": "jeeves"}, Person) # True
is_type({"name": "jeeves"}, Person) # False
is_type({"uid": 5.0, "name": "jeeves"}, Person) # False
is_type({"uid": 5, "name": b"jeeves"}, Person) # False
```

That's it, it's literally the same function, but automatically generated for you by tipsy.

## Example 2: casting

Another use-case is casting, maybe you know that only one type is valid in a certain scenario. Let's say you again have the same TypedDict:

```python
class Person(TypedDict):
    uid: int
    name: str
```

with tipsy, this is a breeze:

```python
jeeves = cast_to_type({"uid": 5, "name": "jeeves"}, Person)
```