diff mbox series

[U-Boot,v2,3/8] test/py: Import 'configparser' lower case to be python 3.x safe

Message ID 20170914213450.28754-4-paul.burton@imgtec.com
State Accepted
Commit 052ca37daa20a9825d7ce905d632e349f434058d
Delegated to: Simon Glass
Headers show
Series test/py: Fixes for python 3.x | expand

Commit Message

Paul Burton Sept. 14, 2017, 9:34 p.m. UTC
In python 3.x the configparser module is named with all lower case.
Import it as such in order to avoid errors when running on python 3.x,
and fall back to the CamelCase version in order to keep working with
python 2.x.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Reviewed-by: Stephen Warren <swarren@nvidia.com>

---

Changes in v2:
- Import python 2.x ConfigParser as the python 3.x style configparser, rather than the other way around.

 test/py/conftest.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Simon Glass July 10, 2018, 8:57 p.m. UTC | #1
On 14 September 2017 at 15:34, Paul Burton <paul.burton@imgtec.com> wrote:
> In python 3.x the configparser module is named with all lower case.
> Import it as such in order to avoid errors when running on python 3.x,
> and fall back to the CamelCase version in order to keep working with
> python 2.x.
>
> Signed-off-by: Paul Burton <paul.burton@imgtec.com>
> Reviewed-by: Stephen Warren <swarren@nvidia.com>
>
> ---
>
> Changes in v2:
> - Import python 2.x ConfigParser as the python 3.x style configparser, rather than the other way around.
>
>  test/py/conftest.py | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!
Michal Simek Aug. 6, 2018, 10:42 a.m. UTC | #2
On 14.9.2017 23:34, Paul Burton wrote:
> In python 3.x the configparser module is named with all lower case.
> Import it as such in order to avoid errors when running on python 3.x,
> and fall back to the CamelCase version in order to keep working with
> python 2.x.
> 
> Signed-off-by: Paul Burton <paul.burton@imgtec.com>
> Reviewed-by: Stephen Warren <swarren@nvidia.com>
> 
> ---
> 
> Changes in v2:
> - Import python 2.x ConfigParser as the python 3.x style configparser, rather than the other way around.
> 
>  test/py/conftest.py | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/test/py/conftest.py b/test/py/conftest.py
> index ced96f1006..bf55bd3d13 100644
> --- a/test/py/conftest.py
> +++ b/test/py/conftest.py
> @@ -19,11 +19,15 @@ import os
>  import os.path
>  import pytest
>  from _pytest.runner import runtestprotocol
> -import ConfigParser
>  import re
>  import StringIO
>  import sys
>  
> +try:
> +    import configparser
> +except:
> +    import ConfigParser as configparser
> +
>  # Globals: The HTML log file, and the connection to the U-Boot console.
>  log = None
>  console = None
> @@ -167,7 +171,7 @@ def pytest_configure(config):
>          with open(dot_config, 'rt') as f:
>              ini_str = '[root]\n' + f.read()
>              ini_sio = StringIO.StringIO(ini_str)
> -            parser = ConfigParser.RawConfigParser()
> +            parser = configparser.RawConfigParser()
>              parser.readfp(ini_sio)
>              ubconfig.buildconfig.update(parser.items('root'))
>  
> 

I have bisect issue with test/py framework on my PC and I end up on this
patch.

Below is the issue I am getting.

And here are my python version.
[u-boot](test)$ python3 --version
Python 3.4.3
[u-boot](test)$ python --version
Python 2.7.6
[u-boot](test)$ which python
/usr/bin/python


Do you know what could be the issue?

Thanks,
Michal


=====================================================================================================
FAILURES
======================================================================================================
Stephen Warren Aug. 20, 2018, 9:19 p.m. UTC | #3
On 08/06/2018 04:42 AM, Michal Simek wrote:
> On 14.9.2017 23:34, Paul Burton wrote:
>> In python 3.x the configparser module is named with all lower case.
>> Import it as such in order to avoid errors when running on python 3.x,
>> and fall back to the CamelCase version in order to keep working with
>> python 2.x.
...
> I have bisect issue with test/py framework on my PC and I end up on this
> patch.
> 
> Below is the issue I am getting.
> 
> And here are my python version.
> [u-boot](test)$ python3 --version
> Python 3.4.3
> [u-boot](test)$ python --version
> Python 2.7.6
> [u-boot](test)$ which python
> /usr/bin/python
> 
> 
> Do you know what could be the issue?

