[Python-checkins] CVS: python/dist/src/Lib/test test_commands.py,NONE,1.1.2.1 test_fpformat.py,NONE,1.3.2.1 test_glob.py,NONE,1.1.2.1 test_b1.py,1.34.6.1,1.34.6.2 test_ntpath.py,1.7.6.1,1.7.6.2 test_unicode.py,1.31.6.2,1.31.6.3

Tim Peters tim_one@users.sourceforge.net
2001年7月27日 22:03:01 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv14630/descr/dist/src/Lib/test
Modified Files:
 Tag: descr-branch
	test_b1.py test_ntpath.py test_unicode.py 
Added Files:
 Tag: descr-branch
	test_commands.py test_fpformat.py test_glob.py 
Log Message:
Merge of trunk tags date2001-07-21 to date2001-07-28.
--- NEW FILE: test_commands.py ---
'''
 Tests for commands module
 Nick Mathewson
'''
import unittest
import os, tempfile, re
from test_support import TestSkipped, run_unittest
from commands import *
# The module says:
# "NB This only works (and is only relevant) for UNIX."
#
# Actually, getoutput should work on any platform with an os.popen, but
# I'll take the comment as given, and skip this suite.
if os.name != 'posix':
 raise TestSkipped('Not posix; skipping test_commands')
class CommandTests(unittest.TestCase):
 def test_getoutput(self):
 self.assertEquals(getoutput('echo xyzzy'), 'xyzzy')
 self.assertEquals(getstatusoutput('echo xyzzy'), (0, 'xyzzy'))
 # we use mktemp in the next line to get a filename which we
 # _know_ won't exist. This is guaranteed to fail.
 status, output = getstatusoutput('cat ' + tempfile.mktemp())
 self.assertNotEquals(status, 0)
 def test_getstatus(self):
 # This pattern should match 'ls -ld /bin/ls' on any posix
 # system, however perversely configured.
 pat = r'''-..x..x..x # It is executable.
 \s+\d+ # It has some number of links.
 \s+\w+\s+\w+ # It has a user and group, which may
 # be named anything.
 [^/]* # Skip the date.
 /bin/ls # and end with the name of the file.
 '''
 self.assert_(re.match(pat, getstatus("/bin/ls"), re.VERBOSE))
run_unittest(CommandTests)
--- NEW FILE: test_fpformat.py ---
'''
 Tests for fpformat module
 Nick Mathewson
'''
from test_support import run_unittest
import unittest
from fpformat import fix, sci, NotANumber
StringType = type('')
# Test the old and obsolescent fpformat module.
#
# (It's obsolescent because fix(n,d) == "%.*f"%(d,n) and
# sci(n,d) == "%.*e"%(d,n)
# for all reasonable numeric n and d, except that sci gives 3 exponent
# digits instead of 2.
#
# Differences only occur for unreasonable n and d. <.2 wink>)
class FpformatTest(unittest.TestCase):
 def checkFix(self, n, digits):
 result = fix(n, digits)
 if isinstance(n, StringType):
 n = repr(n)
 expected = "%.*f" % (digits, float(n))
 self.assertEquals(result, expected)
 def checkSci(self, n, digits):
 result = sci(n, digits)
 if isinstance(n, StringType):
 n = repr(n)
 expected = "%.*e" % (digits, float(n))
 # add the extra 0 if needed
 num, exp = expected.split("e")
 if len(exp) < 4:
 exp = exp[0] + "0" + exp[1:]
 expected = "%se%s" % (num, exp)
 self.assertEquals(result, expected)
 def test_basic_cases(self):
 self.assertEquals(fix(100.0/3, 3), '33.333')
 self.assertEquals(sci(100.0/3, 3), '3.333e+001')
 def test_reasonable_values(self):
 for d in range(7):
 for val in (1000.0/3, 1000, 1000.0, .002, 1.0/3, 1e10):
 for realVal in (val, 1.0/val, -val, -1.0/val):
 self.checkFix(realVal, d)
 self.checkSci(realVal, d)
 def test_failing_values(self):
 # Now for 'unreasonable n and d'
 self.assertEquals(fix(1.0, 1000), '1.'+('0'*1000))
 self.assertEquals(sci("1"+('0'*1000), 0), '1e+1000')
 # This behavior is inconsistent. sci raises an exception; fix doesn't.
 yacht = "Throatwobbler Mangrove"
 self.assertEquals(fix(yacht, 10), yacht)
 try:
 sci(yacht, 10)
 except NotANumber:
 pass
 else:
 self.fail("No exception on non-numeric sci")
