diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/distutils/ccompiler.py | 6 | ||||
-rw-r--r-- | Lib/distutils/command/sdist.py | 1 | ||||
-rwxr-xr-x | Lib/runpy.py | 18 | ||||
-rw-r--r-- | Lib/test/test_itertools.py | 29 | ||||
-rw-r--r-- | Lib/test/test_types.py | 38 |
5 files changed, 81 insertions, 11 deletions
diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py index f4edb7c..1e09123 100644 --- a/Lib/distutils/ccompiler.py +++ b/Lib/distutils/ccompiler.py @@ -147,11 +147,11 @@ class CCompiler: # discovered at run-time, since there are many different ways to do # basically the same things with Unix C compilers. - for key, value in kwargs.items(): + for key in kwargs: if key not in self.executables: - raise ValueError("unknown executable '%s' for class %s" % \ + raise ValueError("unknown executable '%s' for class %s" % (key, self.__class__.__name__)) - self.set_executable(key, value) + self.set_executable(key, kwargs[key]) def set_executable(self, key, value): if isinstance(value, str): diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py index b1c7648..8289925 100644 --- a/Lib/distutils/command/sdist.py +++ b/Lib/distutils/command/sdist.py @@ -357,6 +357,7 @@ class sdist (Command): if line[-1] == '\n': line = line[0:-1] self.filelist.append(line) + manifest.close() def make_release_tree(self, base_dir, files): """Create the directory tree that will become the source diff --git a/Lib/runpy.py b/Lib/runpy.py index 49ce34b..5038266 100755 --- a/Lib/runpy.py +++ b/Lib/runpy.py @@ -89,6 +89,9 @@ def _get_module_details(mod_name): # XXX ncoghlan: Should this be documented and made public? +# (Current thoughts: don't repeat the mistake that lead to its +# creation when run_module() no longer met the needs of +# mainmodule.c, but couldn't be changed because it was public) def _run_module_as_main(mod_name, set_argv0=True): """Runs the designated module in the __main__ namespace @@ -96,7 +99,20 @@ def _run_module_as_main(mod_name, set_argv0=True): __file__ __loader__ """ - loader, code, fname = _get_module_details(mod_name) + try: + loader, code, fname = _get_module_details(mod_name) + except ImportError as exc: + # Try to provide a good error message + # for directories, zip files and the -m switch + if set_argv0: + # For -m switch, just disply the exception + info = str(exc) + else: + # For directories/zipfiles, let the user + # know what the code was looking for + info = "can't find '__main__.py' in %r" % sys.argv[0] + msg = "%s: %s" % (sys.executable, info) + sys.exit(msg) pkg_name = mod_name.rpartition('.')[0] main_globals = sys.modules["__main__"].__dict__ if set_argv0: diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index ae5eb90..380d121 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -5,6 +5,7 @@ from weakref import proxy import sys import operator import random +from functools import reduce maxsize = test_support.MAX_Py_ssize_t minsize = -maxsize-1 @@ -261,6 +262,28 @@ class TestBasicOps(unittest.TestCase): ids = list(map(id, list(izip_longest('abc', 'def')))) self.assertEqual(len(dict.fromkeys(ids)), len(ids)) + def test_product(self): + for args, result in [ + ([], []), # zero iterables ??? is this correct + (['ab'], [('a',), ('b',)]), # one iterable + ([range(2), range(3)], [(0,0), (0,1), (0,2), (1,0), (1,1), (1,2)]), # two iterables + ([range(0), range(2), range(3)], []), # first iterable with zero length + ([range(2), range(0), range(3)], []), # middle iterable with zero length + ([range(2), range(3), range(0)], []), # last iterable with zero length + ]: + self.assertEqual(list(product(*args)), result) + self.assertEqual(len(list(product(*[range(7)]*6))), 7**6) + self.assertRaises(TypeError, product, range(6), None) + argtypes = ['', 'abc', '', range(0), range(4), dict(a=1, b=2, c=3), + set('abcdefg'), range(11), tuple(range(13))] + for i in range(100): + args = [random.choice(argtypes) for j in range(random.randrange(5))] + n = reduce(operator.mul, map(len, args), 1) if args else 0 + self.assertEqual(len(list(product(*args))), n) + args = map(iter, args) + self.assertEqual(len(list(product(*args))), n) + + def test_repeat(self): self.assertEqual(lzip(range(3),repeat('a')), [(0, 'a'), (1, 'a'), (2, 'a')]) @@ -636,6 +659,12 @@ class TestVariousIteratorArgs(unittest.TestCase): self.assertRaises(TypeError, chain, N(s)) self.assertRaises(ZeroDivisionError, list, chain(E(s))) + def test_product(self): + for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)): + self.assertRaises(TypeError, product, X(s)) + self.assertRaises(TypeError, product, N(s)) + self.assertRaises(ZeroDivisionError, product, E(s)) + def test_cycle(self): for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)): for g in (G, I, Ig, S, L, R): diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index f82fe30..654bc11 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -89,6 +89,29 @@ class TypesTests(unittest.TestCase): if float(1) == 1.0 and float(-1) == -1.0 and float(0) == 0.0: pass else: self.fail('float() does not work properly') + def test_float_to_string(self): + def test(f, result): + self.assertEqual(f.__format__('e'), result) + self.assertEqual('%e' % f, result) + + # test all 2 digit exponents, both with __format__ and with + # '%' formatting + for i in range(-99, 100): + test(float('1.5e'+str(i)), '1.500000e{0:+03d}'.format(i)) + + # test some 3 digit exponents + self.assertEqual(1.5e100.__format__('e'), '1.500000e+100') + self.assertEqual('%e' % 1.5e100, '1.500000e+100') + + self.assertEqual(1.5e101.__format__('e'), '1.500000e+101') + self.assertEqual('%e' % 1.5e101, '1.500000e+101') + + self.assertEqual(1.5e-100.__format__('e'), '1.500000e-100') + self.assertEqual('%e' % 1.5e-100, '1.500000e-100') + + self.assertEqual(1.5e-101.__format__('e'), '1.500000e-101') + self.assertEqual('%e' % 1.5e-101, '1.500000e-101') + def test_normal_integers(self): # Ensure the first 256 integers are shared a = 256 @@ -416,16 +439,17 @@ class TypesTests(unittest.TestCase): test(-1.0, ' f', '-1.000000') test( 1.0, '+f', '+1.000000') test(-1.0, '+f', '-1.000000') + test(1.1234e90, 'f', '1.1234e+90') + test(1.1234e90, 'F', '1.1234e+90') test(1.1234e200, 'f', '1.1234e+200') test(1.1234e200, 'F', '1.1234e+200') - # temporarily removed. see issue 1600 - # test( 1.0, 'e', '1.000000e+00') - # test(-1.0, 'e', '-1.000000e+00') - # test( 1.0, 'E', '1.000000E+00') - # test(-1.0, 'E', '-1.000000E+00') - # test(1.1234e20, 'e', '1.123400e+20') - # test(1.1234e20, 'E', '1.123400E+20') + test( 1.0, 'e', '1.000000e+00') + test(-1.0, 'e', '-1.000000e+00') + test( 1.0, 'E', '1.000000E+00') + test(-1.0, 'E', '-1.000000E+00') + test(1.1234e20, 'e', '1.123400e+20') + test(1.1234e20, 'E', '1.123400E+20') # % formatting test(-1.0, '%', '-100.000000%') |