This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Change method of loading .py files in Python tests
- From: Pedro Alves <palves at redhat dot com>
- To: Simon Marchi <simon dot marchi at polymtl dot ca>, gdb-patches at sourceware dot org
- Date: Thu, 26 Jan 2017 16:33:24 +0000
- Subject: Re: [PATCH] Change method of loading .py files in Python tests
- Authentication-results: sourceware.org; auth=none
- References: <20170121045243.1435-1-simon.marchi@polymtl.ca>
On 01/21/2017 04:52 AM, Simon Marchi wrote:
> With my debug build of Python (--with-pydebug), many tests fails because
> of the same issue. Python scripts are loaded by the tests using this
> pattern:
>
> (gdb) python exec (open ('file.py').read ())
>
> This causes Python to output this warning:
>
> __main__:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='file.py' mode='r' encoding='ANSI_X3.4-1968'>
>
> and the test to fail because of that extra output. Instead of using the
> open + read + exec trick which leaks the file and causes the warning,
> why not just source the files?
>
> (gdb) source file.py
Maybe historical. ISTR that "source" didn't read in python
files automatically originally. But I may easily be misremembering.
>
> This patch changes this, and standardizes the test names of the tests I
> touched to "load python file" (some of them were empty, others were
> overly complicated).
Guess we could have:
proc gdb_load_python_file { pyfile {test "load python file"} } {
gdb_test_no_output "source $pyfile" $test
}
But what you have LGTM.
> -gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \
> - "load python file for no debuginfo tests"
> +gdb_test_no_output "source ${remote_python_file}" "load python file for no debuginfo tests"
Long line?
Thanks,
Pedro Alves