test_utils.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright 2016 by MPI-SWS and Data-Ken Research.
  2. # Licensed under the Apache 2.0 License.
  3. """These tests are designed to be run on a desktop. You can use
  4. them to validate the system before deploying to 8266. They use stub
  5. sensors.
  6. Test wifi.py and logger.py
  7. """
  8. import sys
  9. import os
  10. import os.path
  11. try:
  12. import wifi
  13. import logger
  14. except ImportError:
  15. sys.path.append(os.path.abspath('../'))
  16. import wifi
  17. import logger
  18. import unittest
  19. class TestLogging(unittest.TestCase):
  20. def _cleanup(self):
  21. logger.close_logging()
  22. for f in ['test.log', 'test.log.1']:
  23. if os.path.exists(f):
  24. os.remove(f)
  25. def setUp(self):
  26. self._cleanup()
  27. def tearDown(self):
  28. self._cleanup()
  29. def test_logging(self):
  30. self.assertTrue(not os.path.exists('test.log'))
  31. logger.initialize_logging('test.log', max_len=1024, interactive=True)
  32. l = logger.get_logger()
  33. self.assertTrue(os.path.exists('test.log'))
  34. self.assertTrue(not os.path.exists('test.log.1'))
  35. l.debug('debug msg')
  36. l.info('info msg')
  37. l.warn('warn')
  38. l.error('error')
  39. l.info('d'*1024) # force a rollover
  40. l.info('new file')
  41. self.assertTrue(os.path.exists('test.log'))
  42. self.assertTrue(os.path.exists('test.log.1'))
  43. def test_wifi_connect(self):
  44. wifi.wifi_connect('foo', 'bar')
  45. if __name__ == '__main__':
  46. unittest.main()