From bce1b36834cdee4bc17f059a13df32ff759e1075 Mon Sep 17 00:00:00 2001
From: pospelov <pospelov@fz-juelich.de>
Date: Tue, 26 Mar 2013 13:22:01 +0100
Subject: [PATCH] Again forgotten files for test_all.py

---
 Tests/FunctionalTests/TestCore/README         |  2 +-
 Tests/FunctionalTests/TestCore/TestCore.py    |  2 +-
 Tests/FunctionalTests/TestFit/README          |  2 +-
 Tests/FunctionalTests/TestFit/TestFit.py      | 84 ++++++++++---------
 Tests/FunctionalTests/TestFit/test_all.py     | 69 ---------------
 Tests/FunctionalTests/TestPyCore/README       |  2 +-
 .../FunctionalTests/TestPyCore/TestPyCore.py  |  2 +-
 Tests/FunctionalTests/TestPyFit/README        |  2 +-
 Tests/FunctionalTests/TestPyFit/TestPyFit.py  | 67 ++++++++-------
 Tests/FunctionalTests/TestPyFit/test_all.py   | 60 -------------
 Tests/FunctionalTests/TestPyFit/testfit01.py  | 16 ++--
 Tests/FunctionalTests/test_all.py             | 37 +++++---
 12 files changed, 121 insertions(+), 224 deletions(-)
 delete mode 100755 Tests/FunctionalTests/TestFit/test_all.py
 delete mode 100644 Tests/FunctionalTests/TestPyFit/test_all.py

diff --git a/Tests/FunctionalTests/TestCore/README b/Tests/FunctionalTests/TestCore/README
index 85340a48ee1..6942121e934 100644
--- a/Tests/FunctionalTests/TestCore/README
+++ b/Tests/FunctionalTests/TestCore/README
@@ -7,7 +7,7 @@ To build all tests
 qmake; make
 
 To run tests