run_unittest(FpformatTest)
--- NEW FILE: test_glob.py ---
import unittest
from test_support import run_unittest, TESTFN
import glob
import os
def mkdirs(fname):
 if os.path.exists(fname) or fname == '':
 return
 base, file = os.path.split(fname)
 mkdirs(base)
 os.mkdir(fname)
def touchfile(fname):
 base, file = os.path.split(fname)
 mkdirs(base)
 f = open(fname, 'w')
 f.close()
def deltree(fname):
 for f in os.listdir(fname):
 fullname = os.path.join(fname, f)
 if os.path.isdir(fullname):
 deltree(fullname)
 else:
 try:
 os.unlink(fullname)
 except:
 pass
 try:
 os.rmdir(fname)
 except:
 pass
class GlobTests(unittest.TestCase):
 def norm(self, *parts):
 return os.path.normpath(os.path.join(self.tempdir, *parts))
 def mktemp(self, *parts):
 touchfile(self.norm(*parts))
 def setUp(self):
 self.tempdir = TESTFN+"_dir"
 self.mktemp('a', 'D')
 self.mktemp('aab', 'F')
 self.mktemp('aaa', 'zzzF')
 self.mktemp('ZZZ')
 self.mktemp('a', 'bcd', 'EF')
 self.mktemp('a', 'bcd', 'efg', 'ha')
 def tearDown(self):
 deltree(self.tempdir)
 def glob(self, *parts):
 if len(parts) == 1:
 pattern = parts[0]
 else:
 pattern = os.path.join(*parts)
 p = os.path.join(self.tempdir, pattern)
 return glob.glob(p)
 def assertSequencesEqual_noorder(self, l1, l2):
 l1 = list(l1)
 l2 = list(l2)
 l1.sort()
 l2.sort()
 self.assertEqual(l1, l2)
 def test_glob_literal(self):
 eq = self.assertSequencesEqual_noorder
 np = lambda *f: norm(self.tempdir, *f)
 eq(self.glob('a'), [self.norm('a')])
 eq(self.glob('a', 'D'), [self.norm('a', 'D')])
 eq(self.glob('aab'), [self.norm('aab')])
 eq(self.glob('zymurgy'), [])
 def test_glob_one_directory(self):
 eq = self.assertSequencesEqual_noorder
 np = lambda *f: norm(self.tempdir, *f)
 eq(self.glob('a*'), map(self.norm, ['a', 'aab', 'aaa']))
 eq(self.glob('*a'), map(self.norm, ['a', 'aaa']))
 eq(self.glob('aa?'), map(self.norm, ['aaa', 'aab']))
 eq(self.glob('aa[ab]'), map(self.norm, ['aaa', 'aab']))
 eq(self.glob('*q'), [])
 def test_glob_nested_directory(self):
 eq = self.assertSequencesEqual_noorder
 np = lambda *f: norm(self.tempdir, *f)
 if os.path.normcase("abCD") == "abCD":
 # case-sensitive filesystem
 eq(self.glob('a', 'bcd', 'E*'), [self.norm('a', 'bcd', 'EF')])
 else:
 # case insensitive filesystem
 eq(self.glob('a', 'bcd', 'E*'), [self.norm('a', 'bcd', 'EF'),
 self.norm('a', 'bcd', 'efg')])
 eq(self.glob('a', 'bcd', '*g'), [self.norm('a', 'bcd', 'efg')])
 def test_glob_directory_names(self):
 eq = self.assertSequencesEqual_noorder
 np = lambda *f: norm(self.tempdir, *f)
 eq(self.glob('*', 'D'), [self.norm('a', 'D')])
 eq(self.glob('*', '*a'), [])
 eq(self.glob('a', '*', '*', '*a'),
 [self.norm('a', 'bcd', 'efg', 'ha')])
 eq(self.glob('?a?', '*F'), map(self.norm, [os.path.join('aaa', 'zzzF'),
 os.path.join('aab', 'F')]))
