Back to index

python3.2  3.2.2
Public Member Functions
test.test_types.TypesTests Class Reference

List of all members.

Public Member Functions

def test_truth_values
def test_boolean_ops
def test_comparisons
def test_float_constructor
def test_zero_division
def test_numeric_types
def test_float_to_string
def test_normal_integers
def test_floats
def test_strings
def test_type_function
def test_int__format__
def test_float__format__locale
def test_int__format__locale
def test_float__format__
def test_format_spec_errors
def test_internal_sizes

Detailed Description

Definition at line 8 of file test_types.py.


Member Function Documentation

Definition at line 27 of file test_types.py.

00027 
00028     def test_boolean_ops(self):
00029         if 0 or 0: self.fail('0 or 0 is true instead of false')
00030         if 1 and 1: pass
00031         else: self.fail('1 and 1 is false instead of true')
00032         if not 1: self.fail('not 1 is true instead of false')

Here is the call graph for this function:

Definition at line 33 of file test_types.py.

00033 
00034     def test_comparisons(self):
00035         if 0 < 1 <= 1 == 1 >= 1 > 0 != 1: pass
00036         else: self.fail('int comparisons failed')
00037         if 0.0 < 1.0 <= 1.0 == 1.0 >= 1.0 > 0.0 != 1.0: pass
00038         else: self.fail('float comparisons failed')
00039         if '' < 'a' <= 'a' == 'a' < 'abc' < 'abd' < 'b': pass
00040         else: self.fail('string comparisons failed')
00041         if None is None: pass
00042         else: self.fail('identity test failed')

Here is the call graph for this function:

Definition at line 398 of file test_types.py.

