#!/usr/bin/env python3

#
# Jasy - Web Tooling Framework
# Copyright 2010-2012 Zynga Inc.
#

# Import standard library stuff
import sys, os.path

# Importing PKG Resources which is mainly required to be loaded before Pygments
# for omitting ugly side effect errors. Not required at all otherwise.
try:
    import pkg_resources
except ImportError:
    pass

# Version check
if sys.version_info[0] < 3:
    sys.stderr.write("Jasy requires Python 3!\n")
    sys.exit(1)

# Include local Jasy into Python library path
basedir = os.path.join(os.path.dirname(sys.argv[0]), os.pardir)
if os.path.exists(os.path.join(basedir, "jasy")):
    sys.path.insert(0, basedir)

import logging, unittest, jasy

test_dir = os.path.normpath(os.path.join(os.path.dirname(jasy.__file__), "test"))

print("Running Unit Tests for Jasy %s" % jasy.__version__)
print("From: %s" % test_dir)

loader = unittest.TestLoader()
res = loader.discover(test_dir, pattern='*.py')

logging.getLogger().setLevel(logging.ERROR)

result = unittest.TextTestRunner(verbosity=1).run(res)

if result.failures:
	sys.exit(1)
else:
	sys.exit(0)
