mirror of
https://github.com/wassname/cachier.git
synced 2026-09-10 11:50:23 +08:00
trying to make test_stale_after_next_time pass consistently on python 2.7
This commit is contained in:
@@ -7,9 +7,11 @@
|
||||
# http://www.opensource.org/licenses/MIT-license
|
||||
# Copyright (c) 2016, Shay Palachy <shaypal5@gmail.com>
|
||||
|
||||
import sys # to make sure that pymongo was imported
|
||||
import pickle # for serialization of python objects
|
||||
from datetime import datetime
|
||||
import time # to sleep when waiting on Mongo cache\
|
||||
import warnings # to warn if pymongo is missing
|
||||
|
||||
try:
|
||||
from pymongo import (
|
||||
@@ -20,9 +22,6 @@ try:
|
||||
from bson.binary import Binary # to save binary data to mongodb
|
||||
except ImportError: # pragma: no cover
|
||||
pass
|
||||
# warnings.warn((
|
||||
# "Cachier warning: pymongo was not found. "
|
||||
# "MongoDB cores will not work."))
|
||||
|
||||
from .base_core import _BaseCore
|
||||
|
||||
@@ -39,6 +38,10 @@ class _MongoCore(_BaseCore):
|
||||
_INDEX_NAME = 'func_1_key_1'
|
||||
|
||||
def __init__(self, mongetter, stale_after, next_time):
|
||||
if 'pymongo' not in sys.modules:
|
||||
warnings.warn((
|
||||
"Cachier warning: pymongo was not found. "
|
||||
"MongoDB cores will not function."))
|
||||
_BaseCore.__init__(self, stale_after, next_time)
|
||||
self.mongetter = mongetter
|
||||
self.mongo_collection = self.mongetter()
|
||||
|
||||
@@ -48,7 +48,8 @@ def test_pickle_core():
|
||||
_takes_5_seconds.clear_cache()
|
||||
|
||||
|
||||
DELTA = timedelta(seconds=3)
|
||||
SECONDS_IN_DELTA = 3
|
||||
DELTA = timedelta(seconds=SECONDS_IN_DELTA)
|
||||
|
||||
|
||||
@cachier(stale_after=DELTA, next_time=False)
|
||||
@@ -85,9 +86,10 @@ def test_stale_after_next_time():
|
||||
val3 = _stale_after_next_time(1, 3)
|
||||
assert val1 == val2
|
||||
assert val1 != val3
|
||||
sleep(3)
|
||||
sleep(SECONDS_IN_DELTA + 1)
|
||||
val4 = _stale_after_next_time(1, 2)
|
||||
assert val4 == val1
|
||||
sleep(0.5)
|
||||
val5 = _stale_after_next_time(1, 2)
|
||||
assert val5 != val1
|
||||
_stale_after_next_time.clear_cache()
|
||||
|
||||
Reference in New Issue
Block a user