00398 
00399     def test_float__format__(self):
00400         def test(f, format_spec, result):
00401             self.assertEqual(f.__format__(format_spec), result)
00402             self.assertEqual(format(f, format_spec), result)
00403 
00404         test(0.0, 'f', '0.000000')
00405 
00406         # the default is 'g', except for empty format spec
00407         test(0.0, '', '0.0')
00408         test(0.01, '', '0.01')
00409         test(0.01, 'g', '0.01')
00410 
00411         # test for issue 3411
00412         test(1.23, '1', '1.23')
00413         test(-1.23, '1', '-1.23')
00414         test(1.23, '1g', '1.23')
00415         test(-1.23, '1g', '-1.23')
00416 
00417         test( 1.0, ' g', ' 1')
00418         test(-1.0, ' g', '-1')
00419         test( 1.0, '+g', '+1')
00420         test(-1.0, '+g', '-1')
00421         test(1.1234e200, 'g', '1.1234e+200')
00422         test(1.1234e200, 'G', '1.1234E+200')
00423 
00424 
00425         test(1.0, 'f', '1.000000')
00426 
00427         test(-1.0, 'f', '-1.000000')
00428 
00429         test( 1.0, ' f', ' 1.000000')
00430         test(-1.0, ' f', '-1.000000')
00431         test( 1.0, '+f', '+1.000000')
00432         test(-1.0, '+f', '-1.000000')
00433 
00434         # Python versions <= 3.0 switched from 'f' to 'g' formatting for
00435         # values larger than 1e50.  No longer.
00436         f = 1.1234e90
00437         for fmt in 'f', 'F':
00438             # don't do a direct equality check, since on some
00439             # platforms only the first few digits of dtoa
00440             # will be reliable
00441             result = f.__format__(fmt)
00442             self.assertEqual(len(result), 98)
00443             self.assertEqual(result[-7], '.')
00444             self.assertIn(result[:12], ('112340000000', '112339999999'))
00445         f = 1.1234e200
00446         for fmt in 'f', 'F':
00447             result = f.__format__(fmt)
00448             self.assertEqual(len(result), 208)
00449             self.assertEqual(result[-7], '.')
00450             self.assertIn(result[:12], ('112340000000', '112339999999'))
00451 
00452 
00453         test( 1.0, 'e', '1.000000e+00')
00454         test(-1.0, 'e', '-1.000000e+00')
00455         test( 1.0, 'E', '1.000000E+00')
00456         test(-1.0, 'E', '-1.000000E+00')
00457         test(1.1234e20, 'e', '1.123400e+20')
00458         test(1.1234e20, 'E', '1.123400E+20')
00459 
00460         # No format code means use g, but must have a decimal
00461         # and a number after the decimal.  This is tricky, because
00462         # a totaly empty format specifier means something else.
00463         # So, just use a sign flag
00464         test(1e200, '+g', '+1e+200')
00465         test(1e200, '+', '+1e+200')
00466 
00467         test(1.1e200, '+g', '+1.1e+200')
00468         test(1.1e200, '+', '+1.1e+200')
00469 
00470         # 0 padding
00471         test(1234., '010f', '1234.000000')
00472         test(1234., '011f', '1234.000000')
00473         test(1234., '012f', '01234.000000')
00474         test(-1234., '011f', '-1234.000000')
00475         test(-1234., '012f', '-1234.000000')
00476         test(-1234., '013f', '-01234.000000')
00477         test(-1234.12341234, '013f', '-01234.123412')
00478         test(-123456.12341234, '011.2f', '-0123456.12')
00479 
00480         # issue 5782, commas with no specifier type
00481         test(1.2, '010,.2', '0,000,001.2')
00482 
00483         # 0 padding with commas
00484         test(1234., '011,f', '1,234.000000')
00485         test(1234., '012,f', '1,234.000000')
00486         test(1234., '013,f', '01,234.000000')
00487         test(-1234., '012,f', '-1,234.000000')
00488         test(-1234., '013,f', '-1,234.000000')
00489         test(-1234., '014,f', '-01,234.000000')
00490         test(-12345., '015,f', '-012,345.000000')
00491         test(-123456., '016,f', '-0,123,456.000000')
00492         test(-123456., '017,f', '-0,123,456.000000')
00493         test(-123456.12341234, '017,f', '-0,123,456.123412')
00494         test(-123456.12341234, '013,.2f', '-0,123,456.12')
00495 
00496         # % formatting
00497         test(-1.0, '%', '-100.000000%')
00498 
00499         # format spec must be string
00500         self.assertRaises(TypeError, 3.0.__format__, None)
00501         self.assertRaises(TypeError, 3.0.__format__, 0)
00502 
00503         # other format specifiers shouldn't work on floats,
00504         #  in particular int specifiers
00505         for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] +
00506                             [chr(x) for x in range(ord('A'), ord('Z')+1)]):
00507             if not format_spec in 'eEfFgGn%':
00508                 self.assertRaises(ValueError, format, 0.0, format_spec)
00509                 self.assertRaises(ValueError, format, 1.0, format_spec)
00510                 self.assertRaises(ValueError, format, -1.0, format_spec)
00511                 self.assertRaises(ValueError, format, 1e100, format_spec)
00512                 self.assertRaises(ValueError, format, -1e100, format_spec)
00513                 self.assertRaises(ValueError, format, 1e-100, format_spec)
00514                 self.assertRaises(ValueError, format, -1e-100, format_spec)
00515 
00516         # Alternate float formatting
00517         test(1.0, '.0e', '1e+00')
00518         test(1.0, '#.0e', '1.e+00')
00519         test(1.0, '.0f', '1')
00520         test(1.0, '#.0f', '1.')
00521         test(1.1, 'g', '1.1')
00522         test(1.1, '#g', '1.10000')
00523         test(1.0, '.0%', '100%')
00524         test(1.0, '#.0%', '100.%')
00525 
00526         # Issue 7094: Alternate formatting (specified by #)
00527         test(1.0, '0e',  '1.000000e+00')
00528         test(1.0, '#0e', '1.000000e+00')
00529         test(1.0, '0f',  '1.000000' )
00530         test(1.0, '#0f', '1.000000')
00531         test(1.0, '.1e',  '1.0e+00')
00532         test(1.0, '#.1e', '1.0e+00')
00533         test(1.0, '.1f',  '1.0')
00534         test(1.0, '#.1f', '1.0')
00535         test(1.0, '.1%',  '100.0%')
00536         test(1.0, '#.1%', '100.0%')
00537 
00538         # Issue 6902
00539         test(12345.6, "0<20", '12345.60000000000000')
00540         test(12345.6, "1<20", '12345.61111111111111')
00541         test(12345.6, "*<20", '12345.6*************')
00542         test(12345.6, "0>20", '000000000000012345.6')
00543         test(12345.6, "1>20", '111111111111112345.6')
00544         test(12345.6, "*>20", '*************12345.6')
00545         test(12345.6, "0=20", '000000000000012345.6')
00546         test(12345.6, "1=20", '111111111111112345.6')
00547         test(12345.6, "*=20", '*************12345.6')

