test_toucher.py 887 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. import unittest
  3. import time
  4. import media.monitor.pure as mmp
  5. from media.monitor.toucher import Toucher, ToucherThread
  6. class BaseTest(unittest.TestCase):
  7. def setUp(self):
  8. self.p = "api_client.cfg"
  9. class TestToucher(BaseTest):
  10. def test_toucher(self):
  11. t1 = mmp.last_modified(self.p)
  12. t = Toucher(self.p)
  13. t()
  14. t2 = mmp.last_modified(self.p)
  15. print("(t1,t2) = (%d, %d) diff => %d" % (t1, t2, t2 - t1))
  16. self.assertTrue( t2 > t1 )
  17. class TestToucherThread(BaseTest):
  18. def test_thread(self):
  19. t1 = mmp.last_modified(self.p)
  20. ToucherThread(self.p, interval=1)
  21. time.sleep(2)
  22. t2 = mmp.last_modified(self.p)
  23. print("(t1,t2) = (%d, %d) diff => %d" % (t1, t2, t2 - t1))
  24. self.assertTrue( t2 > t1 )
  25. if __name__ == '__main__': unittest.main()