def _test(chat=None): if chat: print "Unit tests for gmpy2 (mpq functionality)" print " on Python %s" % sys.version print "Testing gmpy2 {0}".format(_g.version()) print " Mutliple-precision library: {0}".format(_g.mp_version()) print " Floating-point library: {0}".format(_g.mpfr_version()) print " Complex library: {0}".format(_g.mpc_version()) print " Caching Values: (Number) {0}".format(_g.get_cache()[0]) print " Caching Values: (Size, limbs) {0}".format(_g.get_cache()[1]) thismod = sys.modules.get(__name__) doctest.testmod(thismod, report=0) if chat: print "Repeating tests, with caching disabled" _g.set_cache(0, 128) sav = sys.stdout class _Dummy: def write(self, *whatever): pass try: sys.stdout = _Dummy() doctest.testmod(thismod, report=0) finally: sys.stdout = sav if chat: print print "Overall results for mpq:" return doctest.master.summarize(chat)
def _test(chat=None): python_version = sys.version_info[:3] if chat: print "Unit tests for gmpy2 (decimal interoperation)" print " on Python %s" % sys.version print "Testing gmpy2 {0}".format(_g.version()) print " Mutliple-precision library: {0}".format(_g.mp_version()) print " Floating-point library: {0}".format(_g.mpfr_version()) print " Complex library: {0}".format(_g.mpc_version()) print " Caching Values: (Number) {0}".format(_g.get_cache()[0]) print " Caching Values: (Size, limbs) {0}".format(_g.get_cache()[1]) if not _d: if chat: print "Can't test, since can't import decimal" return 0, 0 thismod = sys.modules.get(__name__) doctest.testmod(thismod, report=0, optionflags=doctest.IGNORE_EXCEPTION_DETAIL) if chat: print print "Overall results for dec:" return doctest.master.summarize(chat)
def _test(chat=None): if chat: print "Unit tests for gmpy2 (mpfr functionality)" print " on Python %s" % sys.version print "Testing gmpy2 {0}".format(_g.version()) print " Mutliple-precision library: {0}".format(_g.mp_version()) print " Floating-point library: {0}".format(_g.mpfr_version()) print " Complex library: {0}".format(_g.mpc_version()) print " Caching Values: (Number) {0}".format(_g.get_cache()[0]) print " Caching Values: (Size, limbs) {0}".format(_g.get_cache()[1]) thismod = sys.modules.get(__name__) doctest.testmod(thismod, report=0) if chat: print "Repeating tests, with caching disabled" _g.set_cache(0,128) sav = sys.stdout class _Dummy: def write(self,*whatever): pass try: sys.stdout = _Dummy() doctest.testmod(thismod, report=0, optionflags=doctest.IGNORE_EXCEPTION_DETAIL) finally: sys.stdout = sav if chat: print print "Overall results for mpfr:" return doctest.master.summarize(chat)
def _test(chat=None): if chat: print("Unit tests for gmpy2 (mpq functionality)") print(" on Python %s" % sys.version) print("Testing gmpy2 {0}".format(_g.version())) print(" Mutliple-precision library: {0}".format(_g.mp_version())) print(" Floating-point library: {0}".format(_g.mpfr_version())) print(" Complex library: {0}".format(_g.mpc_version())) print(" Caching Values: (Number) {0}".format(_g.get_cache()[0])) print(" Caching Values: (Size, limbs) {0}".format(_g.get_cache()[1])) thismod = sys.modules.get(__name__) doctest.testmod(thismod, report=0) if chat: print("Repeating tests, with caching disabled") _g.set_cache(0,128) sav = sys.stdout class _Dummy: encoding = None def write(self,*whatever): pass try: sys.stdout = _Dummy() doctest.testmod(thismod, report=0) finally: sys.stdout = sav if chat: print() print("Overall results for mpq:") return doctest.master.summarize(chat)
def _test(chat=None): if chat: print("Unit tests for gmpy2 (mpfr functionality)") print(" on Python %s" % sys.version) print("Testing gmpy2 {0}".format(_g.version())) print(" Mutliple-precision library: {0}".format(_g.mp_version())) print(" Floating-point library: {0}".format(_g.mpfr_version())) print(" Complex library: {0}".format(_g.mpc_version())) print(" Caching Values: (Number) {0}".format(_g.get_cache()[0])) print(" Caching Values: (Size, limbs) {0}".format(_g.get_cache()[1])) thismod = sys.modules.get(__name__) doctest.testmod(thismod, report=0) if chat: print("Repeating tests, with caching disabled") _g.set_cache(0,128) sav = sys.stdout class _Dummy: encoding = None def write(self,*whatever): pass try: sys.stdout = _Dummy() doctest.testmod(thismod, report=0, optionflags=doctest.IGNORE_EXCEPTION_DETAIL) finally: sys.stdout = sav if chat: print() print("Overall results for mpfr:") return doctest.master.summarize(chat)
def test_gmpy2_version(): expected_gmpy2_version = '2.0.7' local_gmpy2_version = gmpy2.version() if local_gmpy2_version != expected_gmpy2_version: print( '[WARNING] You are using version %s of gmpy2. These scripts have been tested with version %s' % (local_gmpy2_version, expected_gmpy2_version), file=sys.stderr)
def _test(chat=None): if chat: print "Unit tests for gmpy2 (extra cover)" print " on Python %s" % sys.version print "Testing gmpy2 {0}".format(_g.version()) print " Mutliple-precision library: {0}".format(_g.mp_version()) print " Floating-point library: {0}".format(_g.mpfr_version()) print " Complex library: {0}".format(_g.mpc_version()) print " Caching Values: (Number) {0}".format(_g.get_cache()[0]) print " Caching Values: (Size, limbs) {0}".format(_g.get_cache()[1]) thismod = sys.modules.get(__name__) doctest.testmod(thismod, report=0) if chat: print print "Overall results for cvr:" return doctest.master.summarize(chat)
def _test(chat=None): if chat: print "Unit tests for gmpy2 (extra cover)" print " on Python %s" % sys.version print "Testing gmpy2 {0}".format(_g.version()) print " Mutliple-precision library: {0}".format(_g.mp_version()) print " Floating-point library: {0}".format(_g.mpfr_version()) print " Complex library: {0}".format(_g.mpc_version()) print " Caching Values: (Number) {0}".format(_g.get_cache()[0]) print " Caching Values: (Size, limbs) {0}".format(_g.get_cache()[1]) thismod = sys.modules.get(__name__) doctest.testmod(thismod, report=0, optionflags=doctest.IGNORE_EXCEPTION_DETAIL) if chat: print print "Overall results for cvr:" return doctest.master.summarize(chat)
def _test(chat=None): if chat: print("Unit tests for gmpy2 (extra cover)") print(" on Python %s" % sys.version) print("Testing gmpy2 {0}".format(_g.version())) print(" Mutliple-precision library: {0}".format(_g.mp_version())) print(" Floating-point library: {0}".format(_g.mpfr_version())) print(" Complex library: {0}".format(_g.mpc_version())) print(" Caching Values: (Number) {0}".format(_g.get_cache()[0])) print(" Caching Values: (Size, limbs) {0}".format(_g.get_cache()[1])) print(__test__.keys()) thismod = sys.modules.get(__name__) doctest.testmod(thismod, report=0) if chat: print() print("Overall results for cvr:") return doctest.master.summarize(chat)
def _test(chat=None): if chat: print("Unit tests for gmpy2 (decimal interoperation)") print(" on Python %s" % sys.version) print("Testing gmpy2 {0}".format(_g.version())) print(" Mutliple-precision library: {0}".format(_g.mp_version())) print(" Floating-point library: {0}".format(_g.mpfr_version())) print(" Complex library: {0}".format(_g.mpc_version())) print(" Caching Values: (Number) {0}".format(_g.get_cache()[0])) print(" Caching Values: (Size, limbs) {0}".format(_g.get_cache()[1])) if not _d: if chat: print("Can't test, since can't import decimal") return 0, 0 thismod = sys.modules.get(__name__) doctest.testmod(thismod, report=0) if chat: print() print("Overall results for dec:") return doctest.master.summarize(chat)
def _test(chat=None): if chat: print("Unit tests for gmpy2 (extra cover)") print(" on Python %s" % sys.version) print("Testing gmpy2 {0}".format(_g.version())) print(" Mutliple-precision library: {0}".format(_g.mp_version())) print(" Floating-point library: {0}".format(_g.mpfr_version())) print(" Complex library: {0}".format(_g.mpc_version())) print(" Caching Values: (Number) {0}".format(_g.get_cache()[0])) print(" Caching Values: (Size, limbs) {0}".format(_g.get_cache()[1])) print(__test__.keys()) thismod = sys.modules.get(__name__) doctest.testmod(thismod, report=0, optionflags=doctest.IGNORE_EXCEPTION_DETAIL) if chat: print() print("Overall results for cvr:") return doctest.master.summarize(chat)
def _test(chat=None): try: float('nan') except ValueError: if "special" in __test__: del(__test__["special"]) if chat: print "Unit tests for gmpy2 (mpz functionality)" print " on Python %s" % sys.version print "Testing gmpy2 {0}".format(_g.version()) print " Mutliple-precision library: {0}".format(_g.mp_version()) print " Floating-point library: {0}".format(_g.mpfr_version()) print " Complex library: {0}".format(_g.mpc_version()) print " Caching Values: (Number) {0}".format(_g.get_cache()[0]) print " Caching Values: (Size, limbs) {0}".format(_g.get_cache()[1]) thismod = sys.modules.get(__name__) doctest.testmod(thismod, report=0, optionflags=doctest.IGNORE_EXCEPTION_DETAIL) if chat: print "Repeating tests, with caching disabled" _g.set_cache(0,128) sav = sys.stdout class _Dummy: def write(self,*whatever): pass try: sys.stdout = _Dummy() doctest.testmod(thismod, report=0, optionflags=doctest.IGNORE_EXCEPTION_DETAIL) finally: sys.stdout = sav if chat: print print "Overall results for mpz:" return doctest.master.summarize(chat)
else: HASH_BITS = 61 else: HASH_MODULUS = None HASH_BITS = None if "MPMATH_NOGMPY" not in os.environ: try: try: import gmpy2 as gmpy except ImportError: try: import gmpy except ImportError: raise ImportError if gmpy.version() >= "1.03": BACKEND = "gmpy" MPZ = gmpy.mpz except: pass if "MPMATH_NOSAGE" not in os.environ: try: import sage.all import sage.libs.mpmath.utils as _sage_utils sage = sage.all sage_utils = _sage_utils BACKEND = "sage" MPZ = sage.Integer except:
else: HASH_BITS = 61 else: HASH_MODULUS = None HASH_BITS = None if 'MPMATH_NOGMPY' not in os.environ: try: try: import gmpy2 as gmpy except ImportError: try: import gmpy except ImportError: raise ImportError if gmpy.version() >= '1.03': BACKEND = 'gmpy' MPZ = gmpy.mpz except: pass if 'MPMATH_NOSAGE' not in os.environ: try: import sage.all import sage.libs.mpmath.utils as _sage_utils sage = sage.all sage_utils = _sage_utils BACKEND = 'sage' MPZ = sage.Integer except: pass
import gmpy2 import shutil import subprocess import sys import tempfile import os from distutils.dir_util import copy_tree try: import Cython except ImportError: sys.stderr.write('Cython is not installed... skipping cython tests') sys.exit(0) print() print("Unit tests for gmpy2 {0} with Cython {1}".format(gmpy2.version(), Cython.__version__)) print() try: old_path = os.getcwd() tempdir_path = tempfile.mkdtemp() dirname = os.path.dirname(__file__) if dirname != '': os.chdir(dirname) copy_tree('./', tempdir_path) os.chdir(tempdir_path) if subprocess.call([sys.executable, 'setup_cython.py', 'build_ext', '--inplace']): raise SystemExit('compilation failed')
def test_gmpy2_version(): expected_gmpy2_version = '2.0.7' local_gmpy2_version = gmpy2.version() if local_gmpy2_version != expected_gmpy2_version: print('[WARNING] You are using version %s of gmpy2. These scripts have been tested with version %s' %(local_gmpy2_version, expected_gmpy2_version), file=sys.stderr)
debug = True except AttributeError: debug = False # Change repeat to the number of times to repeat each test. Combined with a # debug build, this can help identify memory leaks. if debug: try: repeat = abs(int(sys.argv[1])) except: repeat = 1 else: repeat = 1 print() print("Unit tests for gmpy2 {0} with Python {1}".format(gmpy2.version(), sys.version.split()[0])) print(" Mutliple-precision library: {0}".format(gmpy2.mp_version())) print(" Floating-point library: {0}".format(gmpy2.mpfr_version())) print(" Complex library: {0}".format(gmpy2.mpc_version())) print(" Caching Values: (Cache size) {0}".format(gmpy2.get_cache()[0])) print(" Caching Values: (Size in limbs) {0}".format(gmpy2.get_cache()[1])) print() if sys.version.startswith('3.1'): print("Due to differences in formatting of exceptions and Python 3.x, there") print("will be test failures for exception handling when the tests are run") print("with Python 3.1. The doctest module in Python 3.2 and later does not") print("have this issue.") print() input("Press ENTER to continue.. ") print()
else: HASH_BITS = 61 else: HASH_MODULUS = None HASH_BITS = None if 'MPMATH_NOGMPY' not in os.environ: try: try: import gmpy2 as gmpy except ImportError: try: import gmpy except ImportError: raise ImportError if gmpy.version() >= '1.13': BACKEND = 'gmpy' MPZ = gmpy.mpz except: pass if 'MPMATH_NOSAGE' not in os.environ: try: import sage.all import sage.libs.mpmath.utils as _sage_utils sage = sage.all sage_utils = _sage_utils BACKEND = 'sage' MPZ = sage.Integer except: pass
except AttributeError: debug = False # Change repeat to the number of times to repeat each test. Combined with a # debug build, this can help identify memory leaks. if debug: try: repeat = abs(int(sys.argv[1])) except: repeat = 1 else: repeat = 1 print() print("Unit tests for gmpy2 {0} with Python {1}".format( gmpy2.version(), sys.version.split()[0])) print(" Mutliple-precision library: {0}".format(gmpy2.mp_version())) print(" Floating-point library: {0}".format(gmpy2.mpfr_version())) print(" Complex library: {0}".format(gmpy2.mpc_version())) print(" Caching Values: (Cache size) {0}".format(gmpy2.get_cache()[0])) print(" Caching Values: (Size in limbs) {0}".format(gmpy2.get_cache()[1])) print() if sys.version.startswith('3.1'): print( "Due to differences in formatting of exceptions and Python 3.x, there") print( "will be test failures for exception handling when the tests are run") print( "with Python 3.1. The doctest module in Python 3.2 and later does not")
import shutil import subprocess import sys import tempfile import os from distutils.dir_util import copy_tree try: import Cython except ImportError: sys.stderr.write('Cython is not installed... skipping cython tests') sys.exit(0) print() print("Unit tests for gmpy2 {0} with Cython {1}".format( gmpy2.version(), Cython.__version__)) print() try: old_path = os.getcwd() tempdir_path = tempfile.mkdtemp() dirname = os.path.dirname(__file__) if dirname != '': os.chdir(dirname) copy_tree('./', tempdir_path) os.chdir(tempdir_path) if subprocess.call( [sys.executable, 'setup_cython.py', 'build_ext', '--inplace']): raise SystemExit('compilation failed')
sage = None sage_utils = None BACKEND = "python" MPZ = long if "MPMATH_NOGMPY" not in os.environ: try: try: import gmpy2 as gmpy except ImportError: try: import gmpy except ImportError: raise ImportError if gmpy.version() >= "1.03": if sys.version_info < (2, 5): import warnings warnings.warn( "GMPY mpmath backend is not supported in Python " "2.4. Falling back to python backend.", UserWarning, ) else: BACKEND = "gmpy" MPZ = gmpy.mpz except: pass if "MPMATH_NOSAGE" not in os.environ: try: