Ejemplo n.º 1
0
def test_temppath():
    with temppath() as fpath:
        with open(fpath, 'w') as f:
            pass
    assert_(not os.path.isfile(fpath))

    raised = False
    try:
        with temppath() as fpath:
            raise ValueError()
    except ValueError:
        raised = True
    assert_(raised)
    assert_(not os.path.isfile(fpath))
Ejemplo n.º 2
0
    def test_simple(self):
        with temppath('foo.ini') as path:
            with open(path, 'w') as f:
                f.write(simple)
            pkg = os.path.splitext(path)[0]
            out = read_config(pkg)

        assert_(out.cflags() == simple_d['cflags'])
        assert_(out.libs() == simple_d['libflags'])
        assert_(out.name == simple_d['name'])
        assert_(out.version == simple_d['version'])
Ejemplo n.º 3
0
    def test_simple_variable(self):
        with temppath('foo.ini') as path:
            with open(path, 'w') as f:
                f.write(simple_variable)
            pkg = os.path.splitext(path)[0]
            out = read_config(pkg)

        assert_(out.cflags() == simple_variable_d['cflags'])
        assert_(out.libs() == simple_variable_d['libflags'])
        assert_(out.name == simple_variable_d['name'])
        assert_(out.version == simple_variable_d['version'])
        out.vars['prefix'] = '/Users/david'
        assert_(out.cflags() == '-I/Users/david/include')
Ejemplo n.º 4
0
def _get_compiler_status():
    global _compiler_status
    if _compiler_status is not None:
        return _compiler_status

    _compiler_status = (False, False, False)

    # XXX: this is really ugly. But I don't know how to invoke Distutils
    #      in a safer way...
    code = """
import os
import sys
sys.path = %(syspath)s

def configuration(parent_name='',top_path=None):
    global config
    from numpy1.distutils.misc_util import Configuration
    config = Configuration('', parent_name, top_path)
    return config

from numpy1.distutils.core import setup
setup(configuration=configuration)

config_cmd = config.get_config_cmd()
have_c = config_cmd.try_compile('void foo() {}')
print('COMPILERS:%%d,%%d,%%d' %% (have_c,
                                  config.have_f77c(),
                                  config.have_f90c()))
sys.exit(99)
"""
    code = code % dict(syspath=repr(sys.path))

    with temppath(suffix='.py') as script:
        with open(script, 'w') as f:
            f.write(code)

        cmd = [sys.executable, script, 'config']
        p = subprocess.Popen(cmd,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
        out, err = p.communicate()

    m = re.search(br'COMPILERS:(\d+),(\d+),(\d+)', out)
    if m:
        _compiler_status = (bool(int(m.group(1))), bool(int(m.group(2))),
                            bool(int(m.group(3))))
    # Finished
    return _compiler_status
Ejemplo n.º 5
0
    def test_fromtextfile(self):
        # Tests reading from a text file.
        fcontent = ("""#
'One (S)','Two (I)','Three (F)','Four (M)','Five (-)','Six (C)'
'strings',1,1.0,'mixed column',,1
'with embedded "double quotes"',2,2.0,1.0,,1
'strings',3,3.0E5,3,,1
'strings',4,-1e-10,,,1
""")
        with temppath() as path:
            with open(path, 'w') as f:
                f.write(fcontent)
            mrectxt = fromtextfile(path, delimitor=',', varnames='ABCDEFG')
        assert_(isinstance(mrectxt, MaskedRecords))
        assert_equal(mrectxt.F, [1, 1, 1, 1])
        assert_equal(mrectxt.E._mask, [1, 1, 1, 1])
        assert_equal(mrectxt.C, [1, 2, 3.e+5, -1e-10])
Ejemplo n.º 6
0
def build_code(source_code,
               options=[],
               skip=[],
               only=[],
               suffix=None,
               module_name=None):
    """
    Compile and import Fortran code using f2py.

    """
    if suffix is None:
        suffix = '.f'
    with temppath(suffix=suffix) as path:
        with open(path, 'w') as f:
            f.write(source_code)
        return build_module([path],
                            options=options,
                            skip=skip,
                            only=only,
                            module_name=module_name)
Ejemplo n.º 7
0
 def test_fromfile_bogus(self):
     with temppath() as path:
         with open(path, 'wt') as f:
             f.write("1. 2. 3. flop 4.\n")
         res = np.fromfile(path, dtype=float, sep=" ")
     assert_equal(res, np.array([1., 2., 3.]))
Ejemplo n.º 8
0
 def test_tofile_roundtrip(self):
     with temppath() as path:
         self.tgt.tofile(path, sep=" ")
         res = np.fromfile(path, dtype=np.longdouble, sep=" ")
     assert_equal(res, self.tgt)
Ejemplo n.º 9
0
 def test_loadtxt(self):
     with temppath() as path:
         with open(path, 'wt') as f:
             f.write(self.out)
         res = np.loadtxt(path, dtype=np.longdouble)
     assert_equal(res, self.tgt)
Ejemplo n.º 10
0
 def test_fromfile(self):
     with temppath() as path:
         with open(path, 'wt') as f:
             f.write(self.out)
         res = np.fromfile(path, dtype=np.longdouble, sep="\n")
     assert_equal(res, self.tgt)