#!/usr/bin/env python
import unittest
import sys
import globals
import argparse
import os
import subprocess
import platform

def suite():
    suite = unittest.TestLoader().loadTestsFromNames(['testProcessHelperIOCVersions', 'testPush', 'testUpgrade', 'testDelete', 'testRevert', 'testRun', 'testMissingIOCTop', 'testLint', 'testParsing'])
    return suite

if __name__ == '__main__':
    globals.isunittests = True
    globals.dmzmachine = platform.node()

    parser = argparse.ArgumentParser()
    parser.add_argument('-v', '--verbose', action='store_true', help='Enable verbose logging')
    parser.add_argument('-t', '--tests', help='Specify the tests that need to be run.')
    args = parser.parse_args()
    globals.verbose = args.verbose
    
    
    # Check to see if we have set the PATH correctly. 
    # To run the unit tests against the multi_facility_process_helper.py in this folder, we need to have set the PATH to have the current folder ahead of ${TOOLS}/scripts.
    which_multi_facility_process_helper = os.path.realpath(subprocess.check_output(['which', 'multi_facility_process_helper.py']))
    if not os.path.realpath(os.getcwd()) in which_multi_facility_process_helper:
        raise Exception("We are getting multi_facility_process_helper.py from " +  which_multi_facility_process_helper + "Please set PATH to have the current folder ahead of " + os.path.dirname(which_multi_facility_process_helper))
    
    
    if args.tests:
        runner = unittest.TextTestRunner()
        test_suite = unittest.TestLoader().loadTestsFromNames([args.tests])
        runner.run (test_suite)
    else:
        runner = unittest.TextTestRunner()
        test_suite = suite()
        runner.run (test_suite)
