import 0.2.1
This commit is contained in:
commit
5a4c7db6b4
35 changed files with 3888 additions and 0 deletions
0
test/__init__.py
Normal file
0
test/__init__.py
Normal file
BIN
test/data/test1.gds
Normal file
BIN
test/data/test1.gds
Normal file
Binary file not shown.
24
test/data/test1.txt
Normal file
24
test/data/test1.txt
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
HEADER: 5
|
||||
BGNLIB: 110, 8, 17, 14, 22, 22, 110, 8, 17, 14, 36, 21
|
||||
LIBNAME: "TEST.DB"
|
||||
UNITS: 0.001, 1e-09
|
||||
BGNSTR: 70, 1, 1, 1, 0, 0, 110, 8, 17, 14, 35, 55
|
||||
STRNAME: "test_struc1"
|
||||
BOUNDARY
|
||||
LAYER: 34
|
||||
DATATYPE: 0
|
||||
XY: 33100, -198900, 48100, -198900, 48100, -186800, 33100, -186800, 33100, -198900
|
||||
ENDEL
|
||||
PATH
|
||||
LAYER: 44
|
||||
DATATYPE: 0
|
||||
PATHTYPE: 0
|
||||
WIDTH: 15000
|
||||
XY: -125000, 0, -125000, -52000, -52000, -125000, 13100, -125000
|
||||
PROPATTR: 1
|
||||
PROPVALUE: "test property 1"
|
||||
PROPATTR: 2
|
||||
PROPVALUE: "test property 2"
|
||||
ENDEL
|
||||
ENDSTR
|
||||
ENDLIB
|
||||
60
test/test_lib.py
Normal file
60
test/test_lib.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import unittest
|
||||
from gdsii import library, elements
|
||||
import os.path
|
||||
|
||||
class TestLibraryLoad(unittest.TestCase):
|
||||
def setUp(self):
|
||||
file_name = os.path.join(os.path.dirname(__file__), 'data', 'test1.gds')
|
||||
with open(file_name, 'rb') as stream:
|
||||
self.library = library.Library.load(stream)
|
||||
|
||||
def test_library(self):
|
||||
library = self.library
|
||||
self.assertEqual(library.version, 5)
|
||||
self.assertEqual(library.name, b'TEST.DB')
|
||||
self.assertEqual(library.mod_time.isoformat(), '2010-08-17T14:22:22')
|
||||
self.assertEqual(library.acc_time.isoformat(), '2010-08-17T14:36:21')
|
||||
self.assertAlmostEqual(library.physical_unit, 1e-9)
|
||||
self.assertAlmostEqual(library.logical_unit, 0.001)
|
||||
|
||||
def test_structure(self):
|
||||
library = self.library
|
||||
self.assertEqual(len(library), 1)
|
||||
struc = library[0]
|
||||
self.assertEqual(struc.name, b'test_struc1')
|
||||
self.assertEqual(struc.mod_time.isoformat(), '1970-01-01T01:00:00')
|
||||
self.assertEqual(struc.acc_time.isoformat(), '2010-08-17T14:35:55')
|
||||
self.assertEqual(struc.strclass, None)
|
||||
|
||||
def test_elements(self):
|
||||
struc = self.library[0]
|
||||
self.assertEqual(len(struc), 2)
|
||||
elem = struc[0]
|
||||
self.assertTrue(isinstance(elem, elements.Boundary))
|
||||
self.assertEqual(elem.layer, 34)
|
||||
self.assertEqual(elem.data_type, 0)
|
||||
self.assertEqual(elem.xy, [(33100, -198900), (48100, -198900), (48100, -186800),
|
||||
(33100, -186800), (33100, -198900)])
|
||||
self.assertEqual(elem.properties, []) # TODO it should not be so
|
||||
elem = struc[1]
|
||||
self.assertTrue(isinstance(elem, elements.Path))
|
||||
self.assertEqual(elem.layer, 44)
|
||||
self.assertEqual(elem.data_type, 0)
|
||||
self.assertEqual(elem.path_type, 0)
|
||||
self.assertEqual(elem.width, 15000)
|
||||
self.assertEqual(elem.xy, [(-125000, 0), (-125000, -52000), (-52000, -125000), (13100, -125000)])
|
||||
self.assertEqual(len(elem.properties), 2)
|
||||
self.assertEqual(elem.properties[0], (1, b'test property 1'))
|
||||
self.assertEqual(elem.properties[1], (2, b'test property 2'))
|
||||
|
||||
test_cases = (TestLibraryLoad,)
|
||||
|
||||
def load_tests(loader, tests, pattern):
|
||||
suite = unittest.TestSuite()
|
||||
for test_class in test_cases:
|
||||
tests = loader.loadTestsFromTestCase(test_class)
|
||||
suite.addTests(tests)
|
||||
return suite
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
66
test/test_record.py
Normal file
66
test/test_record.py
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import unittest
|
||||
from gdsii.record import _parse_real8, _pack_real8, _int_to_real, _real_to_int
|
||||
from gdsii import exceptions
|
||||
import struct
|
||||
|
||||
class TestReal8(unittest.TestCase):
|
||||
data = {
|
||||
0x4110000000000000: 1.0,
|
||||
0x4120000000000000: 2.0,
|
||||
0x4130000000000000: 3.0,
|
||||
0xC110000000000000: -1.0,
|
||||
0xC120000000000000: -2.0,
|
||||
0xC130000000000000: -3.0,
|
||||
0x4080000000000000: 0.5,
|
||||
0x4099999999999999: 0.6,
|
||||
0x40B3333333333333: 0.7,
|
||||
0x4118000000000000: 1.5,
|
||||
0x4119999999999999: 1.6,
|
||||
0x411B333333333333: 1.7,
|
||||
0x0000000000000000: 0.0,
|
||||
0x41A0000000000000: 10.0,
|
||||
0x4264000000000000: 100.0,
|
||||
0x433E800000000000: 1000.0, # there is error in doc?
|
||||
0x4427100000000000: 10000.0,
|
||||
0x45186A0000000000: 100000.0
|
||||
}
|
||||
|
||||
def test_from_int(self):
|
||||
for int_val, real_val in self.data.items():
|
||||
self.assertAlmostEqual(_int_to_real(int_val), real_val)
|
||||
|
||||
def test_to_int(self):
|
||||
for int_val, real_val in self.data.items():
|
||||
self.assertAlmostEqual(real_val, _int_to_real(_real_to_int(real_val)))
|
||||
|
||||
def test_parse(self):
|
||||
packed_data = struct.pack('>{0}Q'.format(len(self.data)), *self.data.keys())
|
||||
unpacked = _parse_real8(packed_data)
|
||||
expected_results = list(self.data.values())
|
||||
self.assertEqual(len(unpacked), len(expected_results))
|
||||
for i in range(len(unpacked)):
|
||||
self.assertAlmostEqual(unpacked[i], expected_results[i])
|
||||
|
||||
def test_pack(self):
|
||||
packed_data = _pack_real8(self.data.values())
|
||||
unpacked = _parse_real8(packed_data)
|
||||
expected_results = list(self.data.values())
|
||||
self.assertEqual(len(unpacked), len(expected_results))
|
||||
for i in range(len(unpacked)):
|
||||
self.assertAlmostEqual(unpacked[i], expected_results[i])
|
||||
|
||||
def test_exceptions(self):
|
||||
for i in range(8):
|
||||
self.assertRaises(exceptions.IncorrectDataSize, _parse_real8, b' '*i)
|
||||
|
||||
test_cases = (TestReal8,)
|
||||
|
||||
def load_tests(loader, tests, pattern):
|
||||
suite = unittest.TestSuite()
|
||||
for test_class in test_cases:
|
||||
tests = loader.loadTestsFromTestCase(test_class)
|
||||
suite.addTests(tests)
|
||||
return suite
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue