Bugfix #109 (part 3): OASIS/GDS writer fixed + unit test added.

This commit is contained in:
Matthias Koefferlein 2018-04-06 23:27:29 +02:00
parent 655eb49afd
commit 3d5780db2b
3 changed files with 52 additions and 9 deletions

View File

@ -831,15 +831,8 @@ GDS2WriterBase::write_properties (const db::Layout &layout, db::properties_id_ty
const tl::Variant &name = layout.properties_repository ().prop_name (p->first);
long attr = -1;
if (name.is_long ()) {
if (name.can_convert_to_long ()) {
attr = name.to_long ();
} else if (name.is_a_string ()) {
// string names representing a number are converted to numeric property names
tl::Extractor ex (name.to_string ());
long a = 0;
if (ex.try_read (a) && ex.at_end ()) {
attr = a;
}
}
if (attr >= 0 && attr < 65535) {

View File

@ -55,7 +55,9 @@ make_gds_property (const tl::Variant &name)
{
// We write S_GDS_PROPERTY properties, because that is the only way to write properties
// with numerical keys
return (name.is_long () && (name.to_long () < 0x8000 || name.to_long () >= 0)) ||
return (name.is_longlong () && name.to_longlong () < 0x8000 && name.to_longlong () >= 0) ||
(name.is_ulonglong () && name.to_ulonglong () < 0x8000) ||
(name.is_long () && name.to_long () < 0x8000 && name.to_long () >= 0) ||
(name.is_ulong () && name.to_ulong () < 0x8000);
}

View File

@ -19,6 +19,7 @@
import pya
import unittest
import sys
import os
class DBLayoutTest(unittest.TestCase):
@ -1104,6 +1105,53 @@ class DBLayoutTest(unittest.TestCase):
ly._destroy()
# Bug #109
def test_bug109(self):
testtmp = os.getenv("TESTTMP_WITH_NAME", os.getenv("TESTTMP", "."))
file_gds = os.path.join(testtmp, "bug109.gds")
file_oas = os.path.join(testtmp, "bug109.oas")
ly = pya.Layout()
top = ly.create_cell("TOP")
l1 = ly.layer(1, 0)
shape = top.shapes(l1).insert(pya.Box(0, 10, 20, 30))
shape.set_property(2, "hello, world")
shape.set_property("42", "the answer")
ly.write(file_gds)
ly.write(file_oas)
ly2 = pya.Layout()
ly2.read(file_gds)
l2 = ly2.layer(1, 0)
shape = None
for s in ly2.top_cell().shapes(l2).each():
shape = s
self.assertEqual(shape.property(2), "hello, world")
self.assertEqual(shape.property("2"), None)
self.assertEqual(shape.property(2.0), "hello, world")
self.assertEqual(shape.property(22), None)
self.assertEqual(shape.property(42), "the answer")
self.assertEqual(shape.property("42"), None)
self.assertEqual(shape.property(42.0), "the answer")
ly2 = pya.Layout()
ly2.read(file_oas)
l2 = ly2.layer(1, 0)
shape = None
for s in ly2.top_cell().shapes(l2).each():
shape = s
self.assertEqual(shape.property(2), "hello, world")
self.assertEqual(shape.property("2"), None)
self.assertEqual(shape.property(2.0), "hello, world")
self.assertEqual(shape.property(22), None)
self.assertEqual(shape.property("42"), "the answer")
self.assertEqual(shape.property(42), None)
self.assertEqual(shape.property(42.0), None)
# run unit tests
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(DBLayoutTest)