py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-08-29 00:52:31 +02:00
|
|
|
import argparse
|
2016-08-04 00:35:53 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
|
2017-02-05 21:24:28 +01:00
|
|
|
# check for the venv
|
|
|
|
from lib import sanity_check
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2017-02-05 21:24:28 +01:00
|
|
|
sanity_check.check_venv(__file__)
|
|
|
|
|
2016-08-04 00:35:53 +02:00
|
|
|
if __name__ == '__main__':
|
2016-08-29 00:52:31 +02:00
|
|
|
parser = argparse.ArgumentParser()
|
2020-09-02 04:49:02 +02:00
|
|
|
parser.add_argument('--coverage',
|
2016-12-11 14:30:45 +01:00
|
|
|
action="store_true",
|
2020-09-02 20:45:48 +02:00
|
|
|
help='compute test coverage')
|
2016-08-29 00:52:31 +02:00
|
|
|
args = parser.parse_args()
|
2016-08-04 00:35:53 +02:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def dir_join(dir1: str, dir2: str) -> str:
|
2016-08-04 00:35:53 +02:00
|
|
|
return os.path.abspath(os.path.join(dir1, dir2))
|
|
|
|
|
|
|
|
tools_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
root_dir = dir_join(tools_dir, '..')
|
|
|
|
tools_test_dir = dir_join(tools_dir, 'tests')
|
|
|
|
|
|
|
|
sys.path.insert(0, root_dir)
|
|
|
|
|
2017-08-07 02:01:59 +02:00
|
|
|
loader = unittest.TestLoader()
|
2016-08-04 00:35:53 +02:00
|
|
|
|
2016-08-29 00:52:31 +02:00
|
|
|
if args.coverage:
|
2016-08-04 00:35:53 +02:00
|
|
|
import coverage
|
2016-12-02 06:22:52 +01:00
|
|
|
cov = coverage.Coverage(branch=True, omit=["*/zulip-venv-cache/*", dir_join(tools_test_dir, "*")])
|
2016-08-04 00:35:53 +02:00
|
|
|
cov.start()
|
|
|
|
|
|
|
|
suite = loader.discover(start_dir=tools_test_dir, top_level_dir=root_dir)
|
|
|
|
runner = unittest.TextTestRunner(verbosity=2)
|
2017-08-25 20:01:20 +02:00
|
|
|
result = runner.run(suite)
|
2016-08-04 00:35:53 +02:00
|
|
|
if result.errors or result.failures:
|
|
|
|
raise Exception('Test failed!')
|
|
|
|
|
2016-08-29 00:52:31 +02:00
|
|
|
if args.coverage:
|
2016-08-04 00:35:53 +02:00
|
|
|
cov.stop()
|
|
|
|
cov.save()
|
|
|
|
cov.html_report(directory='var/tools_coverage')
|
|
|
|
print("HTML report saved to var/tools_coverage")
|
|
|
|
|
|
|
|
print('SUCCESS')
|