You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.6 KiB

  1. import re
  2. import unittest
  3. from gooey.gui.processor import ProcessController
  4. class TestProcessor(unittest.TestCase):
  5. def test_extract_progress(self):
  6. # should pull out a number based on the supplied
  7. # regex and expression
  8. processor = ProcessController("^progress: (\d+)%$", None, 'utf-8')
  9. self.assertEqual(processor._extract_progress(b'progress: 50%'), 50)
  10. processor = ProcessController("total: (\d+)%$", None, 'utf-8')
  11. self.assertEqual(processor._extract_progress(b'my cool total: 100%'), 100)
  12. def test_extract_progress_returns_none_if_no_regex_supplied(self):
  13. processor = ProcessController(None, None, 'utf-8')
  14. self.assertIsNone(processor._extract_progress(b'Total progress: 100%'))
  15. def test_extract_progress_returns_none_if_no_match_found(self):
  16. processor = ProcessController(r'(\d+)%$', None, 'utf-8')
  17. self.assertIsNone(processor._extract_progress(b'No match in dis string'))
  18. def test_eval_progress(self):
  19. # given a match in the string, should eval the result
  20. regex = r'(\d+)/(\d+)$'
  21. processor = ProcessController(regex, r'x[0] / x[1]', 'utf-8')
  22. match = re.search(regex, '50/50')
  23. self.assertEqual(processor._eval_progress(match), 1.0)
  24. def test_eval_progress_returns_none_on_failure(self):
  25. # given a match in the string, should eval the result
  26. regex = r'(\d+)/(\d+)$'
  27. processor = ProcessController(regex, r'x[0] *^/* x[1]', 'utf-8')
  28. match = re.search(regex, '50/50')
  29. self.assertIsNone(processor._eval_progress(match))