# -*- coding: utf-8 -*- # Copyright (c) 2013-2014 Google, Inc. # Copyright (c) 2013-2014 LOGILAB S.A. (Paris, FRANCE) # Copyright (c) 2014 Arun Persaud # Copyright (c) 2015-2018 Claudiu Popa # Copyright (c) 2015 Aru Sahni # Copyright (c) 2015 Ionel Cristian Maries # Copyright (c) 2016 Derek Gustafson # Copyright (c) 2016 Glenn Matthews # Copyright (c) 2017-2018 Anthony Sottile # Copyright (c) 2017 Pierre Sassoulas # Copyright (c) 2017 ttenhoeve-aa # Copyright (c) 2017 Łukasz Rogalski # Copyright (c) 2018 Pierre Sassoulas # 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 import io import re from pylint.utils import utils def test__basename_in_blacklist_re_match(): patterns = [re.compile(".*enchilada.*"), re.compile("unittest_.*")] assert utils._basename_in_blacklist_re("unittest_utils.py", patterns) assert utils._basename_in_blacklist_re("cheese_enchiladas.xml", patterns) def test__basename_in_blacklist_re_nomatch(): patterns = [re.compile(".*enchilada.*"), re.compile("unittest_.*")] assert not utils._basename_in_blacklist_re("test_utils.py", patterns) assert not utils._basename_in_blacklist_re("enchilad.py", patterns) def test_decoding_stream_unknown_encoding(): """decoding_stream should fall back to *some* decoding when given an unknown encoding. """ binary_io = io.BytesIO(b"foo\nbar") stream = utils.decoding_stream(binary_io, "garbage-encoding") # should still act like a StreamReader ret = stream.readlines() assert ret == ["foo\n", "bar"] def test_decoding_stream_known_encoding(): binary_io = io.BytesIO("€".encode("cp1252")) stream = utils.decoding_stream(binary_io, "cp1252") assert stream.read() == "€"