Пример #1
0
assert 'abc'.isascii()
assert not 'abç'.isascii()

# issue 1077
assert str.maketrans({'a': 'A'}) == {97: 'A'}
assert 'xyz'.maketrans({'a': 'A'}) == {97: 'A'}

# issue 1078
assert 'xyz'.maketrans('abc', 'def', 'abd') == {97: None, 98: None, 99: 102,
                                                100: None}

# issue 1103
assert str() == ""

# issue 1231
assertRaises(TypeError, sum, ['a', 'b'], '')

# issue 1256
assert "\U00000065" == "e"

# issue 1292
s = 'abcd'
assert s[-100:] == 'abcd'
assert s[:100] == 'abcd'
assert s[-100:100] == 'abcd'

# issue 1306
strs = ['', ' ', '\n', '\n\n', 'a\nb', 'one\ntwo\nthree',
        'one\ntwo\nthree\n', 'one\ntwo\nthree\n\n']
good = [
[], [],
Пример #2
0
t = 1, 2
try:
    t[0] = 1
    raise Exception('should have raised AttributeError')
except AttributeError:
    pass

# issue 298
n = 1
for n in range(n):
    pass
assert n == 0

#issue 301
t = 1, 2
assertRaises(AttributeError, getattr, t, "__setitem__")

# issue 303
assert "{0:.{1}f}".format(1.123, 1) == "1.1"

# issue 305
a = [1, 2, 3]
assert a.sort() is None

# issue 307
x = 1
assertRaises(AttributeError, setattr, x, '__add__', 1)
assertRaises(AttributeError, setattr, x, 'y', 1)

# issue 310
assert 4 in range(5)
Пример #3
0
y = 8
assert f"{y=}" == "y=8"

# issue 1267
a = 5
assert f'{"is" if a == 1 else "are"}' == "are"
a = 1
assert f'{"is" if a == 1 else "are"}' == "is"

# issue 1427
from math import cos, radians
theta = 30
assert f'{theta=}  {cos(radians(theta))=:.3f}' == \
  "theta=30  cos(radians(theta))=0.866"

# issue 1554
assertRaises(SyntaxError, exec, 'f"Bad format {}"')

# issue 1734
assert f'[{"Text":10}]' == '[Text      ]'
assert f'[{"Text:":10}]' == '[Text:     ]'

x = 45
assert f'{x}' 'b' == '45b'

# issue 1863
a = 2
s = f'foo { a }'
assert s == 'foo 2'

print("passed all tests")
Пример #4
0
b.pop()
assert b == bytearray([0, 2])
b.append(5)
assert b == bytearray([0, 2, 5])
b.insert(1, 4)
assert b == bytearray([0, 4, 2, 5])

assert b'-'.join([b'a', b'b']) == b'a-b'

# encoding and decoding
for word in ['donnée', 'ήλιος', 'машина', '太陽']:
    b = word.encode('utf-8')
    assert b.decode('utf-8') == word

# issue 791
assert int.from_bytes(map(ord, 'abcd'), 'big') == 1633837924

t = [66, 'a']
assertRaises(TypeError, bytes, t, "big")

# mentioned in issue 623
assert b''.join([memoryview(b'foo'), b'bar']) == b'foobar'
assert b''.join([b'bar', memoryview(b'foo')]) == b'barfoo'
assert b''.join([bytearray(b'foo'), b'bar']) == b'foobar'
assert b''.join([b'bar', bytearray(b'foo')]) == b'barfoo'

charmap = bytearray(256)
assert charmap.find(1, 0) == -1
assert charmap.find(0, 0) == 0

print('passed all tests...')
Пример #5
0
t = 1, 2
try:
    t[0] = 1
except TypeError:
    pass

# issue 298
n = 1
for n in range(n):
    pass
assert n == 0

#issue 301
t = 1, 2
assertRaises(TypeError, t.__setitem__, 0, 1)

try:
    t[0] = 1
except TypeError:
    pass
else:
    raise Exception('should have raised TypeError')

# issue 303
assert "{0:.{1}f}".format(1.123, 1) == "1.1"

# issue 305
a = [1, 2, 3]
assert a.sort() is None
Пример #6
0
assert b == bytearray([0,2,5])
b.insert(1,4)
assert b == bytearray([0,4,2,5])

assert b'-'.join([b'a', b'b']) == b'a-b'

# encoding and decoding
for word in ['donnée','ήλιος','машина','太陽']:
    b = word.encode('utf-8')
    assert b.decode('utf-8') == word

# issue 791
assert int.from_bytes(map(ord, 'abcd'), 'big') == 1633837924

t = [66, 'a']
assertRaises(TypeError, bytes, t, "big")

# mentioned in issue 623
assert b''.join([memoryview(b'foo'), b'bar']) == b'foobar'
assert b''.join([b'bar', memoryview(b'foo')]) == b'barfoo'
assert b''.join([bytearray(b'foo'), b'bar']) == b'foobar'
assert b''.join([b'bar', bytearray(b'foo')]) == b'barfoo'

charmap = bytearray(256)
assert charmap.find(1, 0) == -1
assert charmap.find(0, 0) == 0

assert charmap.rfind(1, 0) == -1
assert charmap.rfind(0, 0) == 255

assertRaises(ValueError, charmap.index, 1)
Пример #7
0
assert type((1,)*2) == tuple

t = 1,2
try:
    t[0]=1
except TypeError:
    pass

# issue 298
n = 1
for n in range(n): pass
assert n == 0

#issue 301 
t = 1,2
assertRaises(TypeError, t.__setitem__, 0, 1)

try:
    t[0]=1
except TypeError:
    pass
else:
    raise Exception('should have raised TypeError')

# issue 303
assert "{0:.{1}f}".format(1.123,1) == "1.1"

# issue 305
a = [1, 2, 3]
assert a.sort() is None
Пример #8
0
t = 1, 2
try:
    t[0] = 1
    raise Exception('should have raised AttributeError')
except AttributeError:
    pass

# issue 298
n = 1
for n in range(n):
    pass
assert n == 0

#issue 301
t = 1, 2
assertRaises(AttributeError, getattr, t, "__setitem__")

# issue 303
assert "{0:.{1}f}".format(1.123, 1) == "1.1"

# issue 305
a = [1, 2, 3]
assert a.sort() is None

# issue 307
x = 1
assertRaises(AttributeError, setattr, x, '__add__', 1)
assertRaises(AttributeError, setattr, x, 'y', 1)

# issue 310
assert 4 in range(5)
Пример #9
0
        except Exception as exc:
            assert exc.args[0] == msg.format(op, type(value).__name__), \
                (op, exc.args[0], msg.format(op, type(value).__name__))

    if value is not None:
        assert value != None
        assert not (value == None)


# PEP 570 (positional-only parameters)
def pos_only_arg(arg, /):
    return arg


pos_only_arg(1)
assertRaises(TypeError, pos_only_arg, arg=2)


def kwd_only_arg(*, arg):
    return arg


assert kwd_only_arg(arg=2) == 2
assertRaises(TypeError, kwd_only_arg, 1)


def combined_example(pos_only, /, standard, *, kwd_only):
    return pos_only, standard, kwd_only


assert combined_example(1, 2, kwd_only=3) == (1, 2, 3)
Пример #10
0
t = 1, 2
try:
    t[0] = 1
    raise Exception('should have raised AttributeError')
except AttributeError:
    pass

# issue 298
n = 1
for n in range(n):
    pass
assert n == 0

# issue 301
t = 1, 2
assertRaises(AttributeError, getattr, t, "__setitem__")

# issue 307
x = 1
assertRaises(AttributeError, setattr, x, '__add__', 1)
assertRaises(AttributeError, setattr, x, 'y', 1)

# issue 310
assert 4 in range(5)
assert 4 in range(0, 5, 2)
assert not 1 in range(0, 5, 2)

assert 1 in range(10, 0, -1)
assert 10 in range(10, 0, -1)
assert not 1 in range(10, 0, -2)
assert not 0 in range(10, 0, -2)
Пример #11
0
        except Exception as exc:
            assert exc.args[0] == msg.format(op, type(value).__name__), \
                (op, exc.args[0], msg.format(op, type(value).__name__))

    if value is not None:
        assert value != None
        assert not (value == None)


# PEP 570 (positional-only parameters)
def pos_only_arg(arg, /):
    return arg


pos_only_arg(1)
assertRaises(TypeError, pos_only_arg, arg=2)


def kwd_only_arg(*, arg):
    return arg


assert kwd_only_arg(arg=2) == 2
assertRaises(TypeError, kwd_only_arg, 1)


def combined_example(pos_only, /, standard, *, kwd_only):
    return pos_only, standard, kwd_only


assert combined_example(1, 2, kwd_only=3) == (1, 2, 3)
Пример #12
0
t = 1, 2
try:
    t[0] = 1
    raise Exception('should have raised AttributeError')
except AttributeError:
    pass

# issue 298
n = 1
for n in range(n):
    pass
assert n == 0

# issue 301
t = 1, 2
assertRaises(AttributeError, getattr, t, "__setitem__")

# issue 307
x = 1
assertRaises(AttributeError, setattr, x, '__add__', 1)
assertRaises(AttributeError, setattr, x, 'y', 1)

# issue 310
assert 4 in range(5)
assert 4 in range(0, 5, 2)
assert not 1 in range(0, 5, 2)

assert 1 in range(10, 0, -1)
assert 10 in range(10, 0, -1)
assert not 1 in range(10, 0, -2)
assert not 0 in range(10, 0, -2)
Пример #13
0
t = 1, 2
try:
    t[0] = 1
    raise Exception('should have raised AttributeError')
except AttributeError:
    pass

# issue 298
n = 1
for n in range(n): pass
assert n == 0

#issue 301
t = 1,2
assertRaises(AttributeError, getattr, t, "__setitem__")

# issue 303
assert "{0:.{1}f}".format(1.123,1) == "1.1"

# issue 305
a = [1, 2, 3]
assert a.sort() is None

# issue 307
x = 1
assertRaises(AttributeError, setattr, x, '__add__', 1)
assertRaises(AttributeError, setattr, x, 'y', 1)

# issue 310
assert 4 in range(5)
Пример #14
0
t = 1, 2
try:
    t[0] = 1
    raise Exception('should have raised AttributeError')
except AttributeError:
    pass

# issue 298
n = 1
for n in range(n):
    pass
assert n == 0

#issue 301
t = 1, 2
assertRaises(AttributeError, getattr, t, "__setitem__")

# issue 303
assert "{0:.{1}f}".format(1.123, 1) == "1.1"

# issue 305
a = [1, 2, 3]
assert a.sort() is None

# issue 307
x = 1
assertRaises(AttributeError, setattr, x, '__add__', 1)
assertRaises(AttributeError, setattr, x, 'y', 1)

# issue 310
assert 4 in range(5)
Пример #15
0
# issue 840
x = 123 ** 20
y = 123 ** 20
assert (id(x) != id(y) or x is y)

# PEP 515
from tester import assertRaises

population = 65_345_123
assert population == 65345123

population = int("65_345_123")
assert population == 65345123

assertRaises(ValueError, int, "_12000")

amount = 10_000_000.0
assert amount == 10000000.0

addr = 0xCAFE_F00D
assert addr == 0xCAFEF00D

flags = 0b_0011_1111_0100_1110
assert flags == 0b0011111101001110

flags = int('0b_1111_0000', 2)
assert flags == 0b11110000

assert complex("8_7.6+2_67J") == (87.6 + 267j)
assertRaises(ValueError, complex, "_8_7.6+2_67J")
Пример #16
0
# issue 840
x = 123 ** 20
y = 123 ** 20
assert (id(x) != id(y) or x is y)

# PEP 515
from tester import assertRaises

population = 65_345_123
assert population == 65345123

population = int("65_345_123")
assert population == 65345123

assertRaises(ValueError, int, "_12000")

amount = 10_000_000.0
assert amount == 10000000.0

addr = 0xCAFE_F00D
assert addr == 0xCAFEF00D

flags = 0b_0011_1111_0100_1110
assert flags == 0b0011111101001110

flags = int('0b_1111_0000', 2)
assert flags == 0b11110000

assert complex("8_7.6+2_67J") == (87.6+267j)
assertRaises(ValueError, complex, "_8_7.6+2_67J")
Пример #17
0
# issue 1110
assert math.log10(1000) == 3.0

# issue 1111
log1p = math.log1p(1e-5)
assert (log1p == 0.00000999995000033333 or  # CPython, Edge
        log1p == 0.000009999950000333332)  # Firefox, Chrome

# issue 1112
assert math.gamma(2) == 1.0

# issue 1113
assert math.lgamma(2) == 0.0

# issue 1246
assertRaises(TypeError, math.cos)

# issue 1308
assert math.factorial(
    69
) == 171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000

# issue 1312
assert math.comb(5, 2) == 10
assert math.comb(69, 12) == 8815083648488

assert math.perm(69, 12) == 4222439171759589580800

x = math.prod(range(1, 33))
assert x == 263130836933693530167218012160000000
Пример #18
0
# issue 840
x = 123 ** 20
y = 123 ** 20
assert (id(x) != id(y) or x is y)

# PEP 515
from tester import assertRaises

population = 65_345_123
assert population == 65345123

population = int("65_345_123")
assert population == 65345123

assertRaises(ValueError, int, "_12000")

amount = 10_000_000.0
assert amount == 10000000.0

addr = 0xCAFE_F00D
assert addr == 0xCAFEF00D

flags = 0b_0011_1111_0100_1110
assert flags == 0b0011111101001110

flags = int('0b_1111_0000', 2)
assert flags == 0b11110000

assert complex("8_7.6+2_67J") == (87.6 + 267j)
assertRaises(ValueError, complex, "_8_7.6+2_67J")
Пример #19
0
assert type((1,)*2) == tuple

t = 1,2
try:
    t[0]=1
except TypeError:
    pass

# issue 298
n = 1
for n in range(n): pass
assert n == 0

#issue 301 
t = 1,2
assertRaises(TypeError, t.__setitem__, 0, 1)

try:
    t[0]=1
except TypeError:
    pass
else:
    raise Exception('should have raised TypeError')

# issue 305
a = [1, 2, 3]
assert a.sort() is None

# issue 307
x = 1
assertRaises(AttributeError, setattr, x, '__add__', 1)
Пример #20
0
t = 1, 2
try:
    t[0] = 1
except TypeError:
    pass

# issue 298
n = 1
for n in range(n):
    pass
assert n == 0

#issue 301
t = 1, 2
assertRaises(TypeError, t.__setitem__, 0, 1)

try:
    t[0] = 1
except TypeError:
    pass
else:
    raise Exception('should have raised TypeError')

# issue 305
a = [1, 2, 3]
assert a.sort() is None

# issue 307
x = 1
assertRaises(AttributeError, setattr, x, '__add__', 1)
Пример #21
0
t = 1, 2
try:
    t[0] = 1
except TypeError:
    pass

# issue 298
n = 1
for n in range(n):
    pass
assert n == 0

# issue 301
t = 1, 2
assertRaises(TypeError, t.__setitem__, 0, 1)

try:
    t[0] = 1
except TypeError:
    pass
else:
    raise Exception("should have raised TypeError")

# issue 305
a = [1, 2, 3]
assert a.sort() is None

# issue 307
x = 1
assertRaises(AttributeError, setattr, x, "__add__", 1)
Пример #22
0
assert b == bytearray([0, 2, 5])
b.insert(1, 4)
assert b == bytearray([0, 4, 2, 5])

assert b'-'.join([b'a', b'b']) == b'a-b'

# encoding and decoding
for word in ['donnée', 'ήλιος', 'машина', '太陽']:
    b = word.encode('utf-8')
    assert b.decode('utf-8') == word

# issue 791
assert int.from_bytes(map(ord, 'abcd'), 'big') == 1633837924

t = [66, 'a']
assertRaises(TypeError, bytes, t, "big")

# mentioned in issue 623
assert b''.join([memoryview(b'foo'), b'bar']) == b'foobar'
assert b''.join([b'bar', memoryview(b'foo')]) == b'barfoo'
assert b''.join([bytearray(b'foo'), b'bar']) == b'foobar'
assert b''.join([b'bar', bytearray(b'foo')]) == b'barfoo'

charmap = bytearray(256)
assert charmap.find(1, 0) == -1
assert charmap.find(0, 0) == 0

assert charmap.rfind(1, 0) == -1
assert charmap.rfind(0, 0) == 255

assertRaises(ValueError, charmap.index, 1)