forked from kernelci/kcidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_main.py
39 lines (33 loc) · 1.07 KB
/
test_main.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
"""main.py tests"""
import os
import subprocess
import unittest
from importlib import import_module
import yaml
@unittest.skipIf(os.environ.get("KCIDB_DEPLOYMENT"), "local-only")
def test_google_credentials_are_not_specified():
"""Check Google Application credentials are not specified"""
assert os.environ.get("GOOGLE_APPLICATION_CREDENTIALS") is None, \
"Local tests must run without " \
"GOOGLE_APPLICATION_CREDENTIALS " \
"environment variable"
def test_import():
"""Check main.py can be loaded"""
# Load deployment environment variables
file_dir = os.path.dirname(os.path.abspath(__file__))
cloud_path = os.path.join(file_dir, "cloud")
env = yaml.safe_load(
subprocess.check_output([
cloud_path,
"env", "kernelci-production", "", "0",
"--log-level=DEBUG"
])
)
env["GCP_PROJECT"] = "TEST_PROJECT"
orig_env = dict(os.environ)
try:
os.environ.update(env)
import_module("main")
finally:
os.environ.clear()
os.environ.update(orig_env)