#!/usr/bin/env python
# encoding: utf-8

Import('env')
Import('programs')


import subprocess


def run_tests(target=None, source=None, env=None):
    names = ['nosetests-3.3', 'nosetests-3', 'python3-nosetests', 'nosetests3', 'nosetests']
    for name in names:
        print('Found nosetests as ,,{}"'.format(name))
        if not subprocess.call(name + ' -s -v -a !slow', shell=True):
            Exit(0)

    print('Unable to find nosetests, tried these: ' + str(names))
    Exit(-1)


if 'test' in COMMAND_LINE_TARGETS:
    env.Alias('test',
        env.Depends(
            env.Command('run_tests', None, Action(run_tests, "Running tests")),
            programs
        )
    )
