2016-09-29 23:06:07 -05:00
|
|
|
import datetime
|
|
|
|
import time
|
2017-09-29 11:44:22 +01:00
|
|
|
import os
|
2017-07-27 00:11:12 -04:00
|
|
|
import tempfile
|
|
|
|
import shutil
|
2016-09-29 23:06:07 -05:00
|
|
|
import mock
|
2018-07-21 21:12:33 -04:00
|
|
|
from binascii import hexlify
|
2016-09-29 23:06:07 -05:00
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_TIMESTAMP = datetime.datetime(2016, 1, 1)
|
|
|
|
DEFAULT_ISO_TIME = time.mktime(DEFAULT_TIMESTAMP.timetuple())
|
|
|
|
|
|
|
|
|
2017-07-27 00:11:12 -04:00
|
|
|
def mk_db_and_blob_dir():
|
|
|
|
db_dir = tempfile.mkdtemp()
|
|
|
|
blob_dir = tempfile.mkdtemp()
|
|
|
|
return db_dir, blob_dir
|
|
|
|
|
2018-02-20 13:46:17 -05:00
|
|
|
|
2017-07-27 00:11:12 -04:00
|
|
|
def rm_db_and_blob_dir(db_dir, blob_dir):
|
|
|
|
shutil.rmtree(db_dir, ignore_errors=True)
|
|
|
|
shutil.rmtree(blob_dir, ignore_errors=True)
|
|
|
|
|
2018-02-20 13:46:17 -05:00
|
|
|
|
2017-02-17 19:59:57 -05:00
|
|
|
def random_lbry_hash():
|
2018-07-21 21:12:33 -04:00
|
|
|
return hexlify(os.urandom(48)).decode()
|
2017-02-17 19:59:57 -05:00
|
|
|
|
2018-02-20 13:46:17 -05:00
|
|
|
|
2016-09-29 23:06:07 -05:00
|
|
|
def resetTime(test_case, timestamp=DEFAULT_TIMESTAMP):
|
|
|
|
iso_time = time.mktime(timestamp.timetuple())
|
|
|
|
patcher = mock.patch('time.time')
|
|
|
|
patcher.start().return_value = iso_time
|
|
|
|
test_case.addCleanup(patcher.stop)
|
|
|
|
|
|
|
|
patcher = mock.patch('lbrynet.core.utils.now')
|
|
|
|
patcher.start().return_value = timestamp
|
|
|
|
test_case.addCleanup(patcher.stop)
|
|
|
|
|
|
|
|
patcher = mock.patch('lbrynet.core.utils.utcnow')
|
|
|
|
patcher.start().return_value = timestamp
|
|
|
|
test_case.addCleanup(patcher.stop)
|
2017-10-17 03:11:20 +01:00
|
|
|
|
|
|
|
def is_android():
|
|
|
|
return 'ANDROID_ARGUMENT' in os.environ # detect Android using the Kivy way
|