Here is the call graph for this function:

Definition at line 371 of file test_types.py.

00371 
00372     def test_float__format__locale(self):
00373         # test locale support for __format__ code 'n'
00374 
00375         for i in range(-10, 10):
00376             x = 1234567890.0 * (10.0 ** i)
00377             self.assertEqual(locale.format('%g', x, grouping=True), format(x, 'n'))
00378             self.assertEqual(locale.format('%.10g', x, grouping=True), format(x, '.10n'))

Here is the call graph for this function:

Definition at line 43 of file test_types.py.

00043 
00044     def test_float_constructor(self):
00045         self.assertRaises(ValueError, float, '')
00046         self.assertRaises(ValueError, float, '5\0')

Here is the call graph for this function:

Definition at line 83 of file test_types.py.

00083 
00084     def test_float_to_string(self):
00085         def test(f, result):
00086             self.assertEqual(f.__format__('e'), result)
00087             self.assertEqual('%e' % f, result)
00088 
00089         # test all 2 digit exponents, both with __format__ and with
00090         #  '%' formatting
00091         for i in range(-99, 100):
00092             test(float('1.5e'+str(i)), '1.500000e{0:+03d}'.format(i))
00093 
00094         # test some 3 digit exponents
00095         self.assertEqual(1.5e100.__format__('e'), '1.500000e+100')
00096         self.assertEqual('%e' % 1.5e100, '1.500000e+100')
00097 
00098         self.assertEqual(1.5e101.__format__('e'), '1.500000e+101')
00099         self.assertEqual('%e' % 1.5e101, '1.500000e+101')
00100 
00101         self.assertEqual(1.5e-100.__format__('e'), '1.500000e-100')
00102         self.assertEqual('%e' % 1.5e-100, '1.500000e-100')
00103 
00104         self.assertEqual(1.5e-101.__format__('e'), '1.500000e-101')
00105         self.assertEqual('%e' % 1.5e-101, '1.500000e-101')
00106 
00107         self.assertEqual('%g' % 1.0, '1')
00108         self.assertEqual('%#g' % 1.0, '1.00000')

Here is the call graph for this function:

Definition at line 166 of file test_types.py.

00166 
00167     def test_floats(self):
00168         if 12.0 + 24.0 != 36.0: self.fail('float op')
00169         if 12.0 + (-24.0) != -12.0: self.fail('float op')
00170         if (-12.0) + 24.0 != 12.0: self.fail('float op')
00171         if (-12.0) + (-24.0) != -36.0: self.fail('float op')
00172         if not 12.0 < 24.0: self.fail('float op')
00173         if not -24.0 < -12.0: self.fail('float op')

Here is the call graph for this function:

Definition at line 548 of file test_types.py.

00548 
00549     def test_format_spec_errors(self):
00550         # int, float, and string all share the same format spec
00551         # mini-language parser.
00552 
00553         # Check that we can't ask for too many digits. This is
00554         # probably a CPython specific test. It tries to put the width
00555         # into a C long.
00556         self.assertRaises(ValueError, format, 0, '1'*10000 + 'd')
00557 
00558         # Similar with the precision.
00559         self.assertRaises(ValueError, format, 0, '.' + '1'*10000 + 'd')
00560 
00561         # And may as well test both.
00562         self.assertRaises(ValueError, format, 0, '1'*1000 + '.' + '1'*10000 + 'd')
00563 
00564         # Make sure commas aren't allowed with various type codes
00565         for code in 'xXobns':
00566             self.assertRaises(ValueError, format, 0, ',' + code)

