mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
forward port r66386
This commit is contained in:
parent
d31fdc547b
commit
fcf5d639f5
9 changed files with 157 additions and 60 deletions
|
@ -266,21 +266,24 @@ class RelativeImport(unittest.TestCase):
|
|||
self.assertTrue(hasattr(relimport, "RelativeImport"))
|
||||
|
||||
def test_issue3221(self):
|
||||
# Note for mergers: the 'absolute' tests from the 2.x branch
|
||||
# are missing in Py3k because implicit relative imports are
|
||||
# a thing of the past
|
||||
def check_relative():
|
||||
exec("from . import relimport", ns)
|
||||
# Check both OK with __package__ and __name__ correct
|
||||
# Check relative import OK with __package__ and __name__ correct
|
||||
ns = dict(__package__='test', __name__='test.notarealmodule')
|
||||
check_relative()
|
||||
# Check both OK with only __name__ wrong
|
||||
# Check relative import OK with only __name__ wrong
|
||||
ns = dict(__package__='test', __name__='notarealpkg.notarealmodule')
|
||||
check_relative()
|
||||
# Check relative fails with only __package__ wrong
|
||||
# Check relative import fails with only __package__ wrong
|
||||
ns = dict(__package__='foo', __name__='test.notarealmodule')
|
||||
self.assertRaises(SystemError, check_relative)
|
||||
# Check relative fails with __package__ and __name__ wrong
|
||||
# Check relative import fails with __package__ and __name__ wrong
|
||||
ns = dict(__package__='foo', __name__='notarealpkg.notarealmodule')
|
||||
self.assertRaises(SystemError, check_relative)
|
||||
# Check both fail with package set to a non-string
|
||||
# Check relative import fails with package set to a non-string
|
||||
ns = dict(__package__=object())
|
||||
self.assertRaises(ValueError, check_relative)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue