test_abc.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from numpy.testing import assert_
  2. import numbers
  3. import numpy as np
  4. from numpy.core.numerictypes import sctypes
  5. class TestABC:
  6. def test_abstract(self):
  7. assert_(issubclass(np.number, numbers.Number))
  8. assert_(issubclass(np.inexact, numbers.Complex))
  9. assert_(issubclass(np.complexfloating, numbers.Complex))
  10. assert_(issubclass(np.floating, numbers.Real))
  11. assert_(issubclass(np.integer, numbers.Integral))
  12. assert_(issubclass(np.signedinteger, numbers.Integral))
  13. assert_(issubclass(np.unsignedinteger, numbers.Integral))
  14. def test_floats(self):
  15. for t in sctypes['float']:
  16. assert_(isinstance(t(), numbers.Real),
  17. "{0} is not instance of Real".format(t.__name__))
  18. assert_(issubclass(t, numbers.Real),
  19. "{0} is not subclass of Real".format(t.__name__))
  20. assert_(not isinstance(t(), numbers.Rational),
  21. "{0} is instance of Rational".format(t.__name__))
  22. assert_(not issubclass(t, numbers.Rational),
  23. "{0} is subclass of Rational".format(t.__name__))
  24. def test_complex(self):
  25. for t in sctypes['complex']:
  26. assert_(isinstance(t(), numbers.Complex),
  27. "{0} is not instance of Complex".format(t.__name__))
  28. assert_(issubclass(t, numbers.Complex),
  29. "{0} is not subclass of Complex".format(t.__name__))
  30. assert_(not isinstance(t(), numbers.Real),
  31. "{0} is instance of Real".format(t.__name__))
  32. assert_(not issubclass(t, numbers.Real),
  33. "{0} is subclass of Real".format(t.__name__))
  34. def test_int(self):
  35. for t in sctypes['int']:
  36. assert_(isinstance(t(), numbers.Integral),
  37. "{0} is not instance of Integral".format(t.__name__))
  38. assert_(issubclass(t, numbers.Integral),
  39. "{0} is not subclass of Integral".format(t.__name__))
  40. def test_uint(self):
  41. for t in sctypes['uint']:
  42. assert_(isinstance(t(), numbers.Integral),
  43. "{0} is not instance of Integral".format(t.__name__))
  44. assert_(issubclass(t, numbers.Integral),
  45. "{0} is not subclass of Integral".format(t.__name__))