Skip to contentSkip to conversation

tools: binman: fix deprecated Python unittest methods

PATCH In review Brandon Maier 2 participants 10 messages Jun 4, 2024 – Jul 15, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 tools: binman: fix deprecated Python unittest methods

The methods unittest.assertEquals() and unittest.assertRegexpMatches() are marked deprecated[1].

In Python 3.12 these aliases have been removed, so do a sed to replace them with their new names.

[1] https://docs.python.org/3.11/library/unittest.html#deprecated-aliases

CC Simon Glass <[email protected]>
CC Alper Nebi Yasak <[email protected]>
---
 tools/binman/entry_test.py  |  6 +--
 tools/binman/fdt_test.py    | 48 ++++++++++++------------
 tools/binman/ftest.py       | 42 ++++++++++-----------
 tools/buildman/func_test.py | 74 ++++++++++++++++++-------------------
 tools/buildman/test.py      |  2 +-
 5 files changed, 86 insertions(+), 86 deletions(-)
tools/binman/entry_test.py +3 -3
index ac6582cf86a..40d74d401a2 100644
@@ -103,7 +103,7 @@ class TestEntry(unittest.TestCase):
         ent = entry.Entry.Create(None, self.GetNode(), 'missing',
                                  missing_etype=True)
         self.assertTrue(isinstance(ent, Entry_blob))
-        self.assertEquals('missing', ent.etype)
+        self.assertEqual('missing', ent.etype)
 
     def testDecompressData(self):
         """Test the DecompressData() method of the base class"""
@@ -111,8 +111,8 @@ class TestEntry(unittest.TestCase):
         base.compress = 'lz4'
         bintools = {}
         base.comp_bintool = base.AddBintool(bintools, '_testing')
-        self.assertEquals(tools.get_bytes(0, 1024), base.CompressData(b'abc'))
-        self.assertEquals(tools.get_bytes(0, 1024), base.DecompressData(b'abc'))
+        self.assertEqual(tools.get_bytes(0, 1024), base.CompressData(b'abc'))
+        self.assertEqual(tools.get_bytes(0, 1024), base.DecompressData(b'abc'))
 
     def testLookupOffset(self):
         """Test the lookup_offset() method of the base class"""
tools/binman/fdt_test.py +24 -24

67 lines not on this page · raw message

tools/binman/ftest.py +21 -21

136 lines not on this page · raw message

tools/buildman/func_test.py +37 -37

159 lines not on this page · raw message

tools/buildman/test.py +1 -1
index f92add7a7c5..79164bd1993 100644
@@ -584,7 +584,7 @@ class TestBuild(unittest.TestCase):
         if use_network:
             with test_util.capture_sys_output() as (stdout, stderr):
                 url = self.toolchains.LocateArchUrl('arm')
-            self.assertRegexpMatches(url, 'https://www.kernel.org/pub/tools/'
+            self.assertRegex(url, 'https://www.kernel.org/pub/tools/'
                     'crosstool/files/bin/x86_64/.*/'
                     'x86_64-gcc-.*-nolibc[-_]arm-.*linux-gnueabi.tar.xz')
 
Signature · 1 line
2.45.1
#1 lore raw

PATCH 2/3 tools: binman: fix deprecated Python ConfigParser methods

The method ConfigParser.readfp() is marked deprecated[1].

In Python 3.12 this method have been removed, so replace it with ConfigParser.read_file().

[1] https://docs.python.org/3.11/library/configparser.html#configparser.ConfigParser.readfp

---
 tools/buildman/bsettings.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/buildman/bsettings.py +1 -1
index e225ac2ca0f..aea724fc559 100644
@@ -29,7 +29,7 @@ def setup(fname=''):
             settings.read(config_fname)
 
 def add_file(data):
-    settings.readfp(io.StringIO(data))
+    settings.read_file(io.StringIO(data))
 
 def get_items(section):
     """Get the items from a section of the config.
Signature · 1 line
2.45.1
Reviewed-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] tools: binman: fix deprecated Python ConfigParser methods

Hi Brandon,

Quoted 6 lines · Brandon Maier

The method ConfigParser.readfp() is marked deprecated[1].

In Python 3.12 this method have been removed, so replace it with ConfigParser.read_file().

Quoted 7 lines

[1] https://docs.python.org/3.11/library/configparser.html#configparser.ConfigParser.readfp

---
 tools/buildman/bsettings.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Does this still work in earlier Pythons?

Regards,
Simon

#3 lore raw

RE: [External] Re: [PATCH 2/3] tools: binman: fix deprecated Python ConfigParser methods

Hi Simon,

Quoted 26 lines

-----Original Message-----
From: Simon Glass <[email protected]>
Sent: Tuesday, June 4, 2024 9:14 PM
To: Maier, Brandon L Collins <[email protected]>
Cc: [email protected]
Subject: [External] Re: [PATCH 2/3] tools: binman: fix deprecated Python ConfigParser methods

Hi Brandon,

Quoted 7 lines · Brandon Maier

The method ConfigParser.readfp() is marked deprecated[1].

In Python 3.12 this method have been removed, so replace it with ConfigParser.read_file().

[1]

https://docs.python.org/3.11/library/configparser.html#configparser.ConfigParser.read_file

Quoted 5 lines
---
 tools/buildman/bsettings.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 3 lines

Does this still work in earlier Pythons?

The Python docs say ConfigParser.read_file() was added in Python 3.2.
The tools/buildman/pyproject.toml says requires-python = ">=3.7" so I assume this is fine.

Quoted 3 lines

Regards,
Simon

#4 lore raw

Re: RE: [External] Re: [PATCH 2/3] tools: binman: fix deprecated Python ConfigParser methods

Hi Simon,

Quoted 26 lines

-----Original Message-----
From: Simon Glass <[email protected]>
Sent: Tuesday, June 4, 2024 9:14 PM
To: Maier, Brandon L Collins <[email protected]>
Cc: [email protected]
Subject: [External] Re: [PATCH 2/3] tools: binman: fix deprecated Python ConfigParser methods

Hi Brandon,

Quoted 7 lines · Brandon Maier

The method ConfigParser.readfp() is marked deprecated[1].

In Python 3.12 this method have been removed, so replace it with ConfigParser.read_file().

[1]

https://docs.python.org/3.11/library/configparser.html#configparser.ConfigParser.read_file

Quoted 5 lines
---
 tools/buildman/bsettings.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 3 lines

Does this still work in earlier Pythons?

The Python docs say ConfigParser.read_file() was added in Python 3.2. The tools/buildman/pyproject.toml says requires-python = ">=3.7" so I assume this is fine.

Quoted 3 lines

Regards,
Simon

Applied to u-boot-dm, thanks!

#5 lore raw

PATCH 3/3 tools: patman: fix deprecated Python ConfigParser methods

In reply to Brandon Maier

The method ConfigParser.readfp() is marked deprecated[1].

In Python 3.12 this method have been removed, so replace it with ConfigParser.read_file().

[1] https://docs.python.org/3.11/library/configparser.html#configparser.ConfigParser.readfp

---
 tools/patman/settings.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/patman/settings.py +4 -4
index 636983e32da..68c93e313b3 100644
@@ -59,25 +59,25 @@ class _ProjectConfigParser(ConfigParser.ConfigParser):
 
     # Check to make sure that bogus project gets general alias.
     >>> config = _ProjectConfigParser("zzz")
-    >>> config.readfp(StringIO(sample_config))
+    >>> config.read_file(StringIO(sample_config))
     >>> str(config.get("alias", "enemies"))
     'Evil <[email protected]>'
 
     # Check to make sure that alias gets overridden by project.
     >>> config = _ProjectConfigParser("sm")
-    >>> config.readfp(StringIO(sample_config))
+    >>> config.read_file(StringIO(sample_config))
     >>> str(config.get("alias", "enemies"))
     'Green G. <[email protected]>'
 
     # Check to make sure that settings get merged with project.
     >>> config = _ProjectConfigParser("linux")
-    >>> config.readfp(StringIO(sample_config))
+    >>> config.read_file(StringIO(sample_config))
     >>> sorted((str(a), str(b)) for (a, b) in config.items("settings"))
     [('am_hero', 'True'), ('check_patch_use_tree', 'True'), ('process_tags', 'False')]
 
     # Check to make sure that settings works with unknown project.
     >>> config = _ProjectConfigParser("unknown")
-    >>> config.readfp(StringIO(sample_config))
+    >>> config.read_file(StringIO(sample_config))
     >>> sorted((str(a), str(b)) for (a, b) in config.items("settings"))
     [('am_hero', 'True')]
     """
Signature · 1 line
2.45.1
Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] tools: patman: fix deprecated Python ConfigParser methods

Quoted 6 lines · Brandon Maier

The method ConfigParser.readfp() is marked deprecated[1].

In Python 3.12 this method have been removed, so replace it with ConfigParser.read_file().

Quoted 7 lines

[1] https://docs.python.org/3.11/library/configparser.html#configparser.ConfigParser.readfp

---
 tools/patman/settings.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Reviewed-by
#7 lore raw

Re: [PATCH 3/3] tools: patman: fix deprecated Python ConfigParser methods

Quoted 6 lines · Brandon Maier

The method ConfigParser.readfp() is marked deprecated[1].

In Python 3.12 this method have been removed, so replace it with ConfigParser.read_file().

Quoted 7 lines

[1] https://docs.python.org/3.11/library/configparser.html#configparser.ConfigParser.readfp

---
 tools/patman/settings.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Applied to u-boot-dm, thanks!

Reviewed-by on v1 1/3
#8 lore raw
In reply to Brandon Maier
Quoted 12 lines · Brandon Maier

The methods unittest.assertEquals() and unittest.assertRegexpMatches() are marked deprecated[1].

In Python 3.12 these aliases have been removed, so do a sed to replace them with their new names.

[1] https://docs.python.org/3.11/library/unittest.html#deprecated-aliases

CC Simon Glass <[email protected]>
CC Alper Nebi Yasak <[email protected]>
Quoted 7 lines
---
 tools/binman/entry_test.py  |  6 +--
 tools/binman/fdt_test.py    | 48 ++++++++++++------------
 tools/binman/ftest.py       | 42 ++++++++++-----------
 tools/buildman/func_test.py | 74 ++++++++++++++++++-------------------
 tools/buildman/test.py      |  2 +-
 5 files changed, 86 insertions(+), 86 deletions(-)
Reviewed-by
#9 lore raw
Quoted 12 lines · Brandon Maier

The methods unittest.assertEquals() and unittest.assertRegexpMatches() are marked deprecated[1].

In Python 3.12 these aliases have been removed, so do a sed to replace them with their new names.

[1] https://docs.python.org/3.11/library/unittest.html#deprecated-aliases

CC Simon Glass <[email protected]>
CC Alper Nebi Yasak <[email protected]>
Quoted 7 lines
---
 tools/binman/entry_test.py  |  6 +--
 tools/binman/fdt_test.py    | 48 ++++++++++++------------
 tools/binman/ftest.py       | 42 ++++++++++-----------
 tools/buildman/func_test.py | 74 ++++++++++++++++++-------------------
 tools/buildman/test.py      |  2 +-
 5 files changed, 86 insertions(+), 86 deletions(-)

Applied to u-boot-dm, thanks!