diff options
author | Andy Hayden <andyhayden1@gmail.com> | 2019-05-30 13:40:40 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-05-30 16:40:40 -0400 |
commit | 8fb44eba5bb9862de5fcc6c785eb6f21ecbd0aea (patch) | |
tree | 9c866283b36d8388af4fd0e72d2bf2da4b8b70e4 /tools/fetch_test.py | |
parent | 1540b36ce7a4740f4a87c564becca65ed8d97255 (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/fetch_test.py')
-rwxr-xr-x | tools/fetch_test.py | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/tools/fetch_test.py b/tools/fetch_test.py index 9ecb6fff4..35118ab96 100755 --- a/tools/fetch_test.py +++ b/tools/fetch_test.py @@ -2,29 +2,29 @@ # Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import os import sys -from util import mkdtemp, tests_path, run_output, green_ok import shutil +from http_server import spawn +from util import DenoTestCase, mkdtemp, tests_path, run_output, test_main -def fetch_test(deno_exe): - sys.stdout.write("fetch_test...") - sys.stdout.flush() - deno_dir = mkdtemp() - try: - t = os.path.join(tests_path, "006_url_imports.ts") - output = run_output([deno_exe, "fetch", t], - merge_env={"DENO_DIR": deno_dir}) - assert output == "" - # Check that we actually did the prefetch. - os.path.exists( - os.path.join(deno_dir, - "deps/http/localhost_PORT4545/tests/subdir/mod2.ts")) - finally: - shutil.rmtree(deno_dir) - - print green_ok() +class FetchTest(DenoTestCase): + def test_fetch(self): + deno_dir = mkdtemp() + try: + t = os.path.join(tests_path, "006_url_imports.ts") + output = run_output([self.deno_exe, "fetch", t], + merge_env={"DENO_DIR": deno_dir}) + assert output == "" + # Check that we actually did the prefetch. + os.path.exists( + os.path.join( + deno_dir, + "deps/http/localhost_PORT4545/tests/subdir/mod2.ts")) + finally: + shutil.rmtree(deno_dir) if __name__ == "__main__": - fetch_test(sys.argv[1]) + with spawn(): + test_main() |