diff options
author | Barry Warsaw <barry@python.org> | 2001-08-16 20:42:38 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2001-08-16 20:42:38 (GMT) |
commit | f6365e01076d3b9ab7de171c07622f21710206d5 (patch) | |
tree | f55ba0b25a770e3e6dac29a2f203411e0f3adf9d /Lib/test/test_import.py | |
parent | 501c7c7d0eb8c8fb1a9384092efed0141052f324 (diff) | |
download | cpython-f6365e01076d3b9ab7de171c07622f21710206d5.zip cpython-f6365e01076d3b9ab7de171c07622f21710206d5.tar.gz cpython-f6365e01076d3b9ab7de171c07622f21710206d5.tar.bz2 |
Added a test for module repr truncation when the package name is
really long. Closes SF bug #437984.
Diffstat (limited to 'Lib/test/test_import.py')
-rw-r--r-- | Lib/test/test_import.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index b2e3fb6..e2fbc5c 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -69,3 +69,38 @@ try: test_with_extension(ext) finally: del sys.path[0] + +def touch(path): + fp = open(path, 'w') + fp.close() + +# test imports of packages with really long names, but specifically that their +# reprs include the full name +try: + longname = 'areallylongpackageandmodulenametotestreprtruncation' + os.mkdir(longname) + touch(os.path.join(longname, '__init__.py')) + os.mkdir(os.path.join(longname, longname)) + touch(os.path.join(longname, longname, '__init__.py')) + touch(os.path.join(longname, longname, longname + '.py')) + sys.path.insert(0, os.getcwd()) + from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotestreprtruncation + if `areallylongpackageandmodulenametotestreprtruncation` <> \ + "<module 'areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation' from '%s'>" % areallylongpackageandmodulenametotestreprtruncation.__file__: + raise TestFailed, 'module name truncation' +finally: + # Delete recursively + del sys.path[0] + def zap(actions, dirname, names): + for name in names: + actions.append(os.path.join(dirname, name)) + actions = [] + os.path.walk(longname, zap, actions) + actions.append(longname) + actions.sort() + actions.reverse() + for p in actions: + if os.path.isdir(p): + os.rmdir(p) + else: + os.remove(p) |