Skip to content

Commit

Permalink
fix module error and test optional dependencies (#142)
Browse files Browse the repository at this point in the history
* fix error and test optional dependencies

* fix tests

* fix coverage
  • Loading branch information
adbar authored Aug 8, 2024
1 parent 67f6e00 commit 3e375f2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ omit =
exclude_lines =
pragma: no cover
if __name__ == .__main__.:
except .*ImportError.*:
11 changes: 8 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
matrix:
os: [ubuntu-latest]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13-dev']
env: [{ MINIMAL: "true" }, { MINIMAL: "false" }]
include:
# common versions on MacOS
- os: macos-latest
Expand Down Expand Up @@ -55,8 +56,12 @@ jobs:
# package setup
- uses: actions/checkout@v4

- name: Install package and dependencies
run: pip install .[dev]
- name: Install dependencies
run: python -m pip install ".[dev]"

- name: Install full dependencies
if: ${{ matrix.env.MINIMAL == 'false'}}
run: python -m pip install --ignore-installed ".[marisa-trie]"

# tests
- name: Lint with flake8
Expand All @@ -77,7 +82,7 @@ jobs:

# coverage with default version
- name: Upload coverage to Codecov
if: matrix.python-version == '3.11'
if: ${{ matrix.env.MINIMAL == 'false' && matrix.python-version == '3.11' }}
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ marisa-trie = [
"platformdirs == 4.2.2",
]
test = [
"simplemma[marisa-trie]",
"pytest == 8.3.2",
"pytest-cov == 5.0.0",
]
Expand Down
11 changes: 9 additions & 2 deletions simplemma/strategies/dictionaries/trie_directory_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
from pathlib import Path
from typing import List, Mapping, Optional

from marisa_trie import BytesTrie, HUGE_CACHE # type: ignore[import-not-found]
from platformdirs import user_cache_dir
try:
from marisa_trie import BytesTrie, HUGE_CACHE # type: ignore[import-not-found]
from platformdirs import user_cache_dir
except ImportError:

class BytesTrie: # type: ignore[no-redef]
def __init__(self):
raise ImportError("marisa_trie and platformdirs packages not installed")


from simplemma import __version__ as SIMPLEMMA_VERSION
from simplemma.strategies.dictionaries.dictionary_factory import (
Expand Down
12 changes: 11 additions & 1 deletion tests/strategies/dictionaries/test_trie_dictionary_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
from unittest.mock import call, patch

import pytest
from marisa_trie import BytesTrie # type: ignore[import-not-found]

try:
from marisa_trie import BytesTrie # type: ignore[import-not-found]

HAS_MARISA = True
except ImportError:
HAS_MARISA = False

from simplemma.strategies.dictionaries.trie_directory_factory import TrieWrapDict
from simplemma.strategies import TrieDictionaryFactory


if not HAS_MARISA:
pytest.skip("skipping marisa-trie tests", allow_module_level=True)


def test_exceptions() -> None:
# missing languages or faulty language codes
dictionary_factory = TrieDictionaryFactory(use_disk_cache=False)
Expand Down

0 comments on commit 3e375f2

Please sign in to comment.