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.

35 lines
1.3 KiB

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