central timehandling and better mocking during test
This commit is contained in:
@ -4,6 +4,8 @@
|
||||
|
||||
import sys
|
||||
|
||||
import zfs_autobackup.util
|
||||
|
||||
#dirty hack for this error:
|
||||
#AttributeError: module 'collections' has no attribute 'MutableMapping'
|
||||
|
||||
@ -28,6 +30,9 @@ import contextlib
|
||||
import sys
|
||||
import io
|
||||
|
||||
import datetime
|
||||
|
||||
|
||||
TEST_POOLS="test_source1 test_source2 test_target1"
|
||||
ZFS_USERSPACE= subprocess.check_output("dpkg-query -W zfsutils-linux |cut -f2", shell=True).decode('utf-8').rstrip()
|
||||
ZFS_KERNEL= subprocess.check_output("modinfo zfs|grep ^version |sed 's/.* //'", shell=True).decode('utf-8').rstrip()
|
||||
@ -105,3 +110,18 @@ def prepare_zpools():
|
||||
subprocess.check_call("zfs set autobackup:test=child test_source2/fs2", shell=True)
|
||||
|
||||
print("Prepare done")
|
||||
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def mocktime(time_str, format="%Y%m%d%H%M%S"):
|
||||
|
||||
def fake_datetime_now():
|
||||
return datetime.datetime.strptime(time_str, format)
|
||||
|
||||
with patch.object(zfs_autobackup.util,'datetime_now_mock', fake_datetime_now()):
|
||||
yield
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
from basetest import *
|
||||
import time
|
||||
|
||||
class TestZfsAutobackup32(unittest2.TestCase):
|
||||
"""various new 3.2 features"""
|
||||
@ -137,18 +136,39 @@ test_target1/test_source2/fs2/sub@test-20101111000001
|
||||
""")
|
||||
|
||||
|
||||
# def test_stuff(self):
|
||||
#
|
||||
#
|
||||
# shelltest("zfs set autobackup:test=true test_source2")
|
||||
# # shelltest("zfs set readonly=on test_target1")
|
||||
#
|
||||
# with patch('time.strftime', return_value="test-20101111000000"):
|
||||
# self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --clear-mountpoint".split(" ")).run())
|
||||
#
|
||||
# # shelltest("zfs mount test_target1/test_source2/fs2/sub" )
|
||||
#
|
||||
# with patch('time.strftime', return_value="test-20101111000001"):
|
||||
# self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --rollback".split(" ")).run())
|
||||
|
||||
|
||||
#XXX: VERBERTERING VAN ADD VIRTUALSNAPSHOTS IN GIT STASH!
|
||||
def test_thinning(self):
|
||||
|
||||
# time_str = "20111112000000" # month in the "future"
|
||||
# future_timestamp = time_secs = time.mktime(time.strptime(time_str, "%Y%m%d%H%M%S"))
|
||||
# with patch('time.time', return_value=future_timestamp):
|
||||
|
||||
with mocktime("20001001000000"):
|
||||
print(datetime_now(False))
|
||||
self.assertFalse(ZfsAutobackup("test --allow-empty --clear-mountpoint --verbose".split(" ")).run())
|
||||
|
||||
# with patch('time.strftime', return_value="test-20001101000000"):
|
||||
# self.assertFalse(ZfsAutobackup("test --allow-empty --clear-mountpoint test_target1 --no-progress --allow-empty --clear-mountpoint".split(" ")).run())
|
||||
#
|
||||
# with patch('time.strftime', return_value="test-20001201000000"):
|
||||
# self.assertFalse(ZfsAutobackup("test --allow-empty --clear-mountpoint".split(" ")).run())
|
||||
#
|
||||
# with patch('time.strftime', return_value="test-20001202000000"):
|
||||
# self.assertFalse(ZfsAutobackup("test --allow-empty --clear-mountpoint".split(" ")).run())
|
||||
#
|
||||
# time_str="test-20001203000000"
|
||||
# with patch('time.time', return_value=time.mktime(time.strptime(time_str, "test-%Y%m%d%H%M%S"))):
|
||||
# with patch('time.strftime', return_value=time_str):
|
||||
# self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --allow-empty --clear-mountpoint --keep-source=1d2d".split(" ")).run())
|
||||
#
|
||||
#
|
||||
#
|
||||
# r=shelltest("zfs list -H -o name -r -t snapshot test_source1 test_target1")
|
||||
# self.assertMultiLineEqual(r,"""
|
||||
# /test_target1
|
||||
# /test_target1/test_source1/fs1
|
||||
# /test_target1/test_source1/fs1/sub
|
||||
# /test_target1/test_source2/fs2/sub
|
||||
# """)
|
||||
|
||||
Reference in New Issue
Block a user