Here is the call graph for this function:

Definition at line 203 of file test_types.py.

00203 
00204     def test_int__format__(self):
00205         def test(i, format_spec, result):
00206             # just make sure we have the unified type for integers
00207             assert type(i) == int
00208             assert type(format_spec) == str
00209             self.assertEqual(i.__format__(format_spec), result)
00210 
00211         test(123456789, 'd', '123456789')
00212         test(123456789, 'd', '123456789')
00213 
00214         test(1, 'c', '\01')
00215 
00216         # sign and aligning are interdependent
00217         test(1, "-", '1')
00218         test(-1, "-", '-1')
00219         test(1, "-3", '  1')
00220         test(-1, "-3", ' -1')
00221         test(1, "+3", ' +1')
00222         test(-1, "+3", ' -1')
00223         test(1, " 3", '  1')
00224         test(-1, " 3", ' -1')
00225         test(1, " ", ' 1')
00226         test(-1, " ", '-1')
00227 
00228         # hex
00229         test(3, "x", "3")
00230         test(3, "X", "3")
00231         test(1234, "x", "4d2")
00232         test(-1234, "x", "-4d2")
00233         test(1234, "8x", "     4d2")
00234         test(-1234, "8x", "    -4d2")
00235         test(1234, "x", "4d2")
00236         test(-1234, "x", "-4d2")
00237         test(-3, "x", "-3")
00238         test(-3, "X", "-3")
00239         test(int('be', 16), "x", "be")
00240         test(int('be', 16), "X", "BE")
00241         test(-int('be', 16), "x", "-be")
00242         test(-int('be', 16), "X", "-BE")
00243 
00244         # octal
00245         test(3, "o", "3")
00246         test(-3, "o", "-3")
00247         test(65, "o", "101")
00248         test(-65, "o", "-101")
00249         test(1234, "o", "2322")
00250         test(-1234, "o", "-2322")
00251         test(1234, "-o", "2322")
00252         test(-1234, "-o", "-2322")
00253         test(1234, " o", " 2322")
00254         test(-1234, " o", "-2322")
00255         test(1234, "+o", "+2322")
00256         test(-1234, "+o", "-2322")
00257 
00258         # binary
00259         test(3, "b", "11")
00260         test(-3, "b", "-11")
00261         test(1234, "b", "10011010010")
00262         test(-1234, "b", "-10011010010")
00263         test(1234, "-b", "10011010010")
00264         test(-1234, "-b", "-10011010010")
00265         test(1234, " b", " 10011010010")
00266         test(-1234, " b", "-10011010010")
00267         test(1234, "+b", "+10011010010")
00268         test(-1234, "+b", "-10011010010")
00269 
00270         # alternate (#) formatting
00271         test(0, "#b", '0b0')
00272         test(0, "-#b", '0b0')
00273         test(1, "-#b", '0b1')
00274         test(-1, "-#b", '-0b1')
00275         test(-1, "-#5b", ' -0b1')
00276         test(1, "+#5b", ' +0b1')
00277         test(100, "+#b", '+0b1100100')
00278         test(100, "#012b", '0b0001100100')
00279         test(-100, "#012b", '-0b001100100')
00280 
00281         test(0, "#o", '0o0')
00282         test(0, "-#o", '0o0')
00283         test(1, "-#o", '0o1')
00284         test(-1, "-#o", '-0o1')
00285         test(-1, "-#5o", ' -0o1')
00286         test(1, "+#5o", ' +0o1')
00287         test(100, "+#o", '+0o144')
00288         test(100, "#012o", '0o0000000144')
00289         test(-100, "#012o", '-0o000000144')
00290 
00291         test(0, "#x", '0x0')
00292         test(0, "-#x", '0x0')
00293         test(1, "-#x", '0x1')
00294         test(-1, "-#x", '-0x1')
00295         test(-1, "-#5x", ' -0x1')
00296         test(1, "+#5x", ' +0x1')
00297         test(100, "+#x", '+0x64')
00298         test(100, "#012x", '0x0000000064')
00299         test(-100, "#012x", '-0x000000064')
00300         test(123456, "#012x", '0x000001e240')
00301         test(-123456, "#012x", '-0x00001e240')
00302 
00303         test(0, "#X", '0X0')
00304         test(0, "-#X", '0X0')
00305         test(1, "-#X", '0X1')
00306         test(-1, "-#X", '-0X1')
00307         test(-1, "-#5X", ' -0X1')
00308         test(1, "+#5X", ' +0X1')
00309         test(100, "+#X", '+0X64')
00310         test(100, "#012X", '0X0000000064')
00311         test(-100, "#012X", '-0X000000064')
00312         test(123456, "#012X", '0X000001E240')
00313         test(-123456, "#012X", '-0X00001E240')
00314 
00315         test(123, ',', '123')
00316         test(-123, ',', '-123')
00317         test(1234, ',', '1,234')
00318         test(-1234, ',', '-1,234')
00319         test(123456, ',', '123,456')
00320         test(-123456, ',', '-123,456')
00321         test(1234567, ',', '1,234,567')
00322         test(-1234567, ',', '-1,234,567')
00323 
00324         # issue 5782, commas with no specifier type
00325         test(1234, '010,', '00,001,234')
00326 
00327         # Unified type for integers
00328         test(10**100, 'd', '1' + '0' * 100)
00329         test(10**100+100, 'd', '1' + '0' * 97 + '100')
00330 
00331         # make sure these are errors
00332 
00333         # precision disallowed
00334         self.assertRaises(ValueError, 3 .__format__, "1.3")
00335         # sign not allowed with 'c'
00336         self.assertRaises(ValueError, 3 .__format__, "+c")
00337         # format spec must be string
00338         self.assertRaises(TypeError, 3 .__format__, None)
00339         self.assertRaises(TypeError, 3 .__format__, 0)
00340         # can't have ',' with 'n'
00341         self.assertRaises(ValueError, 3 .__format__, ",n")
00342         # can't have ',' with 'c'
00343         self.assertRaises(ValueError, 3 .__format__, ",c")
00344 
00345         # ensure that only int and float type specifiers work
00346         for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] +
00347                             [chr(x) for x in range(ord('A'), ord('Z')+1)]):
00348             if not format_spec in 'bcdoxXeEfFgGn%':
00349                 self.assertRaises(ValueError, 0 .__format__, format_spec)
00350                 self.assertRaises(ValueError, 1 .__format__, format_spec)
00351                 self.assertRaises(ValueError, (-1) .__format__, format_spec)
00352 
00353         # ensure that float type specifiers work; format converts
00354         #  the int to a float
00355         for format_spec in 'eEfFgG%':
00356             for value in [0, 1, -1, 100, -100, 1234567890, -1234567890]:
00357                 self.assertEqual(value.__format__(format_spec),
00358                                  float(value).__format__(format_spec))
00359 
00360         # Issue 6902
00361         test(123456, "0<20", '12345600000000000000')
00362         test(123456, "1<20", '12345611111111111111')
00363         test(123456, "*<20", '123456**************')
00364         test(123456, "0>20", '00000000000000123456')
00365         test(123456, "1>20", '11111111111111123456')
00366         test(123456, "*>20", '**************123456')
00367         test(123456, "0=20", '00000000000000123456')
00368         test(123456, "1=20", '11111111111111123456')
00369         test(123456, "*=20", '**************123456')

