# SPDX-License-Identifier: BSD-3-Clause
# Copyright Contributors to the OpenEXR Project.

import sys, os, glob, unittest


cwd = os.getcwd()

print(sys.argv)

# Make sure we're in the correct directory to get the tests
main_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
os.chdir( main_dir )

# For now, add the path we import from
# for imath paths and make sure they come
# before any other paths
sys.path.insert(1, os.path.abspath(sys.argv[1]))

testFiles = sys.argv[2:]

if not testFiles:
    testFiles = glob.glob('test*.py')

# Load all the tests
suite = unittest.TestSuite()

for file in testFiles:
    name = os.path.splitext(file)[0]
    __import__(name)
    test = unittest.defaultTestLoader.loadTestsFromName(name)
    suite.addTest(test)


# lets set it back before running so our Alembic files get dumped into
# our original working directory, instead of the source of our tests
os.chdir( cwd )

# Run the tests
runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(suite)

if not result.wasSuccessful():
    exit(1)
