forked from kovidgoyal/kitty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·49 lines (39 loc) · 1.24 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
import importlib
import os
import sys
import warnings
from tempfile import TemporaryDirectory
from contextlib import contextmanager
from typing import Iterator
base = os.path.dirname(os.path.abspath(__file__))
@contextmanager
def env_vars(**kw: str) -> Iterator[None]:
originals = {k: os.environ.get(k) for k in kw}
os.environ.update(kw)
try:
yield
finally:
for k, v in originals.items():
if v is None:
os.environ.pop(k, None)
else:
os.environ[k] = v
def init_env() -> None:
sys.path.insert(0, base)
def main() -> None:
warnings.simplefilter('error')
with TemporaryDirectory() as tdir, env_vars(
PYTHONWARNINGS='error', HOME=tdir, USERPROFILE=tdir,
XDG_CONFIG_HOME=os.path.join(tdir, '.config'),
XDG_CONFIG_DIRS=os.path.join(tdir, '.config'),
XDG_DATA_DIRS=os.path.join(tdir, '.local', 'xdg'),
XDG_CACHE_HOME=os.path.join(tdir, '.cache'),
):
init_env()
m = importlib.import_module('kitty_tests.main')
m.run_tests() # type: ignore
if __name__ == '__main__':
main()