2020-07-27 18:57:36 +00:00
|
|
|
"""
|
|
|
|
Helper to run Python unittests in the sandbox. They can be run directly as follows:
|
|
|
|
|
|
|
|
./sandbox/nacl/bin/run -E PYTHONPATH=/thirdparty python -m unittest discover -v -s /grist
|
|
|
|
|
|
|
|
This modules makes this a bit easier, and adds support for --xunit option, needed for running
|
|
|
|
tests under 'arc unit' and under Jenkins.
|
|
|
|
|
|
|
|
./sandbox/nacl/bin/run python /grist/runtests.py [--xunit]
|
|
|
|
"""
|
2020-11-02 15:48:47 +00:00
|
|
|
import codecs
|
2022-09-02 10:15:46 +00:00
|
|
|
import logging
|
2020-07-27 18:57:36 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
sys.path.append('/thirdparty')
|
|
|
|
|
2021-06-22 15:12:25 +00:00
|
|
|
import six
|
|
|
|
|
2020-07-27 18:57:36 +00:00
|
|
|
def main():
|
|
|
|
# Change to the directory of this file (/grist in sandbox), to discover everything under it.
|
|
|
|
os.chdir(os.path.dirname(__file__))
|
|
|
|
|
|
|
|
argv = sys.argv[:]
|
|
|
|
test_runner = None
|
|
|
|
if "--xunit" in argv:
|
|
|
|
import xmlrunner
|
|
|
|
argv.remove("--xunit")
|
2021-06-22 15:12:25 +00:00
|
|
|
utf8_stdout = sys.stdout
|
|
|
|
if six.PY2:
|
|
|
|
utf8_stdout = codecs.getwriter('utf8')(utf8_stdout)
|
2020-11-02 15:48:47 +00:00
|
|
|
test_runner = xmlrunner.XMLTestRunner(stream=utf8_stdout)
|
2020-07-27 18:57:36 +00:00
|
|
|
|
2022-09-02 10:15:46 +00:00
|
|
|
if "-v" in argv or "--verbose" in argv:
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
2020-07-27 18:57:36 +00:00
|
|
|
if all(arg.startswith("-") for arg in argv[1:]):
|
|
|
|
argv.insert(1, "discover")
|
|
|
|
|
|
|
|
unittest.main(module=None, argv=argv, testRunner=test_runner)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|