diff --git a/.travis.yml b/.travis.yml index b533906..2634bc0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/pytest.ini b/pytest.ini index 09575d5..76bef99 100644 --- a/pytest.ini +++ b/pytest.ini @@ -11,3 +11,4 @@ addopts = -r a -v -s + -m "not prep" diff --git a/tests/prepare_text_caching_test.py b/tests/prepare_text_caching_test.py deleted file mode 100644 index f315b24..0000000 --- a/tests/prepare_text_caching_test.py +++ /dev/null @@ -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) diff --git a/tests/test_pickle_core.py b/tests/test_pickle_core.py index 44d6eaa..6a4a54a 100644 --- a/tests/test_pickle_core.py +++ b/tests/test_pickle_core.py @@ -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)