mirror of
https://github.com/wassname/cachier.git
synced 2026-09-09 11:19:08 +08:00
trying to reproduce unstable hash bug on travis
This commit is contained in:
@@ -29,6 +29,7 @@ matrix:
|
||||
- pip3 install codecov
|
||||
install:
|
||||
- pip3 install ".[test]"
|
||||
before_script: python3 test/prepare_text_caching_test.py
|
||||
script: python3 -m pytest
|
||||
after_success: python 3 -m codecov
|
||||
- name: "Python 3.7.3 on macOS 10.14"
|
||||
@@ -42,6 +43,7 @@ matrix:
|
||||
- pip3 install codecov
|
||||
install:
|
||||
- pip3 install ".[test]"
|
||||
before_script: python3 test/prepare_text_caching_test.py
|
||||
script: python3 -m pytest
|
||||
after_success: python3 -m codecov
|
||||
# ====== WINDOWS =========
|
||||
@@ -85,6 +87,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 test/prepare_text_caching_test.py
|
||||
script: pytest
|
||||
after_success:
|
||||
- codecov # submit coverage to codecov.io
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
€G?Öľ2ÍM)F.
|
||||
@@ -0,0 +1,25 @@
|
||||
"""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
|
||||
|
||||
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(hash(text))
|
||||
return random()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
return_val = text_caching(TEXT_VAL_TO_CHECK)
|
||||
print(return_val)
|
||||
with open(TEXT_CACHE_FNAME, 'wb+') as f:
|
||||
dump(return_val, f)
|
||||
@@ -16,6 +16,7 @@ from time import (
|
||||
time,
|
||||
sleep
|
||||
)
|
||||
from pickle import load
|
||||
from datetime import timedelta
|
||||
from random import random
|
||||
import threading
|
||||
@@ -27,6 +28,12 @@ except ImportError: # python 2
|
||||
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
|
||||
|
||||
@@ -392,3 +399,18 @@ def test_pickle_core_custom_cache_dir():
|
||||
assert end - start < 1
|
||||
_takes_5_seconds_custom_dir.clear_cache()
|
||||
assert _takes_5_seconds_custom_dir.cache_dpath() == EXPANDED_CUSTOM_DIR
|
||||
|
||||
|
||||
def test_text_hashing():
|
||||
text = TEXT_VAL_TO_CHECK
|
||||
with open(TEXT_CACHE_FNAME, 'rb') as f:
|
||||
first = load(f)
|
||||
print('\npickled return val found for text cache text:')
|
||||
print(first)
|
||||
start_time = time()
|
||||
second = text_caching(text)
|
||||
print('second value returned:')
|
||||
print(second)
|
||||
call_time = time() - start_time
|
||||
assert call_time < 1
|
||||
assert first == second
|
||||
|
||||
Reference in New Issue
Block a user