TestML.py 966 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from utils import transport
  2. from utils.ml import ML
  3. import unittest
  4. import json
  5. import os
  6. path = os.environ['MONITOR_CONFIG_PATH']
  7. f = open(path)
  8. CONFIG = json.loads( f.read())
  9. f.close()
  10. factory = transport.DataSourceFactory()
  11. #greader = factory.instance(type=ref,args=p)
  12. class TestML(unittest.TestCase):
  13. def setUp(self):
  14. ref = CONFIG['store']['class']['read']
  15. p = CONFIG['store']['args']
  16. p['qid'] = ['apps']
  17. self.greader = factory.instance(type=ref,args=p)
  18. def test_has_date(self):
  19. r = self.greader.read()
  20. self.assertTrue(r)
  21. def test_Filter(self):
  22. r = self.greader.read()
  23. r = r['apps']
  24. x = ML.Filter('label','Google Chrome',r)
  25. for row in x:
  26. self.assertTrue(row['label'] == 'Google Chrome')
  27. def test_Extract(self):
  28. r = self.greader.read()
  29. r = r['apps']
  30. x = ML.Filter('label','Google Chrome',r)
  31. x_ = ML.Extract(['cpu_usage','memory_usage'], x)
  32. print x[0]
  33. print x_
  34. pass
  35. if __name__ == '__main__' :
  36. unittest.main()