Here is the call graph for this function:

Definition at line 380 of file test_types.py.

00380 
00381     def test_int__format__locale(self):
00382         # test locale support for __format__ code 'n' for integers
00383 
00384         x = 123456789012345678901234567890
00385         for i in range(0, 30):
00386             self.assertEqual(locale.format('%d', x, grouping=True), format(x, 'n'))
00387 
00388             # move to the next integer to test
00389             x = x // 10
00390 
00391         rfmt = ">20n"
00392         lfmt = "<20n"
00393         cfmt = "^20n"
00394         for x in (1234, 12345, 123456, 1234567, 12345678, 123456789, 1234567890, 12345678900):
00395             self.assertEqual(len(format(0, rfmt)), len(format(x, rfmt)))
00396             self.assertEqual(len(format(0, lfmt)), len(format(x, lfmt)))
00397             self.assertEqual(len(format(0, cfmt)), len(format(x, cfmt)))

Here is the call graph for this function:

Definition at line 567 of file test_types.py.

00567 
00568     def test_internal_sizes(self):
00569         self.assertGreater(object.__basicsize__, 0)
00570         self.assertGreater(tuple.__itemsize__, 0)
00571 

Here is the call graph for this function:

Definition at line 109 of file test_types.py.

00109 
00110     def test_normal_integers(self):
00111         # Ensure the first 256 integers are shared
00112         a = 256
00113         b = 128*2
00114         if a is not b: self.fail('256 is not shared')
00115         if 12 + 24 != 36: self.fail('int op')
00116         if 12 + (-24) != -12: self.fail('int op')
00117         if (-12) + 24 != 12: self.fail('int op')
00118         if (-12) + (-24) != -36: self.fail('int op')
00119         if not 12 < 24: self.fail('int op')
00120         if not -24 < -12: self.fail('int op')
00121         # Test for a particular bug in integer multiply
00122         xsize, ysize, zsize = 238, 356, 4
00123         if not (xsize*ysize*zsize == zsize*xsize*ysize == 338912):
00124             self.fail('int mul commutativity')
00125         # And another.
00126         m = -sys.maxsize - 1
00127         for divisor in 1, 2, 4, 8, 16, 32:
00128             j = m // divisor
00129             prod = divisor * j
00130             if prod != m:
00131                 self.fail("%r * %r == %r != %r" % (divisor, j, prod, m))
00132             if type(prod) is not int:
00133                 self.fail("expected type(prod) to be int, not %r" %
00134                                    type(prod))
00135         # Check for unified integral type
00136         for divisor in 1, 2, 4, 8, 16, 32:
00137             j = m // divisor - 1
00138             prod = divisor * j
00139             if type(prod) is not int:
00140                 self.fail("expected type(%r) to be int, not %r" %
00141                                    (prod, type(prod)))
00142         # Check for unified integral type
00143         m = sys.maxsize
00144         for divisor in 1, 2, 4, 8, 16, 32:
00145             j = m // divisor + 1
00146             prod = divisor * j
00147             if type(prod) is not int:
00148                 self.fail("expected type(%r) to be int, not %r" %
00149                                    (prod, type(prod)))
00150 
00151         x = sys.maxsize
00152         self.assertIsInstance(x + 1, int,
00153                               "(sys.maxsize + 1) should have returned int")
00154         self.assertIsInstance(-x - 1, int,
00155                               "(-sys.maxsize - 1) should have returned int")
00156         self.assertIsInstance(-x - 2, int,
00157                               "(-sys.maxsize - 2) should have returned int")
00158 
00159         try: 5 << -5
00160         except ValueError: pass
00161         else: self.fail('int negative shift <<')
00162 
00163         try: 5 >> -5
00164         except ValueError: pass
00165         else: self.fail('int negative shift >>')

