Development of an internal social media platform with personalised dashboards for students
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.

unittest_reporters_json.py 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (c) 2014 Vlad Temian <vladtemian@gmail.com>
  2. # Copyright (c) 2015-2017 Claudiu Popa <pcmanticore@gmail.com>
  3. # Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>
  4. # Copyright (c) 2016 Derek Gustafson <degustaf@gmail.com>
  5. # Copyright (c) 2017 guillaume2 <guillaume.peillex@gmail.col>
  6. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  7. # For details: https://github.com/PyCQA/pylint/blob/master/COPYING
  8. """Test for the JSON reporter."""
  9. import json
  10. import six
  11. from pylint.lint import PyLinter
  12. from pylint import checkers
  13. from pylint.reporters.json import JSONReporter
  14. def test_simple_json_output():
  15. output = six.StringIO()
  16. reporter = JSONReporter()
  17. linter = PyLinter(reporter=reporter)
  18. checkers.initialize(linter)
  19. linter.config.persistent = 0
  20. linter.reporter.set_output(output)
  21. linter.open()
  22. linter.set_current_module('0123')
  23. linter.add_message('line-too-long', line=1, args=(1, 2))
  24. # we call this method because we didn't actually run the checkers
  25. reporter.display_messages(None)
  26. expected_result = [[
  27. ("column", 0),
  28. ("line", 1),
  29. ("message", "Line too long (1/2)"),
  30. ("message-id", "C0301"),
  31. ("module", "0123"),
  32. ("obj", ""),
  33. ("path", "0123"),
  34. ("symbol", "line-too-long"),
  35. ("type", "convention"),
  36. ]]
  37. report_result = json.loads(output.getvalue())
  38. report_result = [sorted(report_result[0].items(),
  39. key=lambda item: item[0])]
  40. assert report_result == expected_result