Added test case for non ASCII & non UTF8 encoding Windows-1251 in test_pycode section

This commit is contained in:
hkm 2019-12-15 21:47:57 +03:00
parent 264329079b
commit 1ca9dacbfe
3 changed files with 12 additions and 2 deletions

View File

@ -67,7 +67,7 @@ class ModuleAnalyzer:
if source is not None:
obj = cls.for_string(source, modname, filename if filename is not None else '<string>')
elif filename is not None:
obj = cls.for_file(source, modname)
obj = cls.for_file(filename, modname)
except PycodeError as err:
cls.cache['module', modname] = err
raise

View File

@ -0,0 +1,4 @@
#!python
# -*- coding: windows-1251 -*-
X="Õ" #:It MUST look like X="Õ"

View File

@ -31,13 +31,19 @@ def test_ModuleAnalyzer_for_file():
assert analyzer.encoding is None
def test_ModuleAnalyzer_for_module():
def test_ModuleAnalyzer_for_module(rootdir):
analyzer = ModuleAnalyzer.for_module('sphinx')
assert analyzer.modname == 'sphinx'
assert analyzer.srcname in (SPHINX_MODULE_PATH,
os.path.abspath(SPHINX_MODULE_PATH))
# source should be loaded via native loader, so don`t know file enconding
assert analyzer.encoding == None
path = rootdir / 'test-pycode'
sys.path.insert(0, path)
analyzer = ModuleAnalyzer.for_module('cp_1251_coded')
docs = analyzer.find_attr_docs()
sys.path.pop(0)
assert docs == {('', 'X'): ['It MUST look like X="\u0425"', '']}
def test_ModuleAnalyzer_for_file_in_egg(rootdir):