/DLR_Main/Languages/IronPython/Tests/test_bool.py

https://bitbucket.org/mdavid/dlr · Python · 76 lines · 48 code · 13 blank · 15 comment · 6 complexity · 4e97d4134e70fa96d7e1b2f1b2c62294 MD5 · raw file

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