Repository navigation
Expand file tree
/
Copy pathtest_bool.py
More file actions
76 lines (63 loc) · 2.96 KB
/
Copy pathtest_bool.py
File metadata and controls
76 lines (63 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#####################################################################################
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#
# This source code is subject to terms and conditions of the Apache License, Version 2.0. A
# copy of the license can be found in the License.html file at the root of this distribution. If
# you cannot locate the Apache License, Version 2.0, please send an email to
# [email protected]. By using this source code in any fashion, you are agreeing to be bound
# by the terms of the Apache License, Version 2.0.
#
# You must not remove this notice, or any other, from this software.
#
#
#####################################################################################
from iptest.assert_util import *
# types are always true.
def test_types():
for x in [str, int, float, bool]:
if not x:
Fail("should be true: %r", x)
def test_bool_dir():
bool_dir = ['__abs__', '__add__', '__and__', '__class__', '__cmp__',
'__coerce__', '__delattr__', '__div__', '__divmod__', '__doc__',
'__float__', '__floordiv__', '__getattribute__', '__getnewargs__',
'__hash__', '__hex__', '__index__', '__init__', '__int__',
'__invert__', '__long__', '__lshift__', '__mod__', '__mul__',
'__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__pos__',
'__pow__', '__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__',
'__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__',
'__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__',
'__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__str__',
'__sub__', '__truediv__', '__xor__']
for t_list in [dir(bool), dir(True), dir(False)]:
for stuff in bool_dir:
Assert(stuff in t_list, "%s should be in dir(bool), but is not" % (stuff))
def test__coerce__():
for simple_type in [int, float, str, bool, object]:
AreEqual(NotImplemented, True.__coerce__(simple_type))
AreEqual(NotImplemented, False.__coerce__(simple_type))
def test__float__():
AreEqual(float(True), 1.0)
AreEqual(float(False), 0.0)
def test__index__():
AreEqual(True.__index__(), 1)
AreEqual(False.__index__(), 0)
def test__int__():
AreEqual(int(True), 1)
AreEqual(int(False), 0)
def test__rdivmod__():
AreEqual(divmod(True, True), (1, 0))
AreEqual(divmod(False, True), (0, 0))
AssertError(ZeroDivisionError, divmod, True, False)
AssertError(ZeroDivisionError, divmod, False, False)
@skip("win32")
def test_decimal():
import System
if not System.Decimal:
Fail("should be true: %r", System.Decimal)
AreEqual(bool(System.Decimal(0)), False)
AreEqual(bool(System.Decimal(1)), True)
AreEqual(System.Decimal(True), System.Decimal(1))
AreEqual(System.Decimal(False), System.Decimal(0))
run_test(__name__)