
__author__    = "Ole Weidner"
__copyright__ = "Copyright 2013, The SAGA Project"
__license__   = "MIT"


import os
import sys
import glob
import optparse

try:
    import saga
    import saga.utils.test_config as sutc
    import radical.utils.testing as rut

    print "______________________________________________________________________"
    print "Using saga-python from: %s" % str(saga)
    print "______________________________________________________________________"

except Exception, e:
    srcdir = "%s/../" % os.path.dirname(os.path.realpath(__file__))
    sys.path.insert(0, os.path.abspath(srcdir))
    import saga
    import saga.utils.test_config as sutc
    import radical.utils.testing as rut
    print "______________________________________________________________________"
    print "Using saga-python from: %s" % str(saga)
    print "______________________________________________________________________"


#-----------------------------------------------------------------------------
# entry point
if __name__ == "__main__":

    parser = optparse.OptionParser ()
    parser.add_option ("-n", "--notimpl-warn-only",
                       action  = "store_true", 
                       dest    = "notimpl_warn_only", 
                       default = False,
                       help    = "if set, warn on NotImplemented exceptions. "
                               + "If set to 'False' (default), NotImplemented "
                               + "will produce an error.")
    parser.add_option ("-c", "--config", 
                       dest    = "config", 
                       metavar = "CONFIG",
                       help    = "either a directory that contains test config "
                               + "files or a comma-separated list of individual "
                               + "config files")

    (options, args) = parser.parse_args ()

    if options.config == None and not args :
        print "ERROR: You need to provide the -c/--config option."
        sys.exit (-1)


    # set up the testing framework
    testing = rut.Testing ('saga', __file__)

    # test_cfgs will contain a list of all configuation files
    # that we will use for the tests
    test_cfgs = args

    for config in options.config.split (",") :
        if  os.path.exists (config) :
            test_cfgs.append (config)
        else:
            print "ERROR: Directory/file '%s' doesn't exist." % config
            sys.exit (-1)

    print test_cfgs
    sys.exit (0)

    for test_cfg in test_cfgs :

        # for each config, set up the test config singleton and run the tests
        tc = sutc.TestConfig (test_cfg)

        # tag the notimpl_warn_only option to the config
        tc.notimpl_warn_only = options.notimpl_warn_only

        testing.run ()


# ------------------------------------------------------------------------------



@@ -1883,23 +1883,25 @@
 rgs ()%0A%0A
+%0A
     if 
+ 
 options.
@@ -1915,19 +1915,29 @@
 == None 
-and
+:%0A        if 
  not arg
@@ -1940,16 +1940,20 @@
  args :%0A
+    
         
@@ -1991,32 +1991,43 @@
 de t
-he -c/--config option.%22%0A
+est config files as arguments%22%0A    
     
@@ -2048,96 +2048,54 @@
 -1)%0A
-%0A%0A
     
-# set up the testing framework%0A    testing = rut.Test
+    options.config = %22,%22.jo
 in
-g
  (
-'saga', __file__)
+args)%0A
 %0A%0A   
- #
  tes
@@ -2105,112 +2105,16 @@
 fgs 
-will contain a list of all configuation files%0A    # that we will use for the tests%0A    test_cfgs = args%0A
+= list()
 %0A   
@@ -2349,44 +2349,107 @@
 1)%0A%0A
+%0A
     
-print test_cfgs%0A    sys.exit (0)
+# set up the testing framework%0A    testing = rut.Testing ('saga', __file__)%0A    ret     = True
 %0A%0A  
@@ -2725,21 +2725,102 @@
     
-testing.run (
+# run the tests...%0A        if  not testing.run () :%0A            ret = False%0A%0A    sys.exit (ret
 )%0A%0A%0A

fix backward compatible arg parsing and error reporting in tests