test_commands.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from __future__ import annotations
  2. import sys
  3. sys.path.append("config/commands")
  4. from _split_string import Flake8Error, _update_previous_errors, format_flake8_output
  5. def test_partition_flake8_line():
  6. assert Flake8Error.from_line("existing_lint error.py:12:41: E999 SyntaxError: invalid syntax") == Flake8Error(
  7. "existing_lint error.py", 12, 41, "E999 SyntaxError: invalid syntax"
  8. )
  9. def test_update_previous_errors():
  10. previous_errors = [
  11. Flake8Error("existing_lint_error.py", 12, 41, "E999 SyntaxError: invalid syntax"),
  12. Flake8Error("existing_lint_error.py", 15, 41, "E999 SyntaxError: invalid syntax"),
  13. Flake8Error("existing_lint_error.py", 20, 41, "E999 SyntaxError: invalid syntax"),
  14. ]
  15. assert _update_previous_errors(previous_errors, (15, 18), 3) == [
  16. Flake8Error("existing_lint_error.py", 12, 41, "E999 SyntaxError: invalid syntax"),
  17. Flake8Error("existing_lint_error.py", 19, 41, "E999 SyntaxError: invalid syntax"),
  18. ]
  19. assert _update_previous_errors([], (15, 18), 3) == []
  20. def test_flake8_format_no_error_1():
  21. assert (
  22. format_flake8_output(
  23. "a:12:41: e", previous_errors_string="a:12:41: e", replacement_window=(50, 51), replacement_n_lines=10
  24. )
  25. == ""
  26. )
  27. def test_flake8_format_no_error_2():
  28. assert (
  29. format_flake8_output(
  30. "a:12:41: e", previous_errors_string="a:13:41: e", replacement_window=(1, 2), replacement_n_lines=1
  31. )
  32. == ""
  33. )
  34. def test_flake8_format_no_error_3():
  35. assert (
  36. format_flake8_output(
  37. "a:12:41: e", previous_errors_string="a:13:41: e", replacement_window=(1, 2), replacement_n_lines=1
  38. )
  39. == ""
  40. )
  41. def test_flake8_format_error_1():
  42. assert (
  43. format_flake8_output(
  44. "a:12:41: e", previous_errors_string="a:13:41: e", replacement_window=(12, 13), replacement_n_lines=10
  45. )
  46. == "- e"
  47. )
  48. def test_flake8_format_error_1_linenumbers():
  49. assert (
  50. format_flake8_output(
  51. "a:12:41: e",
  52. previous_errors_string="a:13:41: e",
  53. replacement_window=(12, 13),
  54. replacement_n_lines=10,
  55. show_line_numbers=True,
  56. )
  57. == "- 12:41 e"
  58. )