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_config.py 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # -*- coding: utf-8 -*-
  2. # Copyright (c) 2015 Aru Sahni <arusahni@gmail.com>
  3. # Copyright (c) 2016-2017 Claudiu Popa <pcmanticore@gmail.com>
  4. # Copyright (c) 2016 Derek Gustafson <degustaf@gmail.com>
  5. # Copyright (c) 2017 Ville Skyttä <ville.skytta@iki.fi>
  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. """Unit tests for the config module."""
  9. import re
  10. import sre_constants
  11. from pylint import config
  12. import pytest
  13. def test__regexp_validator_valid():
  14. result = config._regexp_validator(None, None, "test_.*")
  15. assert isinstance(result, re._pattern_type)
  16. assert result.pattern == "test_.*"
  17. def test__regexp_validator_invalid():
  18. with pytest.raises(sre_constants.error):
  19. config._regexp_validator(None, None, "test_)")
  20. def test__csv_validator_no_spaces():
  21. values = ["One", "Two", "Three"]
  22. result = config._csv_validator(None, None, ",".join(values))
  23. assert isinstance(result, list)
  24. assert len(result) == 3
  25. for i, value in enumerate(values):
  26. assert result[i] == value
  27. def test__csv_validator_spaces():
  28. values = ["One", "Two", "Three"]
  29. result = config._csv_validator(None, None, ", ".join(values))
  30. assert isinstance(result, list)
  31. assert len(result) == 3
  32. for i, value in enumerate(values):
  33. assert result[i] == value
  34. def test__regexp_csv_validator_valid():
  35. pattern_strings = ["test_.*", "foo\\.bar", "^baz$"]
  36. result = config._regexp_csv_validator(None, None, ",".join(pattern_strings))
  37. for i, regex in enumerate(result):
  38. assert isinstance(regex, re._pattern_type)
  39. assert regex.pattern == pattern_strings[i]
  40. def test__regexp_csv_validator_invalid():
  41. pattern_strings = ["test_.*", "foo\\.bar", "^baz)$"]
  42. with pytest.raises(sre_constants.error):
  43. config._regexp_csv_validator(None, None, ",".join(pattern_strings))