def testIsTimeToWorkFirst(self): # test the first run w = Worker() self.mox.ReplayAll() # first and not in worktime t = time.gmtime(time.mktime((2012, 10, 1, 15, 26,40,0,0,0))) w.last_work_min = None istime = False while not istime: now = time.localtime() istime = w.is_timeto_work() if not istime: ret = w.get_leaving_time() sys.stdout.write("\r%02d:%02d:%02d waitting %d seconds for the test of IsTimeToWork \r" % (now.tm_hour, now.tm_min, now.tm_sec, ret)) assert ret == 60 - now.tm_sec sys.stdout.flush() time.sleep(1) print assert now.tm_sec >=0 and now.tm_sec <= 5 assert istime == True assert not w.last_work_min is None self.mox.VerifyAll() print "update_time test \t[\033[1;33mOK\033[0m]" print "is_timeto_work test \t[\033[1;33mOK\033[0m]" print "get_leaving_time test \t[\033[1;33mOK\033[0m]"
def test_istime_to_work(self): w = Worker(None) for _ in range(135): time.sleep(w.working_rate) now = time.localtime() istime = w.is_timeto_work() if not istime: ret = w.get_leaving_time() sys.stdout.write(("\r%02d:%02d:%02d waitting %d seconds for work(last=%d,rate=%d,istime=%s)" % (now.tm_hour, now.tm_min, now.tm_sec , ret , w.last_work_min , w.working_rate , istime))) sys.stdout.flush() continue print sys.stdout.write('%02d:%02d:%02d start fake working.' % (now[3], now[4], now[5])) for __ in range(random.randint(0,60)): sys.stdout.write('.') sys.stdout.flush() time.sleep(1) now = time.localtime() print '\n%02d:%02d:%02d working success finished.' % \ (now[3], now[4], now[5]) w.update_time()