-python test_all.py
+python TestCore.py
 
 List of tests
 IsGISAXS01 - Mixture of cylinders and prisms without interference (IsGISAXS example #1)
diff --git a/Tests/FunctionalTests/TestCore/TestCore.py b/Tests/FunctionalTests/TestCore/TestCore.py
index 248d478a06f..c8a5406cb42 100755
--- a/Tests/FunctionalTests/TestCore/TestCore.py
+++ b/Tests/FunctionalTests/TestCore/TestCore.py
@@ -52,7 +52,7 @@ def parse_output(testName, stdout, stderr):
 
 # run tests one by one
 def runTests():
-  print ">>> Starting TestCore"
+  print ">>> Running TestCore, {0:-2d} tests total ...".format(len(Tests))
   for testName in Tests:
     command =  testName+"/"+testName # i.e. "path/executable" like "IsGISAXS01/IsGISAXS01"
     path = os.path.split(__file__)[0]
diff --git a/Tests/FunctionalTests/TestFit/README b/Tests/FunctionalTests/TestFit/README
index 63e29717a12..2ebb0ed821e 100644
--- a/Tests/FunctionalTests/TestFit/README
+++ b/Tests/FunctionalTests/TestFit/README
@@ -5,7 +5,7 @@ Different geometries, number of fit parameters, variety of minimizers
 and minimization strategies.
 
 To run tests
-python test_all.py
+python TestFit.py
 
 List of tests
 TestFit01 - Two parameter fit using variety of minimizers. Geometry: cylinders in the air.
diff --git a/Tests/FunctionalTests/TestFit/TestFit.py b/Tests/FunctionalTests/TestFit/TestFit.py
index 8d81ba91aa5..ef0f2888701 100755
--- a/Tests/FunctionalTests/TestFit/TestFit.py
+++ b/Tests/FunctionalTests/TestFit/TestFit.py
@@ -14,56 +14,62 @@ test_info = []
 
 # run system command and catch multiline stdout and stderr
 def run_command(command):
-    p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-    p.wait()
-    return iter(p.stdout.readline, b''), iter(p.stderr.readline, b'')
+  p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+  p.wait()
+  return iter(p.stdout.readline, b''), iter(p.stderr.readline, b'')
 
 
 # parse stdout, stderr for test description and test result
 def parse_output(testName, stdout, stderr):
-    # normally the message from test looks like "IsGISAXS01 Mixture of cylinders and prisms [OK]"
-    # we want to find status (FAILED or OK) and extract description "Mixture of cylinders and prisms"
-    status="OK"
-    for line in stderr:
-        status="FAILED" # test failed, if there are some non empty stderr messages
-    descr=""
-    for line in stdout:
-        if testName in line:
-            if "FAILED" in line:
-                status="FAILED"
-            descr=line.strip(testName).strip("\n")
-            descr=descr.strip("[OK]")
-            descr=descr.strip("[FAILED]")
-
-    descr = descr[:55]
-    descr = descr.ljust(55)
-    return descr, status
+  # normally the message from test looks like "IsGISAXS01 Mixture of cylinders and prisms [OK]"
+  # we want to find status (FAILED or OK) and extract description "Mixture of cylinders and prisms"
+  status="OK"
+  for line in stderr:
+    status="FAILED" # test failed, if there are some non empty stderr messages
+  descr=""
+  for line in stdout:
+    if testName in line:
+      if "FAILED" in line: status="FAILED"
+      descr=line.strip(testName).strip("\n")
+      descr=descr.strip("[OK]")
+      descr=descr.strip("[FAILED]")
+  descr = descr[:55]
+  descr = descr.ljust(55).lstrip()
+  return descr, status
 
 
 # run tests one by one
 def runTests():
-    for testName in Tests:
-        command = testName+"/"+testName # i.e. "path/executable" like "IsGISAXS01/IsGISAXS01"
-        print "Running test ", testName
-        start_time = time.time()
-        stdout, stderr = run_command(command)
-        total_time = time.time() - start_time
-        descr, status = parse_output(testName, stdout, stderr)
-        test_info.append((testName, descr, total_time, status))
+  print ">>> Running TestFit, {0:-2d} tests total ...".format(len(Tests))
+  for testName in Tests:
+    command =  testName+"/"+testName # i.e. "path/executable" like "IsGISAXS01/IsGISAXS01"
+    path = os.path.split(__file__)[0]
+    if path: command = path + "/" + command
+    print "Running test ", testName
+    start_time = time.time()
+    stdout, stderr = run_command(command)
+    total_time = time.time() - start_time
+    descr, status = parse_output(testName, stdout, stderr)
+    test_info.append((testName, descr, total_time, status))
+  return getSummary()
+
+
+# making summary
+def getSummary():
+  summary  = "--------------------------------------------------------------------------------\n"
+  summary += "Functional Tests of libBornAgainFit (C++)                                      \n"
+  summary += "--------------------------------------------------------------------------------\n"
+  n=1
+  for x in test_info:
+    summary += '{0:2d}. {1} {2:.53s}  {3:.2f}s [{4}] '.format(n, x[0],x[1],x[2],x[3]) + "\n"
+    n+=1
+  return summary
 
-# print test results
-def printResults():
-    print "-------------------------------------------------------------------------------"
-    print "TestFit Summary                                                                "
-    print "-------------------------------------------------------------------------------"
-    n=1
-    for x in test_info:
-        print '{0:2d}. {1} {2}  {3:.3f}sec  [{4}] '.format(n, x[0],x[1],x[2],x[3])
-        n+=1
 
 #-------------------------------------------------------------
 # main()
 #-------------------------------------------------------------
 if __name__ == '__main__':
-    runTests()
-    printResults()
+  summary = runTests()
+  print summary
+
diff --git a/Tests/FunctionalTests/TestFit/test_all.py b/Tests/FunctionalTests/TestFit/test_all.py
deleted file mode 100755
index 8d81ba91aa5..00000000000
--- a/Tests/FunctionalTests/TestFit/test_all.py
+++ /dev/null
@@ -1,69 +0,0 @@
-# Run C++ fitting tests for libBornAgainFit library
-# Usage: python test_all.py
-
-import sys
-import os
-import subprocess
-import time
-
-Tests = [
-    "TestFit01",
-]
-
-test_info = []
-
-# run system command and catch multiline stdout and stderr
-def run_command(command):
-    p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-    p.wait()
-    return iter(p.stdout.readline, b''), iter(p.stderr.readline, b'')
-
-
-# parse stdout, stderr for test description and test result
-def parse_output(testName, stdout, stderr):
-    # normally the message from test looks like "IsGISAXS01 Mixture of cylinders and prisms [OK]"
-    # we want to find status (FAILED or OK) and extract description "Mixture of cylinders and prisms"
-    status="OK"
-    for line in stderr:
-        status="FAILED" # test failed, if there are some non empty stderr messages
-    descr=""
-    for line in stdout:
-        if testName in line:
-            if "FAILED" in line:
-                status="FAILED"
-            descr=line.strip(testName).strip("\n")
-            descr=descr.strip("[OK]")
-            descr=descr.strip("[FAILED]")
-
-    descr = descr[:55]
-    descr = descr.ljust(55)
-    return descr, status
-
-
-# run tests one by one
-def runTests():
-    for testName in Tests:
-        command = testName+"/"+testName # i.e. "path/executable" like "IsGISAXS01/IsGISAXS01"
-        print "Running test ", testName
-        start_time = time.time()
-        stdout, stderr = run_command(command)
-        total_time = time.time() - start_time
-        descr, status = parse_output(testName, stdout, stderr)
-        test_info.append((testName, descr, total_time, status))
-
-# print test results
-def printResults():
-    print "-------------------------------------------------------------------------------"
-    print "TestFit Summary                                                                "
-    print "-------------------------------------------------------------------------------"
-    n=1
-    for x in test_info:
-        print '{0:2d}. {1} {2}  {3:.3f}sec  [{4}] '.format(n, x[0],x[1],x[2],x[3])
-        n+=1
-
-#-------------------------------------------------------------
-# main()
-#-------------------------------------------------------------
-if __name__ == '__main__':
-    runTests()
-    printResults()
diff --git a/Tests/FunctionalTests/TestPyCore/README b/Tests/FunctionalTests/TestPyCore/README
index eb6f0922834..16846c0dd14 100644
--- a/Tests/FunctionalTests/TestPyCore/README
+++ b/Tests/FunctionalTests/TestPyCore/README
@@ -7,7 +7,7 @@ To build all tests
 qmake; make
 
 To run tests
-python test_all.py
+python TestPyCore.py
 
 List of tests
 IsGISAXS01 - Mixture of cylinders and prisms without interference (IsGISAXS example #1)
diff --git a/Tests/FunctionalTests/TestPyCore/TestPyCore.py b/Tests/FunctionalTests/TestPyCore/TestPyCore.py
index 388113aa6e0..fd940c20571 100644
--- a/Tests/FunctionalTests/TestPyCore/TestPyCore.py
+++ b/Tests/FunctionalTests/TestPyCore/TestPyCore.py
@@ -52,7 +52,7 @@ def parse_output(testName, test_result):
 
 # run tests one by one
 def runTests():
-  print ">>> Starting TestPyCore"
+  print ">>> Running TestPyCore, {0:-2d} tests total ...".format(len(Tests))
   for testName in sorted(Tests.iterkeys()):
     print "Running test ", testName
     start_time = time.time()
diff --git a/Tests/FunctionalTests/TestPyFit/README b/Tests/FunctionalTests/TestPyFit/README
index 150ef386dcd..66fc0dd2307 100644
--- a/Tests/FunctionalTests/TestPyFit/README
+++ b/Tests/FunctionalTests/TestPyFit/README
@@ -5,7 +5,7 @@ Different geometries, number of fit parameters, variety of minimizers
 and minimization strategies.
 
 To run tests
-python test_all.py
+python TestPyFit.py
 
 List of tests
 testfit01.py - Two parameter fit using variety of minimizers. Geometry: cylinders in the air.
diff --git a/Tests/FunctionalTests/TestPyFit/TestPyFit.py b/Tests/FunctionalTests/TestPyFit/TestPyFit.py
index 33c891b3897..6caba87190c 100644
--- a/Tests/FunctionalTests/TestPyFit/TestPyFit.py
+++ b/Tests/FunctionalTests/TestPyFit/TestPyFit.py
@@ -16,45 +16,48 @@ test_info = []
 
 # parse stdout, stderr for test description and test result
 def parse_output(testName, test_result):
-    # normally the message from test looks like "IsGISAXS01 Mixture of cylinders and prisms [OK]"
-    # we want to find status (FAILED or OK) and extract description "Mixture of cylinders and prisms"
-    status="OK"
-    descr=""
-    if testName in test_result:
-        descr = test_result[1]
-        status = test_result[2]
-    else:
-       descr = "Can't parse the description"
-    descr = descr[:55]
-    descr = descr.ljust(55)
-    return descr, status
+  # normally the message from test looks like "IsGISAXS01 Mixture of cylinders and prisms [OK]"
+  # we want to find status (FAILED or OK) and extract description "Mixture of cylinders and prisms"
+  status="OK"
+  descr=""
+  if testName in test_result:
+    descr = test_result[1]
+    status = test_result[2]
+  else:
+   descr = "Can't parse the description"
+  descr = descr[:55]
+  descr = descr.ljust(55)
+  return descr, status
 
 
 # run tests one by one
 def runTests():
-    for testName in sorted(Tests.iterkeys()):
-        print "Running test ", testName
-        start_time = time.time()
-        result = Tests[testName]()
-        total_time = time.time() - start_time
-        descr, status = parse_output(testName, result)
-        test_info.append((testName, descr, total_time, status))
-
-
-# print test results
-def printResults():
-    print "-------------------------------------------------------------------------------"
-    print "TestPyFit Summary                                                              "
-    print "-------------------------------------------------------------------------------"
-    n=1
-    for x in test_info:
-        print '{0:2d}. {1}  {2}  {3:.3f}sec  [{4}] '.format(n, x[0],x[1],x[2],x[3])
-        n+=1
+  print ">>> Running TestPyFit, {0:-2d} tests total ...".format(len(Tests))
+  for testName in sorted(Tests.iterkeys()):
+    print "Running test ", testName
+    start_time = time.time()
+    result = Tests[testName]()
+    total_time = time.time() - start_time
+    descr, status = parse_output(testName, result)
+    test_info.append((testName, descr, total_time, status))
+  return getSummary()
+
+
+# compose summary
+def getSummary():
+  summary  = "--------------------------------------------------------------------------------\n"
+  summary += "Functional Tests of libBornAgainFit (Python)                                    \n"
+  summary += "--------------------------------------------------------------------------------\n"
+  n=1
+  for x in test_info:
+    summary += '{0:2d}. {1} {2:.53s}  {3:.2f}s [{4}] '.format(n, x[0],x[1],x[2],x[3]) + "\n"
+    n+=1
+  return summary
 
 
 #-------------------------------------------------------------
 # main()
 #-------------------------------------------------------------
 if __name__ == '__main__':
-    runTests()
-    printResults()
+  summary = runTests()
+  print summary
diff --git a/Tests/FunctionalTests/TestPyFit/test_all.py b/Tests/FunctionalTests/TestPyFit/test_all.py
deleted file mode 100644
index 33c891b3897..00000000000
--- a/Tests/FunctionalTests/TestPyFit/test_all.py
+++ /dev/null
@@ -1,60 +0,0 @@
-# Run Python fitting tests for libBornAgainFit library
-# Usage: python test_all.py
-
-import sys
-import os
-import subprocess
-import time
-
-import testfit01
-
-Tests = {
-    "TestFit01": testfit01.runTest
-}
-
-test_info = []
-
-# parse stdout, stderr for test description and test result
-def parse_output(testName, test_result):
-    # normally the message from test looks like "IsGISAXS01 Mixture of cylinders and prisms [OK]"
-    # we want to find status (FAILED or OK) and extract description "Mixture of cylinders and prisms"
-    status="OK"
-    descr=""
-    if testName in test_result:
-        descr = test_result[1]
-        status = test_result[2]
-    else:
-       descr = "Can't parse the description"
-    descr = descr[:55]
-    descr = descr.ljust(55)
-    return descr, status
-
-
-# run tests one by one
-def runTests():
-    for testName in sorted(Tests.iterkeys()):
-        print "Running test ", testName
-        start_time = time.time()
-        result = Tests[testName]()
-        total_time = time.time() - start_time
-        descr, status = parse_output(testName, result)
-        test_info.append((testName, descr, total_time, status))
-
-
-# print test results
-def printResults():
-    print "-------------------------------------------------------------------------------"
-    print "TestPyFit Summary                                                              "
-    print "-------------------------------------------------------------------------------"
-    n=1
-    for x in test_info:
-        print '{0:2d}. {1}  {2}  {3:.3f}sec  [{4}] '.format(n, x[0],x[1],x[2],x[3])
-        n+=1
-
-
-#-------------------------------------------------------------
-# main()
-#-------------------------------------------------------------
-if __name__ == '__main__':
-    runTests()
-    printResults()
diff --git a/Tests/FunctionalTests/TestPyFit/testfit01.py b/Tests/FunctionalTests/TestPyFit/testfit01.py
index 6f6e0db94d2..34172693e64 100644
--- a/Tests/FunctionalTests/TestPyFit/testfit01.py
+++ b/Tests/FunctionalTests/TestPyFit/testfit01.py
@@ -39,15 +39,15 @@ Minimizers = [
 # run several minimization rounds using different minimizers
 # -----------------------------------------------------------------------------
 def runTest():
-  print "**********************************************************************"
-  print "*  Starting  TestFit01                                               *"
-  print "**********************************************************************"
+  #print "**********************************************************************"
+  #print "*  Starting  TestFit01                                               *"
+  #print "**********************************************************************"
   nTest=0
   status = "OK"
   for m in Minimizers:
     minimizer_name = m[0]
     minimizer_algorithm = m[1]
-    print "Test {0:2d}   {1:}({2:})".format(nTest, minimizer_name, minimizer_algorithm)
+    print "Minimizer {0:-2d}   {1:}({2:})".format(nTest, minimizer_name, minimizer_algorithm)
     result_ok = run_fitting(minimizer_name, minimizer_algorithm)
     nTest+=1
     if not result_ok: status = "FAILED"
@@ -84,10 +84,10 @@ def run_fitting(minimizer_name, minimizer_algorithm):
   radius_found = fitSuite.getMinimizer().getValueOfVariableAtMinimum(1)
   radius_diff = abs(radius_found - cylinder_radius)/cylinder_radius
 
-  print "          RealTime : {0:.3f} sec".format(real_time)
-  print "          NCalls   : {0:<5d}".format(fitSuite.getNCalls())
-  print '          par1     : {0:.4f} ({1:.3g}) '.format(height_found, height_diff)
-  print '          par2     : {0:.4f} ({1:.3g}) '.format(radius_found, radius_diff)
+  print "            RealTime : {0:.3f} sec".format(real_time)
+  print "            NCalls   : {0:<5d}".format(fitSuite.getNCalls())
+  print '            par1     : {0:.4f} ({1:.3g}) '.format(height_found, height_diff)
+  print '            par2     : {0:.4f} ({1:.3g}) '.format(radius_found, radius_diff)
 
   diff = 1.0e-02
   isSuccess = True
diff --git a/Tests/FunctionalTests/test_all.py b/Tests/FunctionalTests/test_all.py
index be9cd09c0df..7ac20993ba0 100644
--- a/Tests/FunctionalTests/test_all.py
+++ b/Tests/FunctionalTests/test_all.py
@@ -1,5 +1,5 @@
 # run C++/Python functional tests for BornAgain libraries
-#
+# C++ will be compiled automatically
 # Usage:
 # 'python test_all.py' - to run all tests
 # 'python test_all.py C++' - to run C++ tests only
@@ -12,26 +12,44 @@ import glob
 
 sys.path.insert(0, './TestPyCore')
 import TestPyCore
+sys.path.insert(0, './TestPyFit')
+import TestPyFit
 sys.path.insert(0, './TestCore')
 import TestCore
+sys.path.insert(0, './TestFit')
+import TestFit
 
-
-#-------------------------------------------------------------
-# run python functional tests
-#-------------------------------------------------------------
-def runPythonTests():
-  summary = TestPyCore.runTests()
-  return summary
+def run_command(command):
+  p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+  p.wait()
+  return iter(p.stdout.readline, b''), iter(p.stderr.readline, b'')
 
 
 #-------------------------------------------------------------
 # run C++ functional tests
 #-------------------------------------------------------------
 def runCppTests():
+  #make compilation
+  print "Compiling C++ functional tests"
+  os.system("cd TestCore; qmake; make")
+  os.system("cd TestFit; qmake; make")
+  #command = "cd TestCore; qmake; make"
+  #command = "cd TestFit; qmake; make"
+  #stdout, stderr = run_command(command)
+  #stdout, stderr = run_command(command)
   summary = TestCore.runTests()
+  summary += TestFit.runTests()
   return summary
 
 
+#-------------------------------------------------------------
+# run python functional tests
+#-------------------------------------------------------------
+def runPythonTests():
+  summary = TestPyCore.runTests()
+  summary += TestPyFit.runTests()
+  return summary
+
 
 #-------------------------------------------------------------
 # main()
@@ -48,12 +66,11 @@ def main():
   elif len(sys.argv) == 2:
     if "C++" in sys.argv[1]: run_python_tests = False
     if "Python" in sys.argv[1]: run_cpp_tests = False
-  print run_python_tests, run_cpp_tests
 
   summary  = "\n"
   summary += "Functional Tests Summary -->\n"
-  if run_python_tests: summary += runPythonTests()
   if run_cpp_tests: summary += runCppTests()
+  if run_python_tests: summary += runPythonTests()
   print summary
 
 
-- 
GitLab