Coverage for tests/env_test.py: 97%
35 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-08 12:43 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-08 12:43 +0000
1#
2# --------------------------------------------------------------------------------
3# SPDX-FileCopyrightText: 2024-2025 Martin Jan Köhler and Harald Pretl
4# Johannes Kepler University, Institute for Integrated Circuits.
5#
6# This file is part of KPEX
7# (see https://github.com/iic-jku/klayout-pex).
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21# SPDX-License-Identifier: GPL-3.0-or-later
22# --------------------------------------------------------------------------------
23#
25from __future__ import annotations
27import allure
28import os
29from typing import *
30import unittest
32from klayout_pex.env import Env, EnvVar
33from klayout_pex.pdk_config import PDK
36@allure.parent_suite("Unit Tests")
37@allure.tag("Env", "Environment", "Environmental Variables")
38class Test(unittest.TestCase):
39 def test_env_has_defaults(self):
40 # ensure env is unset
41 for var in EnvVar:
42 if var.value in os.environ:
43 del os.environ[var.value]
45 env = Env.from_os_environ()
47 for var in EnvVar:
48 val = env[var]
49 self.assertNotEqual('', val, f"Env must have a non-empty default for every variable, "
50 f"but {var.value} has none!")
52 def test_env_with_custom_variables(self):
53 def value_for_var(var: EnvVar) -> str:
54 return f"{var.value}_is_set"
56 # ensure env is unset
57 for var in EnvVar:
58 os.environ[var.value] = value_for_var(var)
60 env = Env.from_os_environ()
62 for var in EnvVar:
63 val = env[var]
64 self.assertEqual(value_for_var(var), val,
65 f"Envrionmental variable {var.value} was set to '{value_for_var(var)}', "
66 f"but Env['{var.value}'] returns '{val}'!")
68 def test_valid_pdk_from_env(self):
69 os.environ[EnvVar.PDK.value] = 'sky130A'
70 env = Env.from_os_environ()
71 self.assertEqual(PDK.SKY130A, env.default_pdk)
73 def test_invalid_pdk_from_env(self):
74 os.environ[EnvVar.PDK.value] = 'invalid_pdk'
75 env = Env.from_os_environ()
76 self.assertIsNone(env.default_pdk)