Skip to content

Commit

Permalink
Merge branch 'master' into fix/raise_exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Borda authored Oct 17, 2024
2 parents 48cd23b + 5f5dd22 commit 0755934
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 27 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ jobs:
- name: Unit tests (DB)
if: matrix.backend == 'db'
run: pytest -m "mongo" --cov=cachier --cov-report=term --cov-report=xml:cov.xml
- name: Speed eval
run: python tests/speed_eval.py

- name: "Upload coverage to Codecov"
- name: Upload coverage to Codecov
continue-on-error: true
uses: codecov/codecov-action@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
name: cachier_dist
path: dist
- name: Publish distribution 📦 to PyPI
uses: pypa/[email protected].0
uses: pypa/[email protected].2
with:
user: __token__
password: ${{ secrets.pypi_password }}
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
Expand All @@ -23,7 +23,7 @@ repos:
- id: detect-private-key

- repo: https://github.com/crate-ci/typos
rev: v1.22.9
rev: v1.26.0
hooks:
- id: typos
# empty to do not write fixes
Expand All @@ -47,7 +47,7 @@ repos:
args: ["--number"]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
rev: v4.0.0-alpha.8
hooks:
- id: prettier
files: \.(json|yml|yaml|toml)
Expand All @@ -60,7 +60,7 @@ repos:
# - id: mypy

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
rev: v0.6.9
hooks:
# use black formatting
- id: ruff-format
Expand All @@ -71,11 +71,11 @@ repos:
args: ["--fix"]

- repo: https://github.com/tox-dev/pyproject-fmt
rev: 2.1.3
rev: 2.2.4
hooks:
- id: pyproject-fmt
additional_dependencies: [tox]
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.18
rev: v0.20.2
hooks:
- id: validate-pyproject
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ lint.extend-select = [
"A", # see: https://pypi.org/project/flake8-builtins
"B", # see: https://pypi.org/project/flake8-bugbear
"C4", # see: https://pypi.org/project/flake8-comprehensions
"PT", # see: https://pypi.org/project/flake8-pytest-style
]
lint.ignore = [
"C901",
Expand Down
1 change: 1 addition & 0 deletions tests/test_core_lookup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Testing a few basic cachier interfaces."""

import pytest

from cachier import cachier, get_default_params
from cachier.cores.mongo import MissingMongetter

Expand Down
5 changes: 3 additions & 2 deletions tests/test_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import threading
import time

import cachier
import pytest

from tests.test_mongo_core import MONGO_DELTA, _test_mongetter
import cachier
from tests.test_mongo_core import _test_mongetter

MONGO_DELTA = datetime.timedelta(seconds=3)
_default_params = cachier.get_default_params().copy()


Expand Down
12 changes: 7 additions & 5 deletions tests/test_general.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Non-core-specific tests for cachier."""

import datetime
import functools
import os
import queue
Expand All @@ -9,21 +10,22 @@
from random import random
from time import sleep, time

import cachier
import pytest

import cachier
from cachier.core import (
DEFAULT_MAX_WORKERS,
MAX_WORKERS_ENVAR_NAME,
_get_executor,
_max_workers,
_set_max_workers,
)

from tests.test_mongo_core import (
MONGO_DELTA_LONG,
_test_mongetter,
)

MONGO_DELTA_LONG = datetime.timedelta(seconds=10)


def test_information():
print("\ncachier version: ", end="")
Expand Down Expand Up @@ -154,7 +156,7 @@ def _calls_wait_for_calc_timeout_slow(res_queue):


@pytest.mark.parametrize(
"mongetter,backend",
("mongetter", "backend"),
[
pytest.param(_test_mongetter, "mongo", marks=pytest.mark.mongo),
(None, "memory"),
Expand All @@ -176,7 +178,7 @@ def dummy_func(arg_1, arg_2):


@pytest.mark.parametrize(
"mongetter,backend",
("mongetter", "backend"),
[
pytest.param(_test_mongetter, "mongo", marks=pytest.mark.mongo),
(None, "memory"),
Expand Down
1 change: 1 addition & 0 deletions tests/test_memory_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import pandas as pd
import pytest

from cachier import cachier


Expand Down
23 changes: 11 additions & 12 deletions tests/test_mongo_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import queue
import sys
import threading
from datetime import timedelta
from random import random
from time import sleep
from urllib.parse import quote_plus
Expand All @@ -15,13 +14,14 @@
import pymongo
import pytest
from birch import Birch # type: ignore[import-not-found]
from cachier import cachier
from cachier.cores.base import RecalculationNeeded
from cachier.cores.mongo import _MongoCore
from pymongo.errors import OperationFailure
from pymongo.mongo_client import MongoClient
from pymongo_inmemory import MongoClient as InMemoryMongoClient

from cachier import cachier
from cachier.cores.base import RecalculationNeeded
from cachier.cores.mongo import _MongoCore

# === Enables testing vs a real MongoDB instance ===


Expand Down Expand Up @@ -146,16 +146,14 @@ def _test_mongo_caching(arg_1, arg_2):
assert val6 == val5


MONGO_DELTA = timedelta(seconds=3)
MONGO_DELTA_LONG = timedelta(seconds=10)


@pytest.mark.mongo
def test_mongo_stale_after():
"""Testing MongoDB core stale_after functionality."""

@cachier(
mongetter=_test_mongetter, stale_after=MONGO_DELTA, next_time=False
mongetter=_test_mongetter,
stale_after=datetime.timedelta(seconds=3),
next_time=False,
)
def _stale_after_mongo(arg_1, arg_2):
"""Some function."""
Expand Down Expand Up @@ -241,9 +239,10 @@ def _func_w_bad_mongo(arg_1, arg_2):
return random() + arg_1 + arg_2

with pytest.raises(OperationFailure):
val1 = _func_w_bad_mongo(1, 2)
val2 = _func_w_bad_mongo(1, 2)
assert val1 == val2
_func_w_bad_mongo(1, 2)
with pytest.raises(OperationFailure):
_func_w_bad_mongo(1, 2)
# assert val1 == val2


@pytest.mark.mongo
Expand Down
1 change: 1 addition & 0 deletions tests/test_pickle_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import hashlib

import pandas as pd

from cachier import cachier
from cachier.core import _default_params

Expand Down

0 comments on commit 0755934

Please sign in to comment.