summaryrefslogtreecommitdiff
path: root/tools/unit_tests.py
diff options
context:
space:
mode:
authorAndy Hayden <andyhayden1@gmail.com>2019-05-30 13:40:40 -0700
committerRyan Dahl <ry@tinyclouds.org>2019-05-30 16:40:40 -0400
commit8fb44eba5bb9862de5fcc6c785eb6f21ecbd0aea (patch)
tree9c866283b36d8388af4fd0e72d2bf2da4b8b70e4 /tools/unit_tests.py
parent1540b36ce7a4740f4a87c564becca65ed8d97255 (diff)
chore: refactor python tests to use unittest (#2414)
Move every test to a method on DenoTestCase. test.py is a single TestSuite of every TestCase. Add a Spawn context manager for http_server, this is explicitly used where it's needed. Each python test file can now be run independently without needing to manually run http_server. Add --help and consistent flags using argparse for each python test, including --failfast. Use ColorTextTestRunner so that '... ok' is green.
Diffstat (limited to 'tools/unit_tests.py')
-rwxr-xr-xtools/unit_tests.py35
1 files changed, 18 insertions, 17 deletions
diff --git a/tools/unit_tests.py b/tools/unit_tests.py
index 10f6a4a47..439ea325f 100755
--- a/tools/unit_tests.py
+++ b/tools/unit_tests.py
@@ -2,26 +2,27 @@
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import sys
import subprocess
-import http_server
+from http_server import spawn
+from util import DenoTestCase, test_main
-def unit_tests(deno_exe):
- cmd = [
- deno_exe, "run", "--reload", "--allow-run", "js/unit_test_runner.ts"
- ]
- process = subprocess.Popen(
- cmd, bufsize=1, universal_newlines=True, stderr=subprocess.STDOUT)
- process.wait()
- errcode = process.returncode
- if errcode != 0:
- sys.exit(errcode)
+class JsUnitTests(DenoTestCase):
+ def test_unit_test_runner(self):
+ cmd = [
+ self.deno_exe, "run", "--reload", "--allow-run",
+ "js/unit_test_runner.ts"
+ ]
+ process = subprocess.Popen(
+ cmd, bufsize=1, universal_newlines=True, stderr=subprocess.STDOUT)
+ process.wait()
+ errcode = process.returncode
+ if errcode != 0:
+ raise AssertionError(
+ "js/unit_test_runner.ts exited with exit code %s" % errcode)
-if __name__ == '__main__':
- if len(sys.argv) < 2:
- print "Usage ./tools/unit_tests.py target/debug/deno"
- sys.exit(1)
- http_server.spawn()
- unit_tests(sys.argv[1])
+if __name__ == '__main__':
+ with spawn():
+ test_main()