Here is the call graph for this function:

Definition at line 72 of file test_types.py.

00072 
00073     def test_numeric_types(self):
00074         if 0 != 0.0 or 1 != 1.0 or -1 != -1.0:
00075             self.fail('int/float value not equal')
00076         # calling built-in types without argument must return 0
00077         if int() != 0: self.fail('int() does not return 0')
00078         if float() != 0.0: self.fail('float() does not return 0.0')
00079         if int(1.9) == 1 == int(1.1) and int(-1.1) == -1 == int(-1.9): pass
00080         else: self.fail('int() does not round properly')
00081         if float(1) == 1.0 and float(-1) == -1.0 and float(0) == 0.0: pass
00082         else: self.fail('float() does not work properly')

Here is the call graph for this function:

Definition at line 174 of file test_types.py.

00174 
00175     def test_strings(self):
00176         if len('') != 0: self.fail('len(\'\')')
00177         if len('a') != 1: self.fail('len(\'a\')')
00178         if len('abcdef') != 6: self.fail('len(\'abcdef\')')
00179         if 'xyz' + 'abcde' != 'xyzabcde': self.fail('string concatenation')
00180         if 'xyz'*3 != 'xyzxyzxyz': self.fail('string repetition *3')
00181         if 0*'abcde' != '': self.fail('string repetition 0*')
00182         if min('abc') != 'a' or max('abc') != 'c': self.fail('min/max string')
00183         if 'a' in 'abc' and 'b' in 'abc' and 'c' in 'abc' and 'd' not in 'abc': pass
00184         else: self.fail('in/not in string')
00185         x = 'x'*103
00186         if '%s!'%x != x+'!': self.fail('nasty string formatting bug')
00187 
00188         #extended slices for strings
00189         a = '0123456789'
00190         self.assertEqual(a[::], a)
00191         self.assertEqual(a[::2], '02468')
00192         self.assertEqual(a[1::2], '13579')
00193         self.assertEqual(a[::-1],'9876543210')
00194         self.assertEqual(a[::-2], '97531')
00195         self.assertEqual(a[3::-2], '31')
00196         self.assertEqual(a[-100:100:], a)
00197         self.assertEqual(a[100:-100:-1], a[::-1])
00198         self.assertEqual(a[-100:100:2], '02468')

