Coverage for tests/klayout/shapes_pb2_converter_test.py: 100%

42 statements  

« 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# 

24 

25import allure 

26import unittest 

27 

28import klayout.db as kdb 

29import klayout_pex_protobuf.kpex.geometry.shapes_pb2 as shapes_pb2 

30from klayout_pex.klayout.shapes_pb2_converter import ShapesConverter 

31 

32from klayout_pex.log import ( 

33 LogLevel, 

34 set_log_level, 

35) 

36 

37 

38@allure.parent_suite("Unit Tests") 

39@allure.tag("Geometry", "Shapes", "KLayout") 

40class ShapesConverterTest(unittest.TestCase): 

41 @classmethod 

42 def setUpClass(cls): 

43 set_log_level(LogLevel.DEBUG) 

44 

45 def setUp(self): 

46 self.dbu = 0.001 

47 

48 def test_klayout_region(self): 

49 conv = ShapesConverter(self.dbu) 

50 

51 r_pb = shapes_pb2.Region() 

52 pg_pb = r_pb.polygons.add() 

53 p0 = pg_pb.hull_points.add() 

54 p0.x = 10 

55 p0.y = 20 

56 p1 = pg_pb.hull_points.add() 

57 p1.x = 10 

58 p1.y = 30 

59 p2 = pg_pb.hull_points.add() 

60 p2.x = 750 

61 p2.y = 30 

62 p3 = pg_pb.hull_points.add() 

63 p3.x = 750 

64 p3.y = 20 

65 

66 r_kly = conv.klayout_region(r_pb) 

67 self.assertEqual(1, r_kly.count()) 

68 pg_kly = list(r_kly.each())[0] 

69 pt_kly = list(pg_kly.each_point_hull()) 

70 self.assertEqual(p0.x, pt_kly[0].x) 

71 self.assertEqual(p0.y, pt_kly[0].y) 

72 self.assertEqual(p1.x, pt_kly[1].x) 

73 self.assertEqual(p1.y, pt_kly[1].y) 

74 self.assertEqual(p2.x, pt_kly[2].x) 

75 self.assertEqual(p2.y, pt_kly[2].y) 

76 self.assertEqual(p3.x, pt_kly[3].x) 

77 self.assertEqual(p3.y, pt_kly[3].y)