run_unittest(GlobTests)
Index: test_b1.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_b1.py,v
retrieving revision 1.34.6.1
retrieving revision 1.34.6.2
diff -C2 -d -r1.34.6.1 -r1.34.6.2
*** test_b1.py	2001年07月07日 22:55:28	1.34.6.1
--- test_b1.py	2001年07月28日 05:02:59	1.34.6.2
***************
*** 367,370 ****
--- 367,383 ----
 else:
 raise TestFailed, "int(%s)" % `s[1:]` + " should raise ValueError"
+ try:
+ int(1e100)
+ except OverflowError:
+ pass
+ else:
+ raise TestFailed("int(1e100) expected OverflowError")
+ try:
+ int(-1e100)
+ except OverflowError:
+ pass
+ else:
+ raise TestFailed("int(-1e100) expected OverflowError")
+ 
 
 # SF bug 434186: 0x80000000/2 != 0x80000000>>1.
Index: test_ntpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_ntpath.py,v
retrieving revision 1.7.6.1
retrieving revision 1.7.6.2
diff -C2 -d -r1.7.6.1 -r1.7.6.2
*** test_ntpath.py	2001年07月21日 06:07:13	1.7.6.1
--- test_ntpath.py	2001年07月28日 05:02:59	1.7.6.2
***************
*** 66,69 ****
--- 66,77 ----
 tester('ntpath.join("a", "b\\", "c")', 'a\\b\\c')
 tester('ntpath.join("a", "b", "\\c")', '\\c')
+ tester('ntpath.join("d:\\", "\\pleep")', 'd:\\pleep')
+ tester('ntpath.join("d:\\", "a", "b")', 'd:\\a\\b')
+ tester("ntpath.join('c:', '/a')", 'c:/a')
+ tester("ntpath.join('c:/', '/a')", 'c:/a')
+ tester("ntpath.join('c:/a', '/b')", '/b')
+ tester("ntpath.join('c:', 'd:/')", 'd:/')
+ tester("ntpath.join('c:/', 'd:/')", 'd:/')
+ tester("ntpath.join('c:/', 'd:/a/b')", 'd:/a/b')
 
 if errors:
Index: test_unicode.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_unicode.py,v
retrieving revision 1.31.6.2
retrieving revision 1.31.6.3
diff -C2 -d -r1.31.6.2 -r1.31.6.3
*** test_unicode.py	2001年07月21日 06:07:13	1.31.6.2
--- test_unicode.py	2001年07月28日 05:02:59	1.31.6.3
***************
*** 456,460 ****
 for encoding in ('utf-8',
 'utf-16', 'utf-16-le', 'utf-16-be',
! 'raw_unicode_escape', 'unicode_escape', 'unicode_internal'):
 verify(unicode(u.encode(encoding),encoding) == u)
 
--- 456,461 ----
 for encoding in ('utf-8',
 'utf-16', 'utf-16-le', 'utf-16-be',
! #'raw_unicode_escape',
! 'unicode_escape', 'unicode_internal'):
 verify(unicode(u.encode(encoding),encoding) == u)
 

AltStyle によって変換されたページ (->オリジナル) /