Mercurial > vim
comparison src/testdir/test_python3.vim @ 22728:1928f863ac6e v8.2.1912
patch 8.2.1912: with Python 3.9 some tests fail
Commit: https://github.com/vim/vim/commit/68a48ee55e55c189b03a6718a0d06af1dfedcd16
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Oct 27 19:59:10 2020 +0100
patch 8.2.1912: with Python 3.9 some tests fail
Problem: With Python 3.9 some tests fail.
Solution: Take into account the different error message. (James McCoy,
closes #7210)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 27 Oct 2020 20:00:03 +0100 |
parents | 2b6d696b063d |
children | 690b84a6a7ce |
comparison
equal
deleted
inserted
replaced
22727:bc07ea7707df | 22728:1928f863ac6e |
---|---|
21 import sys | 21 import sys |
22 import re | 22 import re |
23 | 23 |
24 py33_type_error_pattern = re.compile('^__call__\(\) takes (\d+) positional argument but (\d+) were given$') | 24 py33_type_error_pattern = re.compile('^__call__\(\) takes (\d+) positional argument but (\d+) were given$') |
25 py37_exception_repr = re.compile(r'([^\(\),])(\)+)$') | 25 py37_exception_repr = re.compile(r'([^\(\),])(\)+)$') |
26 py39_type_error_pattern = re.compile('\w+\.([^(]+\(\) takes)') | |
26 | 27 |
27 def emsg(ei): | 28 def emsg(ei): |
28 return ei[0].__name__ + ':' + repr(ei[1].args) | 29 return ei[0].__name__ + ':' + repr(ei[1].args) |
29 | 30 |
30 def ee(expr, g=globals(), l=locals()): | 31 def ee(expr, g=globals(), l=locals()): |
54 msg = msg.replace(newmsg1, oldmsg1) | 55 msg = msg.replace(newmsg1, oldmsg1) |
55 newmsg2 = """'argument must be str, bytes or bytearray, not int'""" | 56 newmsg2 = """'argument must be str, bytes or bytearray, not int'""" |
56 oldmsg2 = '''"Can't convert 'int' object to str implicitly"''' | 57 oldmsg2 = '''"Can't convert 'int' object to str implicitly"''' |
57 if msg.find(newmsg2) > -1: | 58 if msg.find(newmsg2) > -1: |
58 msg = msg.replace(newmsg2, oldmsg2) | 59 msg = msg.replace(newmsg2, oldmsg2) |
60 # Python 3.9 reports errors like "vim.command() takes ..." instead of "command() takes ..." | |
61 msg = py39_type_error_pattern.sub(r'\1', msg) | |
59 elif sys.version_info >= (3, 5) and e.__class__ is ValueError and str(e) == 'embedded null byte': | 62 elif sys.version_info >= (3, 5) and e.__class__ is ValueError and str(e) == 'embedded null byte': |
60 msg = repr((TypeError, TypeError('expected bytes with no null'))) | 63 msg = repr((TypeError, TypeError('expected bytes with no null'))) |
61 else: | 64 else: |
62 msg = repr((e.__class__, e)) | 65 msg = repr((e.__class__, e)) |
63 # Some Python versions say can't, others cannot. | 66 # Some Python versions say can't, others cannot. |
3810 vim.current.window = True:(<class 'TypeError'>, TypeError('expected vim.Window object, but got bool',)) | 3813 vim.current.window = True:(<class 'TypeError'>, TypeError('expected vim.Window object, but got bool',)) |
3811 vim.current.tabpage = True:(<class 'TypeError'>, TypeError('expected vim.TabPage object, but got bool',)) | 3814 vim.current.tabpage = True:(<class 'TypeError'>, TypeError('expected vim.TabPage object, but got bool',)) |
3812 vim.current.xxx = True:(<class 'AttributeError'>, AttributeError('xxx',)) | 3815 vim.current.xxx = True:(<class 'AttributeError'>, AttributeError('xxx',)) |
3813 END | 3816 END |
3814 | 3817 |
3815 call assert_equal(expected, getline(2, '$')) | 3818 let actual = getline(2, '$') |
3819 let n_expected = len(expected) | |
3820 let n_actual = len(actual) | |
3821 call assert_equal(n_expected, n_actual, 'number of lines to compare') | |
3822 | |
3823 " Compare line by line so the errors are easier to understand. Missing lines | |
3824 " are compared with an empty string. | |
3825 for i in range(n_expected > n_actual ? n_expected : n_actual) | |
3826 call assert_equal(i >= n_expected ? '' : expected[i], i >= n_actual ? '' : actual[i]) | |
3827 endfor | |
3816 close! | 3828 close! |
3817 endfunc | 3829 endfunc |
3818 | 3830 |
3819 " Test import | 3831 " Test import |
3820 func Test_python3_import() | 3832 func Test_python3_import() |