Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full test coverage #14

Merged
merged 1 commit into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
cache-dependency-path: requirements-dev.txt

- name: Install dev dependencies
run: pip install --root-user-action=ignore --requirement requirements-dev.txt
run: pip install --root-user-action=ignore --upgrade pip --requirement requirements-dev.txt

# Install library
- name: Install maybe
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ PYTHON_PRE_310 := $(shell python -c "import sys; print(sys.version_info < (3, 10

install: phony
@echo Installing dependencies...
pip install --require-virtualenv -r requirements-dev.txt
pip install --require-virtualenv -e .
python -m pip install --require-virtualenv -r requirements-dev.txt
python -m pip install --require-virtualenv -e .

lint: phony lint-flake lint-mypy

Expand Down
4 changes: 2 additions & 2 deletions src/maybe/maybe.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
Union,
)

if sys.version_info >= (3, 10):
if sys.version_info >= (3, 10): # pragma: no cover
from typing import ParamSpec, TypeAlias, TypeGuard
else:
else: # pragma: no cover
from typing_extensions import ParamSpec, TypeAlias, TypeGuard


Expand Down
13 changes: 11 additions & 2 deletions tests/test_maybe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from maybe import Some, SomeNothing, Maybe, Nothing, UnwrapError
from maybe import Some, SomeNothing, Maybe, Nothing, UnwrapError, is_nothing, is_some


def test_some_factories() -> None:
Expand All @@ -21,6 +21,7 @@ def test_nothing_factory() -> None:
def test_eq() -> None:
assert Some(1) == Some(1)
assert Nothing() == Nothing()
assert not (Nothing() != Nothing())
assert Some(1) != Nothing()
assert Some(1) != Some(2)
assert not (Some(1) != Some(1))
Expand Down Expand Up @@ -60,6 +61,14 @@ def test_some() -> None:
assert res.some_value == 'haha'


def test_some_guard() -> None:
assert is_some(Some(1))


def test_nothing_guard() -> None:
assert is_nothing(Nothing())


def test_nothing() -> None:
res = Nothing()
assert res.is_some() is False
Expand Down Expand Up @@ -185,7 +194,7 @@ def test_slots() -> None:


def sq(i: int) -> Maybe[int]:
return Some(i * i)
return Some(i**2)


def to_nothing(_: int) -> Maybe[int]:
Expand Down
2 changes: 1 addition & 1 deletion tests/type-checking/test_maybe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
some = personalized_greeting.some()
reveal_type(some) # N: Revealed type is "Union[builtins.str, None]"
- case: map_maybe
- case: typeguard
disable_cache: false
main: |
from maybe import Maybe, Some, Nothing, is_some, is_nothing
Expand Down