WIP: rdb module for Python, fixed unit tests for non-Qt bindings case

This commit is contained in:
Matthias Koefferlein 2018-06-15 22:49:01 +02:00
parent 147ee20b55
commit 757c6af80f
8 changed files with 148 additions and 7 deletions

View File

@ -8,7 +8,7 @@ SOURCES = \
HEADERS += \
LIBS += -lklayout_lay
LIBS += -lklayout_lay -lklayout_ext
# Use this opportunity to provide the __init__.py file

View File

@ -3,6 +3,7 @@ TEMPLATE = subdirs
SUBDIRS = \
db \
tl \
rdb \
lay \
equals(HAVE_QTBINDINGS, "1") {

11
src/pymod/rdb/rdb.pro Normal file
View File

@ -0,0 +1,11 @@
TARGET = rdb
include($$PWD/../pymod.pri)
SOURCES = \
rdbMain.cc \
HEADERS += \
LIBS += -lklayout_rdb

25
src/pymod/rdb/rdbMain.cc Normal file
View File

@ -0,0 +1,25 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2018 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../pymodHelper.h"
DEFINE_PYMOD(rdb, "rdb", "KLayout core module 'rdb'")

View File

@ -29,6 +29,7 @@
#include <QProcessEnvironment>
int run_pymodtest (tl::TestBase * /*_this*/, const std::string &fn)
{
QProcess process;
@ -57,7 +58,12 @@ PYMODTEST (bridge, "bridge.py")
PYMODTEST (import_tl, "import_tl.py")
PYMODTEST (import_db, "import_db.py")
PYMODTEST (import_rdb, "import_rdb.py")
#if defined(HAVE_QTBINDINGS)
PYMODTEST (import_lay, "import_lay.py")
PYMODTEST (import_QtCore, "import_QtCore.py")
PYMODTEST (import_QtGui, "import_QtGui.py")
PYMODTEST (import_QtXml, "import_QtXml.py")
@ -74,3 +80,9 @@ PYMODTEST (import_QtSvg, "import_QtSvg.py")
PYMODTEST (import_QtXmlPatterns, "import_QtXmlPatterns.py")
#endif
#else
PYMODTEST (import_lay, "import_lay_noqt.py")
#endif

View File

@ -96,7 +96,7 @@ static rdb::Reference *new_ref_tp (const db::DCplxTrans &trans, rdb::id_type par
return new rdb::Reference (trans, parent_cell_id);
}
Class<rdb::Reference> decl_RdbReference ("lay", "RdbReference",
Class<rdb::Reference> decl_RdbReference ("rdb", "RdbReference",
gsi::constructor ("new", &new_ref_tp,
"@brief Creates a reference with a given transformation and parent cell ID\n"
"@args trans, parent_cell_id\n"
@ -166,7 +166,7 @@ ItemRefUnwrappingIterator cell_items_end (const rdb::Cell *cell)
return cell->database ()->items_by_cell (cell->id ()).second;
}
Class<rdb::Cell> decl_RdbCell ("lay", "RdbCell",
Class<rdb::Cell> decl_RdbCell ("rdb", "RdbCell",
gsi::method ("rdb_id", &rdb::Cell::id,
"@brief Gets the cell ID\n"
"The cell ID is an integer that uniquely identifies the cell. It is used for referring to a "
@ -272,7 +272,7 @@ static void scan_shapes (rdb::Category *cat, const db::RecursiveShapeIterator &i
rdb::scan_layer (cat, iter);
}
Class<rdb::Category> decl_RdbCategory ("lay", "RdbCategory",
Class<rdb::Category> decl_RdbCategory ("rdb", "RdbCategory",
gsi::method ("rdb_id", &rdb::Category::id,
"@brief Gets the category ID\n"
"The category ID is an integer that uniquely identifies the category. It is used for referring to a "
@ -559,7 +559,7 @@ void value_set_tag_id (rdb::ValueWrapper *v, rdb::id_type id)
v->set_tag_id (id);
}
Class<rdb::ValueWrapper> decl_RdbItemValue ("lay", "RdbItemValue",
Class<rdb::ValueWrapper> decl_RdbItemValue ("rdb", "RdbItemValue",
gsi::method ("from_s", &value_from_string,
"@brief Creates a value object from a string\n"
"@args s\n"
@ -739,7 +739,7 @@ static void clear_values (rdb::Item *item)
item->set_values (rdb::Values ());
}
Class<rdb::Item> decl_RdbItem ("lay", "RdbItem",
Class<rdb::Item> decl_RdbItem ("rdb", "RdbItem",
gsi::method ("database", (const rdb::Database *(rdb::Item::*)() const) &rdb::Item::database,
"@brief Gets the database object that item is associated with\n"
"\n"
@ -1078,7 +1078,7 @@ static rdb::Item *create_item_from_objects (rdb::Database *db, rdb::Cell *cell,
}
}
Class<rdb::Database> decl_ReportDatabase ("lay", "ReportDatabase",
Class<rdb::Database> decl_ReportDatabase ("rdb", "ReportDatabase",
gsi::constructor ("new", &create_rdb,
"@brief Creates a report database\n"
"@args name\n"

47
testdata/pymod/import_lay_noqt.py vendored Normal file
View File

@ -0,0 +1,47 @@
# KLayout Layout Viewer
# Copyright (C) 2006-2018 Matthias Koefferlein
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import pykl.db as db
import pykl.lay as lay
import unittest
import sys
# Tests the basic abilities of the module
class BasicTest(unittest.TestCase):
def test_1(self):
self.assertEqual("Annotation" in lay.__all__, True)
def test_2(self):
# Some smoke test
ant = lay.Annotation()
ant.style = lay.Annotation.StyleRuler
self.assertEqual(str(ant.style), str(lay.Annotation.StyleRuler))
ant.fmt_x = "abc"
self.assertEqual(ant.fmt_x, "abc")
# run unit tests
if __name__ == '__main__':
suite = unittest.TestSuite()
suite = unittest.TestLoader().loadTestsFromTestCase(BasicTest)
if not unittest.TextTestRunner(verbosity = 1).run(suite).wasSuccessful():
sys.exit(1)

45
testdata/pymod/import_rdb.py vendored Normal file
View File

@ -0,0 +1,45 @@
# KLayout Layout Viewer
# Copyright (C) 2006-2018 Matthias Koefferlein
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import pykl.rdb as rdb
import unittest
import sys
# Tests the basic abilities of the module
class BasicTest(unittest.TestCase):
def test_1(self):
self.assertEqual("RdbItemValue" in rdb.__all__, True)
def test_2(self):
# Some smoke test
v = rdb.RdbItemValue()
self.assertEqual(str(v), "")
v = rdb.RdbItemValue(2.5)
self.assertEqual(str(v), "float: 2.5")
# run unit tests
if __name__ == '__main__':
suite = unittest.TestSuite()
suite = unittest.TestLoader().loadTestsFromTestCase(BasicTest)
if not unittest.TextTestRunner(verbosity = 1).run(suite).wasSuccessful():
sys.exit(1)