mirror of
https://github.com/wassname/cachier.git
synced 2026-09-10 11:50:23 +08:00
adler32 solves cross-kernel stable caching on my local machine
This commit is contained in:
+1
-3
@@ -29,7 +29,6 @@ matrix:
|
||||
- pip3 install codecov
|
||||
install:
|
||||
- pip3 install ".[test]"
|
||||
before_script: python3 tests/prepare_text_caching_test.py
|
||||
script: python3 -m pytest
|
||||
after_success: python 3 -m codecov
|
||||
- name: "Python 3.7.3 on macOS 10.14"
|
||||
@@ -43,7 +42,6 @@ matrix:
|
||||
- pip3 install codecov
|
||||
install:
|
||||
- pip3 install ".[test]"
|
||||
before_script: python3 tests/prepare_text_caching_test.py
|
||||
script: python3 -m pytest
|
||||
after_success: python3 -m codecov
|
||||
# ====== WINDOWS =========
|
||||
@@ -87,7 +85,7 @@ install:
|
||||
- echo $TRAVIS_OS_NAME
|
||||
- pip install ".[test]"
|
||||
# - if [ "$TRAVIS_PYTHON_VERSION" == "2.7" ] && ["$TRAVIS_OS_NAME" == "linux"]; then pip install coverage pytest-cov .; else pip install ".[test]"; fi
|
||||
before_script: python tests/prepare_text_caching_test.py
|
||||
before_script: pytest -m prep
|
||||
script: pytest
|
||||
after_success:
|
||||
- codecov # submit coverage to codecov.io
|
||||
|
||||
@@ -11,3 +11,4 @@ addopts =
|
||||
-r a
|
||||
-v
|
||||
-s
|
||||
-m "not prep"
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
"""Prepares a pickle cache for the text hashing test function."""
|
||||
|
||||
|
||||
from cachier import cachier
|
||||
from time import sleep
|
||||
from random import random
|
||||
from pickle import dump, dumps
|
||||
from zlib import adler32
|
||||
|
||||
|
||||
TEXT_VAL_TO_CHECK = 'foo'
|
||||
TEXT_CACHE_FNAME = 'cachier_text_cache_temp.pkl'
|
||||
|
||||
|
||||
@cachier(pickle_reload=False)
|
||||
def text_caching(text):
|
||||
sleep(1)
|
||||
print(text)
|
||||
print(adler32(dumps(text)) & 0xffffffff)
|
||||
return random()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
text_caching.clear_cache()
|
||||
return_val = text_caching(TEXT_VAL_TO_CHECK)
|
||||
print(return_val)
|
||||
with open(TEXT_CACHE_FNAME, 'wb+') as f:
|
||||
dump(return_val, f)
|
||||
@@ -16,24 +16,20 @@ from time import (
|
||||
time,
|
||||
sleep
|
||||
)
|
||||
from pickle import load
|
||||
from pickle import load, dump, dumps
|
||||
from datetime import timedelta
|
||||
from random import random
|
||||
from zlib import adler32
|
||||
import threading
|
||||
try:
|
||||
import queue
|
||||
except ImportError: # python 2
|
||||
import Queue as queue
|
||||
|
||||
import pytest
|
||||
from cachier import cachier
|
||||
from cachier.pickle_core import DEF_CACHIER_DIR
|
||||
|
||||
from .prepare_text_caching_test import (
|
||||
TEXT_VAL_TO_CHECK,
|
||||
TEXT_CACHE_FNAME,
|
||||
text_caching,
|
||||
)
|
||||
|
||||
|
||||
# Pickle core tests
|
||||
|
||||
@@ -401,6 +397,27 @@ def test_pickle_core_custom_cache_dir():
|
||||
assert _takes_5_seconds_custom_dir.cache_dpath() == EXPANDED_CUSTOM_DIR
|
||||
|
||||
|
||||
TEXT_VAL_TO_CHECK = 'foo'
|
||||
TEXT_CACHE_FNAME = 'cachier_text_cache_temp.pkl'
|
||||
|
||||
|
||||
@cachier()
|
||||
def text_caching(text):
|
||||
sleep(1)
|
||||
print(text)
|
||||
print(adler32(dumps(text)) & 0xffffffff)
|
||||
return random()
|
||||
|
||||
|
||||
@pytest.mark.prep
|
||||
def test_prep_text_hashing():
|
||||
text_caching.clear_cache()
|
||||
return_val = text_caching(TEXT_VAL_TO_CHECK)
|
||||
print(return_val)
|
||||
with open(TEXT_CACHE_FNAME, 'wb+') as f:
|
||||
dump(return_val, f)
|
||||
|
||||
|
||||
def test_text_hashing():
|
||||
with open(TEXT_CACHE_FNAME, 'rb') as f:
|
||||
first = load(f)
|
||||
|
||||
Reference in New Issue
Block a user