File size: 2,245 Bytes
34292e0 | 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | #!/usr/bin/env python3
"""klayout.sh runs a KLayout executable: a deck still in Ruby, the
gallery and the viewers. Without KLayout it stops with an error. With KLayout, the call
goes to it unchanged.
"""
import os
import subprocess
import tempfile
import unittest
SCRIPTS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "scripts")
KLAYOUT_SH = os.path.join(SCRIPTS_DIR, "klayout.sh")
class TestKlayoutSh(unittest.TestCase):
def setUp(self):
self.tmp_dir = tempfile.TemporaryDirectory()
self.out_file = os.path.join(self.tmp_dir.name, "6_1_merged.gds")
def tearDown(self):
self.tmp_dir.cleanup()
def run_klayout(self, klayout_cmd, *args):
return subprocess.run(
["bash", KLAYOUT_SH, *args],
env=dict(os.environ, KLAYOUT_CMD=klayout_cmd),
capture_output=True,
text=True,
)
def stream_args(self):
return [
"-zz",
"-rd",
"design_name=gcd",
"-rd",
f"out_file={self.out_file}",
"-r",
"/flow/util/def2stream.py",
]
def test_ruby_deck_still_needs_klayout(self):
result = self.run_klayout(
"",
"-zz",
"-rd",
"in_gds=6_final.gds",
"-rd",
"report_file=6_drc.lyrdb",
"-r",
"deck.lydrc",
)
self.assertEqual(result.returncode, 1)
self.assertIn("Error: KLayout not found", result.stdout)
def test_viewer_still_needs_klayout(self):
result = self.run_klayout("", "-nn", "klayout.lyt", "6_final.odb")
self.assertEqual(result.returncode, 1)
self.assertIn("Error: KLayout not found", result.stdout)
self.assertFalse(os.path.exists(self.out_file))
def test_installed_klayout_gets_the_call(self):
result = self.run_klayout("echo", *self.stream_args())
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
self.assertNotIn("WARNING", result.stdout)
self.assertIn(f"out_file={self.out_file}", result.stdout)
self.assertFalse(os.path.exists(self.out_file))
if __name__ == "__main__":
unittest.main()
|