示例#1
0
def test_datetime_patch():
    clock = TimeMachineClock()
    patcher = DatetimePatcher(clock)
    patcher.start()

    assert datetime.datetime.today() == datetime.datetime.fromtimestamp(0)

    clock.time = 3600
    assert datetime.datetime.today() == datetime.datetime.fromtimestamp(3600)
    patcher.stop()
示例#2
0
def test_time_patch():
    clock = TimeMachineClock()
    
    patcher = TimePatcher(clock)
    patcher.start()
    
    assert time.time() == 0
    clock.time = 3600
    assert time.time() == 3600
    
    patcher.stop()
示例#3
0
def test_sleep_patch():
    clock = TimeMachineClock()
    
    patcher = TimePatcher(clock)
    patcher.start()

    assert time.time() == 0
    time.sleep(3600)
    assert time.time() == 3600
    
    clock.time = 7200
    assert time.time() == 7200

    patcher.stop()
示例#4
0
 def setup_method(self, method):
     """Start a datetime patcher."""
     self.clock = TimeMachineClock()
     self.patcher = DatetimePatcher(clock=self.clock,
                                    event_pool=None,
                                    modules_to_patch=__name__)
     self.patcher.start()
示例#5
0
def test_patcher_stop():
    clock = TimeMachineClock()
    patcher = TimePatcher(clock)
    patcher.start()
    
    assert time.time() == 0
    
    patcher.stop()
    
    assert time.time() != 0
示例#6
0
def test_patcher_stop():
    clock = TimeMachineClock()
    patcher = DatetimePatcher(clock)
    patcher.start()

    assert datetime.datetime.today() == datetime.datetime.fromtimestamp(0)

    patcher.stop()

    assert datetime.datetime.today() != datetime.datetime.fromtimestamp(0)