Skip to content

Commit

Permalink
Fix unit tests & setup.py file (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
JafarAbdi committed Jul 30, 2021
1 parent cadab16 commit dd742a0
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 38 deletions.
11 changes: 8 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ install(PROGRAMS
set_target_properties(${PROJECT_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
target_compile_definitions(${PROJECT_NAME} PRIVATE "SRDFDOM_BUILDING_DLL")

ament_python_install_package(${PROJECT_NAME})

if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
ament_add_gtest(test_parser test/srdf_parser.test)
find_package(ament_cmake_pytest REQUIRED)
ament_add_pytest_test(self_parser_test "test/test.py")

add_definitions(-DTEST_RESOURCE_LOCATION="${CMAKE_SOURCE_DIR}/test/resources")
execute_process(COMMAND bash -c "locale -a | grep -q ^en_US"
Expand All @@ -77,8 +80,10 @@ if(BUILD_TESTING)
message(STATUS "Locale nl_NL not available. Locale test will not be meaningful.")
endif()

ament_add_gtest(test_cpp test/srdf_parser_cpp.test test/test_parser.cpp)
target_link_libraries(test_cpp ${PROJECT_NAME})
foreach(LOCALE IN ITEMS C nl_NL.UTF-8)
ament_add_gtest(test_cpp_${LOCALE} test/test_parser.cpp ENV LC_ALL=${LOCALE})
target_link_libraries(test_cpp_${LOCALE} ${PROJECT_NAME})
endforeach()

# ament_lint
find_package(ament_lint_auto REQUIRED)
Expand Down
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<url type="repository">https://github.com/ros-planning/srdfdom</url>

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>ament_cmake_python</buildtool_depend>
<build_depend>libboost-dev</build_depend>
<build_depend>console_bridge_vendor</build_depend>
<build_depend>libconsole-bridge-dev</build_depend>
Expand All @@ -29,6 +30,7 @@
<exec_depend>urdfdom_py</exec_depend>

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_cmake_pytest</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_cmake</test_depend>
<export>
Expand Down
9 changes: 0 additions & 9 deletions setup.py

This file was deleted.

File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions test/srdf_parser.test

This file was deleted.

8 changes: 0 additions & 8 deletions test/srdf_parser_cpp.test

This file was deleted.

26 changes: 11 additions & 15 deletions test/test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#!/usr/bin/env python
#!/usr/bin/env python3
PKG = "srdfdom"

import sys
import rospkg
import os
import unittest
from srdfdom.srdf import SRDF
from xml.dom.minidom import parseString
import xml.dom

try:
string_types = (str, unicode)
except NameError:
string_types = str

# xml match code from test_xacro.py
# by Stuart Glaser and William Woodall

Expand Down Expand Up @@ -91,9 +86,9 @@ def elements_match(a, b):


def xml_matches(a, b):
if isinstance(a, string_types):
if isinstance(a, str):
return xml_matches(parseString(a).documentElement, b)
if isinstance(b, string_types):
if isinstance(b, str):
return xml_matches(a, parseString(b).documentElement)
if a.nodeType == xml.dom.Node.DOCUMENT_NODE:
return xml_matches(a.documentElement, b)
Expand All @@ -102,7 +97,6 @@ def xml_matches(a, b):
if not elements_match(a, b):
print("Match failed:")
a.writexml(sys.stdout)
print
print("=" * 78)
b.writexml(sys.stdout)
return False
Expand Down Expand Up @@ -170,7 +164,7 @@ def test_full_srdf(self):
self.assertTrue(xml_matches(robot.to_xml_string(), expected))

def test_simple_srdf(self):
datadir = rospkg.RosPack().get_path("srdfdom") + "/test/resources/"
datadir = os.path.dirname(os.path.realpath(__file__)) + "/resources/"
stream = open(datadir + "pr2_desc.1.srdf", "r")
robot = SRDF.from_xml_string(stream.read())
stream.close()
Expand All @@ -190,7 +184,7 @@ def test_simple_srdf(self):
self.assertTrue(len(robot.end_effectors) == 0)

def test_complex_srdf(self):
datadir = rospkg.RosPack().get_path("srdfdom") + "/test/resources/"
datadir = os.path.dirname(os.path.realpath(__file__)) + "/resources/"
stream = open(datadir + "pr2_desc.3.srdf", "r")
robot = SRDF.from_xml_string(stream.read())
stream.close()
Expand Down Expand Up @@ -258,6 +252,8 @@ def test_complex_srdf(self):


if __name__ == "__main__":
import rostest

rostest.rosrun(PKG, "srdf_python_parser_test", TestSRDFParser)
suite = unittest.TestSuite()
suite.addTest(TestSRDFParser("test_full_srdf"))
suite.addTest(TestSRDFParser("test_simple_srdf"))
suite.addTest(TestSRDFParser("test_complex_srdf"))
unittest.TextTestRunner(verbosity=2).run(suite)

0 comments on commit dd742a0

Please sign in to comment.