
##############################################################################
#
# Copyright (c) 2003-2016 by The University of Queensland
# http://www.uq.edu.au
#
# Primary Business: Queensland, Australia
# Licensed under the Apache License, version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Development until 2012 by Earth Systems Science Computational Center (ESSCC)
# Development 2012-2013 by School of Earth Sciences
# Development from 2014 by Centre for Geoscience Computing (GeoComp)
#
##############################################################################


import os
Import('*')

local_env = env.Clone()

# 
#  files defining test runs (passing in a release)
# 
testruns = []
testruns += ['run_escriptOnDudley.py']
testruns += ['run_inputOutput.py']
testruns += ['run_linearPDEsOnDudley1.py']
testruns += ['run_linearPDEsOnDudley2.py']
testruns += ['run_nlpde2dOnDudley.py']
testruns += ['run_nlpde3dOnDudley.py']
testruns += ['run_models.py']
testruns += ['run_simplesolve.py']
testruns += ['run_utilOnDudley.py']
# 
#  files defining a few tests for a quick test
# 
scalable_tests = []
scalable_tests += ['run_inputOutput.py']
scalable_tests += ['run_simplesolve.py']
#
# files defining tests run locally (not as part of a release)
#
localtestruns = [x for x in Glob('*.py', strings=True) if not x.startswith('run_')]

#
# all test 
#
alltestruns = testruns + localtestruns
#
# test files are just compiled:

test_pyc = env.PyCompile(alltestruns)
env.Alias('build_py_tests', test_pyc)

#Add Unit Test to target alias
local_env.PrependENVPath('PYTHONPATH', Dir('.').abspath)
local_env.PrependENVPath('PYTHONPATH', env.Dir('$BUILD_DIR/$PLATFORM/dudley/test/python').abspath)
local_env.PrependENVPath('PYTHONPATH', env.Dir('$BUILD_DIR/$PLATFORM/escriptcore/test/python').abspath)
local_env['ENV']['DUDLEY_TEST_DATA']=Dir('.').srcnode().abspath
local_env['ENV']['DUDLEY_WORKDIR']=Dir('.').abspath
# needed for a test from the util base class in escript
local_env['ENV']['ESCRIPT_WORKDIR']=Dir('.').abspath
env.Alias('local_py_tests',[os.path.splitext(x)[0]+'.passed' for x in alltestruns])
env.Alias('py_tests', [os.path.splitext(x)[0]+'.passed' for x in testruns ])
env.Alias('scalable_tests', [os.path.splitext(x)[0]+'.passed' for x in scalable_tests ])

#
# run all tests:
#
# run all tests
program = local_env.RunPyUnitTest(alltestruns)
Depends(program, py_wrapper_lib)
Depends(program, 'build_py_tests')
if env['usempi']:
    Depends(program, env['prefix']+"/lib/pythonMPI")

# Add a group of tests
from grouptest import *
tgroup=GroupTest("$PYTHONRUNNER ",(("DUDLEY_TEST_DATA","$BATCH_ROOT/dudley/test/python"),('DUDLEY_WORKDIR','$BUILD_DIR/dudley/test/python')),"$BATCH_ROOT/escriptcore/test/python:$BATCH_ROOT/dudley/test/python","$BATCH_ROOT/dudley/test/python",testruns)
tgroup.makeDir("$BUILD_DIR/dudley/test/python")
TestGroups.append(tgroup)

