def loadMod(module): if module == 'crlibm': SHARED_LIB = os.path.join(LIB_DIR, "libf2crlibm." + LIB_EXT) elif module == 'run_star_support': SHARED_LIB = os.path.join(LIB_DIR, "librun_star_support." + LIB_EXT) else: SHARED_LIB = os.path.join(LIB_DIR, "lib" + module + "." + LIB_EXT) MODULE_LIB = os.path.join(INCLUDE_DIR, module + "_lib.mod") MODULE_DEF = os.path.join(INCLUDE_DIR, module + "_def.mod") x = None y = None try: x = gf.fFort(SHARED_LIB, MODULE_LIB, rerun=True) except FileNotFoundError: pass try: y = gf.fFort(SHARED_LIB, MODULE_DEF, rerun=True) except FileNotFoundError: pass return x, y
import unittest2 as unittest import subprocess import numpy.testing as np_test from contextlib import contextmanager try: from StringIO import StringIO from BytesIO import BytesIO except ImportError: from io import StringIO from io import BytesIO os.chdir('tests') subprocess.check_output(["make"]) x = gf.fFort('./tester.so', 'tester.mod', rerun=True) #Decreases recursion depth to make debugging easier #sys.setrecursionlimit(100) @contextmanager def captured_output(): """ For use when we need to grab the stdout/stderr from fortran (but only in testing) Use as: with captured_output() as (out,err): func() output=out.getvalue().strip() error=err.getvalue().strip() """
try: import unittest as unittest except ImportError: import unittest2 as unittest import os import subprocess import tempfile import random import filecmp import gfort2py as gf os.chdir('test') x = gf.fFort('../lib/libfSys.so', '../include/fshell.mod', rerun=True) class TestSystem(unittest.TestCase): def test_gfort2py(self): # Make sure it loaded correctly self.assertEqual(hasattr(x, '_funcs'), True) class TestMkdir(unittest.TestCase): def test_make_empty(self): folder = tempfile.mkdtemp() os.rmdir(folder) x.mkdir(folder) self.assertEqual(os.path.isdir(folder), True) os.rmdir(folder)