From 558a4d6a8861f2d7fca27b5f8c9145f89e2b325c Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Mon, 14 May 2018 10:27:28 -0400 Subject: [PATCH 1/4] bpo-33465: Use binascii, as it's less likely to be built-in --- Lib/test/test_import/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index c23fac1ecc24d79..129f8aacfb5b5e8 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -91,12 +91,12 @@ def test_from_import_missing_attr_has_name_and_path(self): self.assertRegex(str(cm.exception), r"cannot import name 'i_dont_exist' from 'os' \(.*os.py\)") def test_from_import_missing_attr_has_name_and_so_path(self): - import select + import binascii with self.assertRaises(ImportError) as cm: - from select import i_dont_exist - self.assertEqual(cm.exception.name, 'select') - self.assertEqual(cm.exception.path, select.__file__) - self.assertRegex(str(cm.exception), r"cannot import name 'i_dont_exist' from 'select' \(.*\.(so|pyd)\)") + from binascii import i_dont_exist + self.assertEqual(cm.exception.name, 'binascii') + self.assertEqual(cm.exception.path, binascii.__file__) + self.assertRegex(str(cm.exception), r"cannot import name 'i_dont_exist' from 'binascii' \(.*\.(so|pyd)\)") def test_from_import_missing_attr_has_name(self): with self.assertRaises(ImportError) as cm: From 402af3222408d1f5e74fd82ee7241a1c6a23a4c5 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Mon, 14 May 2018 10:57:30 -0400 Subject: [PATCH 2/4] Use _hashlib instead, since binascii gets built-in on Debuntu --- Lib/test/test_import/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index 129f8aacfb5b5e8..2301add9de9fd75 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -91,12 +91,12 @@ def test_from_import_missing_attr_has_name_and_path(self): self.assertRegex(str(cm.exception), r"cannot import name 'i_dont_exist' from 'os' \(.*os.py\)") def test_from_import_missing_attr_has_name_and_so_path(self): - import binascii + import _hashlib with self.assertRaises(ImportError) as cm: - from binascii import i_dont_exist - self.assertEqual(cm.exception.name, 'binascii') - self.assertEqual(cm.exception.path, binascii.__file__) - self.assertRegex(str(cm.exception), r"cannot import name 'i_dont_exist' from 'binascii' \(.*\.(so|pyd)\)") + from _hashlib import i_dont_exist + self.assertEqual(cm.exception.name, '_hashlib') + self.assertEqual(cm.exception.path, _hashlib.__file__) + self.assertRegex(str(cm.exception), r"cannot import name 'i_dont_exist' from '_hashlib' \(.*\.(so|pyd)\)") def test_from_import_missing_attr_has_name(self): with self.assertRaises(ImportError) as cm: From 799679d935aae3ed50f52d0b22aa3657c5168766 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Tue, 15 May 2018 10:30:18 -0400 Subject: [PATCH 3/4] Based on PR comments, use _testcapi instead of _hashlib --- Lib/test/test_import/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index 2301add9de9fd75..7b63915526ddda8 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -91,12 +91,12 @@ def test_from_import_missing_attr_has_name_and_path(self): self.assertRegex(str(cm.exception), r"cannot import name 'i_dont_exist' from 'os' \(.*os.py\)") def test_from_import_missing_attr_has_name_and_so_path(self): - import _hashlib + import _testcapi with self.assertRaises(ImportError) as cm: - from _hashlib import i_dont_exist - self.assertEqual(cm.exception.name, '_hashlib') - self.assertEqual(cm.exception.path, _hashlib.__file__) - self.assertRegex(str(cm.exception), r"cannot import name 'i_dont_exist' from '_hashlib' \(.*\.(so|pyd)\)") + from _testcapi import i_dont_exist + self.assertEqual(cm.exception.name, '_testcapi') + self.assertEqual(cm.exception.path, _testcapi.__file__) + self.assertRegex(str(cm.exception), r"cannot import name 'i_dont_exist' from '_testcapi' \(.*\.(so|pyd)\)") def test_from_import_missing_attr_has_name(self): with self.assertRaises(ImportError) as cm: From d781a7970bc6b0b9870a4e70dfaeb360a61abd37 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Tue, 15 May 2018 10:47:23 -0400 Subject: [PATCH 4/4] Only run test_from_import_missing_attr_has_name_and_so_path on CPython --- Lib/test/test_import/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index 7b63915526ddda8..fb9453ad0b39203 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -90,6 +90,7 @@ def test_from_import_missing_attr_has_name_and_path(self): self.assertEqual(cm.exception.path, os.__file__) self.assertRegex(str(cm.exception), r"cannot import name 'i_dont_exist' from 'os' \(.*os.py\)") + @cpython_only def test_from_import_missing_attr_has_name_and_so_path(self): import _testcapi with self.assertRaises(ImportError) as cm: