[Python-checkins] CVS: python/dist/src/Lib/test test_import.py,1.7,1.8
Barry Warsaw
bwarsaw@users.sourceforge.net
Thu, 16 Aug 2001 13:42:41 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv14474
Modified Files:
test_import.py
Log Message:
Added a test for module repr truncation when the package name is
really long. Closes SF bug #437984.
Index: test_import.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_import.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** test_import.py 2001/08/04 08:12:35 1.7
--- test_import.py 2001/08/16 20:42:38 1.8
***************
*** 70,71 ****
--- 70,106 ----
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)