from subprocess import call, PIPE, Popen
import sys
import re

import numpy as np
from numpy.linalg import lapack_lite
from numpy.testing import TestCase, dec

class FindDependenciesLdd:
    def __init__(self):
        self.cmd = ['ldd']

        try:
            st = call(self.cmd, stdout=PIPE, stderr=PIPE)
        except OSError:
            raise RuntimeError("command %s cannot be run" % self.cmd)

    def get_dependencies(self, file):
        p = Popen(self.cmd + [file], stdout=PIPE, stderr=PIPE)
        stdout, stderr = p.communicate()
        if not (p.returncode == 0):
            raise RuntimeError("Failed to check dependencies for %s" % libfile)

        return stdout

    def grep_dependencies(self, file, deps):
        stdout = self.get_dependencies(file)

        rdeps = dict([(dep, re.compile(dep)) for dep in deps])
        founds = []
        for l in stdout.splitlines():
            for k, v in rdeps.items():
                if v.search(l):
                    founds.append(k)

        return founds

@dec.skipif(not(sys.platform[:5] == 'linux'), 
            "Skipping fortran compiler mismatch on non Linux platform")
def test_f77_mismatch():
    f = FindDependenciesLdd()
    deps = f.grep_dependencies(lapack_lite.__file__, 
                               ['libg2c', 'libgfortran'])
    if len(deps) > 1:
        raise AssertionFailure("Both g77 and gfortran runtimes linked in "\
        "lapack_lite ! This is likely to cause random crashes and wrong "\
        "results")

@@ -1024,16 +1024,53 @@
 founds%0A%0A
+class TestF77Mismatch(TestCase):%0A    
 @dec.ski
@@ -1120,16 +1120,20 @@
         
+    
 %22Skippin
@@ -1184,16 +1184,20 @@
 tform%22)%0A
+    
 def test
@@ -1201,24 +1201,26 @@
 est_
-f77_mismatch():%0A
+lapack(self):%0A    
     
@@ -1245,16 +1245,20 @@
 esLdd()%0A
+    
     deps
@@ -1334,16 +1334,20 @@
         
+   
+ 
 %5B'libg2c
@@ -1373,57 +1373,41 @@
     
-if len(deps) %3E 1:%0A        raise AssertionFailure(
+    self.failIf(len(deps) %3E 1,%0A%22%22
 %22Bot
@@ -1444,28 +1444,16 @@
 nked in 
-%22%5C%0A        %22
 lapack_l
@@ -1475,17 +1475,17 @@
 ikely to
- 
+%0A
 cause ra
@@ -1511,26 +1511,61 @@
 ong 
-%22%5C%0A        %22results
+results. See numpy INSTALL.txt for more%0Ainformation.%22%22
 %22)%0A

Fix fortrab ABI mismatch test.