I honestly can't think why the configuration parsing could cause the 
kind of issue that was shown in the test log. It seems like there's a 
bug in the test/py code w.r.t. receiving characters from the target 
outside the ASCII range, which should be applicable in all cases, but I 
can't see how that would only happen based on how configparser was imported.

> 
> Thanks,
> Michal
> 
> 
> =====================================================================================================
> FAILURES
> ======================================================================================================
> _____________________________________________________________________________________________________
> test_help
> _____________________________________________________________________________________________________
> 
> u_boot_console = <u_boot_console_exec_attach.ConsoleExecAttach object at
> 0x7f1da3e6f290>
> 
>      def test_help(u_boot_console):
>          """Test that the "help" command can be executed."""
> 
>>        u_boot_console.run_command('help')
> 
> test/py/tests/test_help.py:8:
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> test/py/u_boot_console_base.py:181: in run_command
>      self.logstream.write(self.prompt, implicit=True)
> test/py/multiplexed_log.py:65: in write
>      self.logfile.write(self, data, implicit)
> test/py/multiplexed_log.py:688: in write
>      self.f.write(self._escape(data))
> test/py/multiplexed_log.py:335: in _escape
>      c for c in data)
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> 
> .0 = <iterator object at 0x7f1da3d9bb90>
> 
>      data = ''.join((c in self._nonprint) and ('%%%02x' % ord(c)) or
>>                   c for c in data)
> E   UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position
> 32: ordinal not in range(128)
> 
> test/py/multiplexed_log.py:335: UnicodeDecodeError
> ===============================================================================================
> 130 tests deselected
> ================================================================================================
> =====================================================================================
> 1 failed, 130 deselected in 7.32 seconds
> ======================================================================================
> 
> 
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
>
Michal Simek Aug. 21, 2018, 5:48 a.m. UTC | #4
On 20.8.2018 23:19, Stephen Warren wrote:
> On 08/06/2018 04:42 AM, Michal Simek wrote:
>> On 14.9.2017 23:34, Paul Burton wrote:
>>> In python 3.x the configparser module is named with all lower case.
>>> Import it as such in order to avoid errors when running on python 3.x,
>>> and fall back to the CamelCase version in order to keep working with
>>> python 2.x.
> ...
>> I have bisect issue with test/py framework on my PC and I end up on this
>> patch.
>>
>> Below is the issue I am getting.
>>
>> And here are my python version.
>> [u-boot](test)$ python3 --version
>> Python 3.4.3
>> [u-boot](test)$ python --version
>> Python 2.7.6
>> [u-boot](test)$ which python
>> /usr/bin/python
>>
>>
>> Do you know what could be the issue?
> 
> I honestly can't think why the configuration parsing could cause the
> kind of issue that was shown in the test log. It seems like there's a
> bug in the test/py code w.r.t. receiving characters from the target
> outside the ASCII range, which should be applicable in all cases, but I
> can't see how that would only happen based on how configparser was
> imported.

hm. ok.

Thanks,
Michal
diff mbox series

Patch

diff --git a/test/py/conftest.py b/test/py/conftest.py
index ced96f1006..bf55bd3d13 100644
--- a/test/py/conftest.py
+++ b/test/py/conftest.py
@@ -19,11 +19,15 @@  import os
 import os.path
 import pytest
 from _pytest.runner import runtestprotocol
-import ConfigParser
 import re
 import StringIO
 import sys
 
+try:
+    import configparser
+except:
+    import ConfigParser as configparser
+
 # Globals: The HTML log file, and the connection to the U-Boot console.
 log = None
 console = None
@@ -167,7 +171,7 @@  def pytest_configure(config):
         with open(dot_config, 'rt') as f:
             ini_str = '[root]\n' + f.read()
             ini_sio = StringIO.StringIO(ini_str)
-            parser = ConfigParser.RawConfigParser()
+            parser = configparser.RawConfigParser()
             parser.readfp(ini_sio)
             ubconfig.buildconfig.update(parser.items('root'))