Coverage for tests/common/capacitance_matrix_test.py: 100%
36 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-17 17:24 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-17 17:24 +0000
1#
2# --------------------------------------------------------------------------------
3# SPDX-FileCopyrightText: 2024 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
29import tempfile
30from typing import *
31import unittest
33from klayout_pex.common.capacitance_matrix import CapacitanceMatrix
36@allure.parent_suite("Unit Tests")
37@allure.tag("Capacitance", "FasterCap")
38class Test(unittest.TestCase):
39 @property
40 def klayout_testdata_dir(self) -> str:
41 return os.path.realpath(os.path.join(__file__, '..', '..', '..',
42 'testdata', 'fastercap'))
44 def test_parse_csv(self):
45 csv_path = os.path.join(self.klayout_testdata_dir, 'nmos_diode2_FasterCap_Result_Matrix.csv')
46 parsed_matrix = CapacitanceMatrix.parse_csv(path=csv_path, separator=';')
47 self.assertEqual(3, len(parsed_matrix.rows))
48 self.assertEqual(3, len(parsed_matrix.rows[0]))
49 self.assertEqual(3, len(parsed_matrix.rows[1]))
50 self.assertEqual(3, len(parsed_matrix.rows[2]))
51 self.assertEqual(
52 ['g1_VSUBS', 'g1_VDD', 'g1_VSS'],
53 parsed_matrix.conductor_names
54 )
56 def test_write_csv(self):
57 csv_path = os.path.join(self.klayout_testdata_dir, 'nmos_diode2_FasterCap_Result_Matrix.csv')
58 parsed_matrix = CapacitanceMatrix.parse_csv(path=csv_path, separator=';')
59 out_path = tempfile.mktemp(prefix='fastercap_matrix_raw__', suffix='.csv')
60 parsed_matrix.write_csv(output_path=out_path, separator=';')
61 parsed_matrix2 = CapacitanceMatrix.parse_csv(path=out_path, separator=';')
62 self.assertEqual(parsed_matrix, parsed_matrix2)
64 def test_averaged_off_diagonals(self):
65 csv_path = os.path.join(self.klayout_testdata_dir, 'nmos_diode2_FasterCap_Result_Matrix.csv')
66 parsed_matrix = CapacitanceMatrix.parse_csv(path=csv_path, separator=';')
67 avg_matrix = parsed_matrix.averaged_off_diagonals()
68 out_path = tempfile.mktemp(prefix='fastercap_matrix_avg__', suffix='.csv')
69 avg_matrix.write_csv(output_path=out_path, separator=';')
70 allure.attach.file(out_path, attachment_type=allure.attachment_type.CSV)
71 print(f"averaged matrix stored in {out_path}")