Coverage for tests/env_test.py: 96%
26 statements
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-08 18:54 +0000
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-08 18:54 +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/martinjankoehler/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
35@allure.parent_suite("Unit Tests")
36@allure.tag("Env", "Environment", "Environmental Variables")
37class Test(unittest.TestCase):
38 def test_env_has_defaults(self):
39 # ensure env is unset
40 for var in EnvVar:
41 if var.value in os.environ:
42 del os.environ[var.value]
44 env = Env.from_os_environ()
46 for var in EnvVar:
47 val = env[var]
48 self.assertNotEqual('', val, f"Env must have a non-empty default for every variable, "
49 f"but {var.value} has none!")
51 def test_env_with_custom_variables(self):
52 def value_for_var(var: EnvVar) -> str:
53 return f"{var.value}_is_set"
55 # ensure env is unset
56 for var in EnvVar:
57 os.environ[var.value] = value_for_var(var)
59 env = Env.from_os_environ()
61 for var in EnvVar:
62 val = env[var]
63 self.assertEqual(value_for_var(var), val,
64 f"Envrionmental variable {var.value} was set to '{value_for_var(var)}', "
65 f"but Env['{var.value}'] returns '{val}'!")