Test constructors via special methods
=====================================

>>> from gmpy2 import mpz, mpq, mpfr, mpc
>>> class A:
...     def __mpz__(self): return mpz(1)
...     def __mpq__(self): return mpq(3,2)
...     def __mpfr__(self): return mpfr(1.5)
...     def __mpc__(self): return mpc(42,67)
>>> class B:
...     def __mpz__(self): return 'hello'
...     def __mpq__(self): return 'hello'
...     def __mpfr__(self): return 'hello'
...     def __mpc__(self): return 'hello'
>>> class C:
...     pass
>>> class D:
...     def __mpz__(self): raise TypeError
...     def __mpq__(self): raise TypeError
...     def __mpfr__(self): raise TypeError
...     def __mpc__(self): raise TypeError

>>> a = A()
>>> b = B()
>>> c = C()
>>> d = D()

Test mpz conversion
-------------------

>>> x = mpz(a)
>>> isinstance(x, mpz)
True
>>> x == 1
True

>>> mpz(b)
Traceback (most recent call last):
...
TypeError: object of type 'str' can not be interpreted as mpz

>>> mpz(c)
Traceback (most recent call last):
...
TypeError: mpz() requires numeric or string argument

Test mpq conversion
-------------------

>>> x = mpq(a)
>>> isinstance(x, mpq)
True
>>> 2*x == 3
True

>>> mpq(b)
Traceback (most recent call last):
...
TypeError: object of type 'str' can not be interpreted as mpq

>>> mpq(c)
Traceback (most recent call last):
...
TypeError: mpq() requires numeric or string argument

Test mpfr conversion
--------------------

>>> x = mpfr(a)
>>> isinstance(x, mpfr)
True
>>> x == 1.5
True

>>> mpfr(b)
Traceback (most recent call last):
...
TypeError: object of type 'str' can not be interpreted as mpc

>>> mpfr(c)
Traceback (most recent call last):
...
TypeError: mpfr() requires numeric or string argument

Test mpc conversion
--------------------

>>> x = mpc(a)
>>> isinstance(x, mpc)
True
>>> x == 42+67j
True

>>> mpc(b)
Traceback (most recent call last):
...
TypeError: object of type 'str' can not be interpreted as mpc

>>> mpc(c)
Traceback (most recent call last):
...
TypeError: mpc() requires numeric or string argument

Test special methods raising errors
--------------------
>>> mpz(d)
Traceback (most recent call last):
...
TypeError
>>> mpq(d)
Traceback (most recent call last):
...
TypeError
>>> mpfr(d)
Traceback (most recent call last):
...
TypeError
>>> mpc(d)
Traceback (most recent call last):
...
TypeError

