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_reporting.py 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Copyright (c) 2013-2014 LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
  2. # Copyright (c) 2014-2017 Claudiu Popa <pcmanticore@gmail.com>
  3. # Copyright (c) 2014 Calin Don <calin.don@gmail.com>
  4. # Copyright (c) 2014 Google, Inc.
  5. # Copyright (c) 2014 Arun Persaud <arun@nubati.net>
  6. # Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>
  7. # Copyright (c) 2016-2017 Derek Gustafson <degustaf@gmail.com>
  8. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  9. # For details: https://github.com/PyCQA/pylint/blob/master/COPYING
  10. import warnings
  11. import six
  12. from pylint.lint import PyLinter
  13. from pylint import checkers
  14. from pylint.reporters.text import TextReporter, ParseableTextReporter
  15. import pytest
  16. @pytest.fixture(scope='module')
  17. def reporter(reporter):
  18. return TextReporter
  19. @pytest.fixture(scope='module')
  20. def disable(disable):
  21. return ['I']
  22. def test_template_option(linter):
  23. output = six.StringIO()
  24. linter.reporter.set_output(output)
  25. linter.set_option('msg-template', '{msg_id}:{line:03d}')
  26. linter.open()
  27. linter.set_current_module('0123')
  28. linter.add_message('C0301', line=1, args=(1, 2))
  29. linter.add_message('line-too-long', line=2, args=(3, 4))
  30. assert output.getvalue() == \
  31. '************* Module 0123\n' \
  32. 'C0301:001\n' \
  33. 'C0301:002\n'
  34. def test_parseable_output_deprecated():
  35. with warnings.catch_warnings(record=True) as cm:
  36. warnings.simplefilter("always")
  37. ParseableTextReporter()
  38. assert len(cm) == 1
  39. assert isinstance(cm[0].message, DeprecationWarning)
  40. def test_parseable_output_regression():
  41. output = six.StringIO()
  42. with warnings.catch_warnings(record=True):
  43. linter = PyLinter(reporter=ParseableTextReporter())
  44. checkers.initialize(linter)
  45. linter.config.persistent = 0
  46. linter.reporter.set_output(output)
  47. linter.set_option('output-format', 'parseable')
  48. linter.open()
  49. linter.set_current_module('0123')
  50. linter.add_message('line-too-long', line=1, args=(1, 2))
  51. assert output.getvalue() == \
  52. '************* Module 0123\n' \
  53. '0123:1: [C0301(line-too-long), ] ' \
  54. 'Line too long (1/2)\n'
  55. def test_display_results_is_renamed():
  56. class CustomReporter(TextReporter):
  57. def _display(self, layout):
  58. return None
  59. reporter = CustomReporter()
  60. with pytest.raises(AttributeError):
  61. reporter.display_results