2017-12-15 11:24:15 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-07-22 21:22:28 +00:00
|
|
|
# Copyright (c) 2015 Aru Sahni <arusahni@gmail.com>
|
2018-07-15 09:36:36 +00:00
|
|
|
# Copyright (c) 2016-2018 Claudiu Popa <pcmanticore@gmail.com>
|
2017-12-15 11:24:15 +00:00
|
|
|
# Copyright (c) 2016 Derek Gustafson <degustaf@gmail.com>
|
|
|
|
# Copyright (c) 2017 Ville Skyttä <ville.skytta@iki.fi>
|
2016-07-22 21:22:28 +00:00
|
|
|
|
2016-06-01 15:11:29 +00:00
|
|
|
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
# For details: https://github.com/PyCQA/pylint/blob/master/COPYING
|
|
|
|
|
2015-12-09 22:52:43 +00:00
|
|
|
"""Unit tests for the config module."""
|
|
|
|
|
|
|
|
import re
|
|
|
|
import sre_constants
|
|
|
|
|
2016-12-02 17:09:18 +00:00
|
|
|
import pytest
|
2015-12-09 22:52:43 +00:00
|
|
|
|
2019-03-09 10:22:36 +00:00
|
|
|
from pylint import config
|
2018-02-04 14:17:40 +00:00
|
|
|
|
2018-09-16 15:33:50 +00:00
|
|
|
RE_PATTERN_TYPE = getattr(re, "Pattern", getattr(re, "_pattern_type", None))
|
2018-02-04 14:17:40 +00:00
|
|
|
|
|
|
|
|
2016-12-06 15:42:53 +00:00
|
|
|
def test__regexp_validator_valid():
|
|
|
|
result = config._regexp_validator(None, None, "test_.*")
|
2018-02-04 14:17:40 +00:00
|
|
|
assert isinstance(result, RE_PATTERN_TYPE)
|
2016-12-06 15:42:53 +00:00
|
|
|
assert result.pattern == "test_.*"
|
|
|
|
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2016-12-06 15:42:53 +00:00
|
|
|
def test__regexp_validator_invalid():
|
|
|
|
with pytest.raises(sre_constants.error):
|
|
|
|
config._regexp_validator(None, None, "test_)")
|
|
|
|
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2016-12-06 15:42:53 +00:00
|
|
|
def test__csv_validator_no_spaces():
|
|
|
|
values = ["One", "Two", "Three"]
|
|
|
|
result = config._csv_validator(None, None, ",".join(values))
|
|
|
|
assert isinstance(result, list)
|
|
|
|
assert len(result) == 3
|
|
|
|
for i, value in enumerate(values):
|
|
|
|
assert result[i] == value
|
|
|
|
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2016-12-06 15:42:53 +00:00
|
|
|
def test__csv_validator_spaces():
|
|
|
|
values = ["One", "Two", "Three"]
|
|
|
|
result = config._csv_validator(None, None, ", ".join(values))
|
|
|
|
assert isinstance(result, list)
|
|
|
|
assert len(result) == 3
|
|
|
|
for i, value in enumerate(values):
|
|
|
|
assert result[i] == value
|
|
|
|
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2016-12-06 15:42:53 +00:00
|
|
|
def test__regexp_csv_validator_valid():
|
2017-04-02 15:07:31 +00:00
|
|
|
pattern_strings = ["test_.*", "foo\\.bar", "^baz$"]
|
2016-12-06 15:42:53 +00:00
|
|
|
result = config._regexp_csv_validator(None, None, ",".join(pattern_strings))
|
|
|
|
for i, regex in enumerate(result):
|
2018-02-04 14:17:40 +00:00
|
|
|
assert isinstance(regex, RE_PATTERN_TYPE)
|
2016-12-06 15:42:53 +00:00
|
|
|
assert regex.pattern == pattern_strings[i]
|
|
|
|
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2016-12-06 15:42:53 +00:00
|
|
|
def test__regexp_csv_validator_invalid():
|
2017-04-02 15:07:31 +00:00
|
|
|
pattern_strings = ["test_.*", "foo\\.bar", "^baz)$"]
|
2016-12-06 15:42:53 +00:00
|
|
|
with pytest.raises(sre_constants.error):
|
|
|
|
config._regexp_csv_validator(None, None, ",".join(pattern_strings))
|