test_general.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from __future__ import absolute_import
  2. from ondemand.service import find_repetitions
  3. from ondemand.service import cloud_download
  4. import unittest
  5. import time
  6. class TestGeneral(unittest.TestCase):
  7. def test_find_repetitions(self):
  8. found = find_repetitions([
  9. {'timestamp': 1519769650, 'confidence': 5},
  10. {'timestamp': 1519769655, 'confidence': 5},
  11. {'timestamp': 1519769660, 'confidence': 15},
  12. {'timestamp': 1519769665, 'confidence': 15},
  13. {'timestamp': 1519769670, 'confidence': 25},
  14. {'timestamp': 1519769675, 'confidence': 47},
  15. {'timestamp': 1519769680, 'confidence': 150},
  16. {'timestamp': 1519769685, 'confidence': 47},
  17. {'timestamp': 1519769690, 'confidence': 19},
  18. {'timestamp': 1519769695, 'confidence': 15},
  19. {'timestamp': 1519769700, 'confidence': 15},
  20. {'timestamp': 1519769705, 'confidence': 15},
  21. {'timestamp': 1519769710, 'confidence': 15},
  22. {'timestamp': 1519769720, 'confidence': 15},
  23. {'timestamp': 1519769725, 'confidence': 150},
  24. {'timestamp': 1519769730, 'confidence': 300},
  25. {'timestamp': 1519769735, 'confidence': 5},
  26. ])
  27. self.assertEquals(len(found), 2)
  28. self.assertEquals(found[0], 1519769670)
  29. self.assertEquals(found[1], 1519769725)
  30. def test_find_empty_repetitions(self):
  31. found = find_repetitions([])
  32. self.assertTrue(not found)
  33. def test_find_not_enough_data(self):
  34. found = find_repetitions([
  35. {'timestamp': 1519769650, 'confidence': 5},
  36. {'timestamp': 1519769655, 'confidence': 5},
  37. {'timestamp': 1519769660, 'confidence': 100},
  38. {'timestamp': 1519769665, 'confidence': 15},
  39. {'timestamp': 1519769670, 'confidence': 25}
  40. ])
  41. self.assertTrue(not found)
  42. def test_cloud_download(self):
  43. filename, md5hash = cloud_download(ad_key='-L6EoklO90painUCd7df')
  44. print(filename, md5hash)
  45. pass
  46. if __name__ == '__main__':
  47. unittest.main()