summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt3
-rw-r--r--include/gras/CMakeLists.txt1
-rw-r--r--include/gras/element.i44
-rw-r--r--python/gras/CMakeLists.txt1
-rw-r--r--python/gras/GRASElements.i16
-rw-r--r--tests/CMakeLists.txt14
-rw-r--r--tests/import_test.py25
7 files changed, 93 insertions, 11 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dd0b5fe..1420595 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,6 +6,8 @@ project(gras CXX C)
enable_testing()
set(GRAS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(GRAS_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+
list(APPEND CMAKE_MODULE_PATH ${GRAS_SOURCE_DIR}/PMC/cmake/Modules)
include(CMakeDefsHelper)
@@ -53,3 +55,4 @@ add_subdirectory(include/gras)
add_subdirectory(lib)
add_subdirectory(PMC)
add_subdirectory(python/gras)
+add_subdirectory(tests)
diff --git a/include/gras/CMakeLists.txt b/include/gras/CMakeLists.txt
index 69c4d2c..d5607c9 100644
--- a/include/gras/CMakeLists.txt
+++ b/include/gras/CMakeLists.txt
@@ -5,6 +5,7 @@ install(FILES
block.hpp
element.hpp
+ element.i
gras.hpp
hier_block.hpp
io_signature.hpp
diff --git a/include/gras/element.i b/include/gras/element.i
new file mode 100644
index 0000000..aa197c5
--- /dev/null
+++ b/include/gras/element.i
@@ -0,0 +1,44 @@
+//
+// Copyright 2012 Josh Blum
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef INCLUDED_GRAS_ELEMENT_I
+#define INCLUDED_GRAS_ELEMENT_I
+
+%{
+
+#include <gras/element.hpp>
+
+%}
+
+%include <std_string.i>
+
+%include <boost_shared_ptr.i>
+%shared_ptr(gras::ElementImpl)
+
+%include <gras/element.hpp>
+
+namespace gras
+{
+ %extend Element
+ {
+ std::string __str__(void)
+ {
+ return self->to_string();
+ }
+ }
+}
+
+#endif /*INCLUDED_GRAS_ELEMENT_I*/
diff --git a/python/gras/CMakeLists.txt b/python/gras/CMakeLists.txt
index cd0c9be..5386096 100644
--- a/python/gras/CMakeLists.txt
+++ b/python/gras/CMakeLists.txt
@@ -15,6 +15,7 @@ find_package(Boost) #for headers
########################################################################
list(APPEND GR_SWIG_INCLUDE_DIRS ${GRAS_INCLUDE_DIRS})
list(APPEND GR_SWIG_INCLUDE_DIRS ${Boost_INCLUDE_DIRS})
+set(GR_SWIG_LIBRARIES gras)
GR_SWIG_MAKE(GRASElements GRASElements.i)
GR_SWIG_INSTALL(
diff --git a/python/gras/GRASElements.i b/python/gras/GRASElements.i
index 1217ae8..12854a9 100644
--- a/python/gras/GRASElements.i
+++ b/python/gras/GRASElements.i
@@ -34,15 +34,11 @@
}
%{
-
-#include <gras/element.hpp>
#include <gras/hier_block.hpp>
#include <gras/top_block.hpp>
#include <gras/io_signature.hpp>
-
%}
-
////////////////////////////////////////////////////////////////////////
//helps with funny swig error for io signature
////////////////////////////////////////////////////////////////////////
@@ -55,10 +51,7 @@
////////////////////////////////////////////////////////////////////////
// pull in hier and top interface
////////////////////////////////////////////////////////////////////////
-%include <boost_shared_ptr.i>
-%shared_ptr(gras::ElementImpl)
-
-%include <gras/element.hpp>
+%include <gras/element.i>
%include <gras/hier_block.hpp>
%include <gras/top_block.hpp>
%include <gras/io_signature.hpp>
@@ -138,10 +131,11 @@ class TopBlock(TopBlockPython):
def disconnect(self, *args):
return internal_connect__(TopBlockPython.disconnect, self, *args)
-class HierBlock(HierBlock):
+HierBlockPython = HierBlock
+
+class HierBlock(HierBlockPython):
def __init__(self, *args, **kwargs):
- HierBlock.__init__(self, *args, **kwargs)
- self._hb = self #backwards compat
+ HierBlockPython.__init__(self, *args, **kwargs)
def connect(self, *args):
return internal_connect__(HierBlock.connect, self, *args)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..be70903
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,14 @@
+########################################################################
+# Unit tests!
+########################################################################
+
+include(GrTest)
+
+include(GrPython)
+set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B})
+
+list(APPEND GR_TEST_PYTHON_DIRS ${GRAS_SOURCE_DIR}/python)
+list(APPEND GR_TEST_PYTHON_DIRS ${GRAS_BINARY_DIR}/python)
+list(APPEND GR_TEST_PYTHON_DIRS ${GRAS_BINARY_DIR}/python/gras)
+list(APPEND GR_TEST_PYTHON_DIRS ${GRAS_BINARY_DIR}/python/gras/${CMAKE_BUILD_TYPE})
+GR_ADD_TEST(import_test ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/import_test.py)
diff --git a/tests/import_test.py b/tests/import_test.py
new file mode 100644
index 0000000..4ccd00e
--- /dev/null
+++ b/tests/import_test.py
@@ -0,0 +1,25 @@
+
+import unittest
+
+class ImportTest(unittest.TestCase):
+
+ def test_import(self):
+ import gras
+
+ def test_expected_attrs(self):
+ import gras
+ self.assertTrue(hasattr(gras, 'HierBlock'))
+ self.assertTrue(hasattr(gras, 'TopBlock'))
+
+ def test_make_hier(self):
+ import gras
+ h = gras.HierBlock('my_hb')
+ print h
+
+ def test_make_top(self):
+ import gras
+ t = gras.TopBlock('my_tb')
+ print t
+
+if __name__ == '__main__':
+ unittest.main()