Here is the call graph for this function:

Definition at line 10 of file test_types.py.

00010 
00011     def test_truth_values(self):
00012         if None: self.fail('None is true instead of false')
00013         if 0: self.fail('0 is true instead of false')
00014         if 0.0: self.fail('0.0 is true instead of false')
00015         if '': self.fail('\'\' is true instead of false')
00016         if not 1: self.fail('1 is false instead of true')
00017         if not 1.0: self.fail('1.0 is false instead of true')
00018         if not 'x': self.fail('\'x\' is false instead of true')
00019         if not {'x': 1}: self.fail('{\'x\': 1} is false instead of true')
00020         def f(): pass
00021         class C: pass
00022         x = C()
00023         if not f: self.fail('f is false instead of true')
00024         if not C: self.fail('C is false instead of true')
00025         if not sys: self.fail('sys is false instead of true')
00026         if not x: self.fail('x is false instead of true')

Here is the call graph for this function:

Definition at line 199 of file test_types.py.

00199 
00200     def test_type_function(self):
00201         self.assertRaises(TypeError, type, 1, 2)
00202         self.assertRaises(TypeError, type, 1, 2, 3, 4)

Here is the call graph for this function:

Definition at line 47 of file test_types.py.

00047 
00048     def test_zero_division(self):
00049         try: 5.0 / 0.0
00050         except ZeroDivisionError: pass
00051         else: self.fail("5.0 / 0.0 didn't raise ZeroDivisionError")
00052 
00053         try: 5.0 // 0.0
00054         except ZeroDivisionError: pass
00055         else: self.fail("5.0 // 0.0 didn't raise ZeroDivisionError")
00056 
00057         try: 5.0 % 0.0
00058         except ZeroDivisionError: pass
00059         else: self.fail("5.0 % 0.0 didn't raise ZeroDivisionError")
00060 
00061         try: 5 / 0
00062         except ZeroDivisionError: pass
00063         else: self.fail("5 / 0 didn't raise ZeroDivisionError")
00064 
00065         try: 5 // 0
00066         except ZeroDivisionError: pass
00067         else: self.fail("5 // 0 didn't raise ZeroDivisionError")
00068 
00069         try: 5 % 0
00070         except ZeroDivisionError: pass
00071         else: self.fail("5 % 0 didn't raise ZeroDivisionError")

Here is the call graph for this function:


The documentation for this class was generated from the following file: