From 78af2485a783584c4948414a5b4e7f85226154b2 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Wed, 5 Sep 2018 23:50:54 -0600 Subject: [PATCH 1/2] bpo-34594: Fix usage of hardcoded errno values in the tests --- Lib/test/test_spwd.py | 4 +++- Lib/test/test_tabnanny.py | 4 +++- .../next/Tests/2018-09-05-23-50-21.bpo-34594.tqL-GS.rst | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2018-09-05-23-50-21.bpo-34594.tqL-GS.rst diff --git a/Lib/test/test_spwd.py b/Lib/test/test_spwd.py index e893f3a847fdf90..9b426da82ba99e1 100644 --- a/Lib/test/test_spwd.py +++ b/Lib/test/test_spwd.py @@ -1,3 +1,4 @@ +import errno import os import unittest from test import support @@ -68,7 +69,8 @@ def test_getspnam_exception(self): except KeyError as exc: self.skipTest("spwd entry %r doesn't exist: %s" % (name, exc)) else: - self.assertEqual(str(cm.exception), '[Errno 13] Permission denied') + self.assertEqual(str(cm.exception), + f'[Errno {errno.EACCES}] Permission denied') if __name__ == "__main__": diff --git a/Lib/test/test_tabnanny.py b/Lib/test/test_tabnanny.py index ec887361730b96e..845096e63c269ce 100644 --- a/Lib/test/test_tabnanny.py +++ b/Lib/test/test_tabnanny.py @@ -5,6 +5,7 @@ """ from unittest import TestCase, mock from unittest import mock +import errno import tabnanny import tokenize import tempfile @@ -232,7 +233,8 @@ def test_when_nannynag_error(self): def test_when_no_file(self): """A python file which does not exist actually in system.""" path = 'no_file.py' - err = f"{path!r}: I/O Error: [Errno 2] No such file or directory: {path!r}\n" + err = f"{path!r}: I/O Error: [Errno {errno.ENOENT}] " \ + f"No such file or directory: {path!r}\n" self.verify_tabnanny_check(path, err=err) def test_errored_directory(self): diff --git a/Misc/NEWS.d/next/Tests/2018-09-05-23-50-21.bpo-34594.tqL-GS.rst b/Misc/NEWS.d/next/Tests/2018-09-05-23-50-21.bpo-34594.tqL-GS.rst new file mode 100644 index 000000000000000..7a7b1f055561a04 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2018-09-05-23-50-21.bpo-34594.tqL-GS.rst @@ -0,0 +1 @@ +Fix usage of hardcoded ``errno`` values in the tests. From b78a2fd5bf1f1e75e71bc27ec812fccb7ad13446 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Thu, 6 Sep 2018 01:14:34 -0600 Subject: [PATCH 2/2] Remove unnecessary assert. --- Lib/test/test_spwd.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Lib/test/test_spwd.py b/Lib/test/test_spwd.py index 9b426da82ba99e1..07793c84c8e912c 100644 --- a/Lib/test/test_spwd.py +++ b/Lib/test/test_spwd.py @@ -1,4 +1,3 @@ -import errno import os import unittest from test import support @@ -68,9 +67,6 @@ def test_getspnam_exception(self): spwd.getspnam(name) except KeyError as exc: self.skipTest("spwd entry %r doesn't exist: %s" % (name, exc)) - else: - self.assertEqual(str(cm.exception), - f'[Errno {errno.EACCES}] Permission denied') if __name__ == "__main__":