-
Notifications
You must be signed in to change notification settings - Fork 280
/
Copy pathtest_with_mock_workspace.py
132 lines (110 loc) · 5.59 KB
/
test_with_mock_workspace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python
import os
import shutil
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
from test.utils import AbstractCatkinWorkspaceTest # noqa: E402, I202
from test.utils import MAKE_CMD # noqa: E402
from test.utils import MOCK_DIR # noqa: E402
from test.utils import assert_exists # noqa: E402
from test.utils import fail # noqa: E402
from test.utils import succeed # noqa: E402
import em # noqa: E402
class MockTest(AbstractCatkinWorkspaceTest):
"""This test case uses workspaces with catkin projects from the test/mock_resources folder."""
# uncomment to keep temporary files in /tmp
# def tearDown(self):
# pass
def test_catkin_only(self):
self.cmake()
succeed(MAKE_CMD, cwd=self.builddir)
succeed(MAKE_CMD + ['install'], cwd=self.builddir)
assert_exists(self.installdir,
'env.sh',
'setup.sh',
'setup.zsh')
def test_linker_options_propagation(self):
dstdir = os.path.join(self.workspacedir, 'linker_options')
shutil.copytree(os.path.join(MOCK_DIR, 'src', 'linker_options'), dstdir)
self.cmake()
succeed(MAKE_CMD, cwd=self.builddir)
succeed(MAKE_CMD + ['install'], cwd=self.builddir)
assert_exists(self.installdir,
'env.sh',
'setup.sh',
'setup.zsh')
def test_nolang(self):
dstdir = os.path.join(self.workspacedir, 'nolangs')
shutil.copytree(os.path.join(MOCK_DIR, 'src', 'nolangs'), dstdir)
self.cmake(CATKIN_WHITELIST_PACKAGES='nolangs',
CATKIN_DPKG_BUILDPACKAGE_FLAGS='-d;-S;-us;-uc')
self.assertTrue(os.path.exists(self.builddir + '/nolangs'))
self.assertFalse(os.path.exists(self.builddir + '/std_msgs'))
self.assertFalse(os.path.exists(self.builddir + '/genmsg'))
succeed(MAKE_CMD, cwd=self.builddir)
self.assertTrue(os.path.exists(self.builddir +
'/nolangs/bin/nolangs_exec'))
succeed(MAKE_CMD + ['install'], cwd=self.builddir)
assert_exists(self.installdir,
'bin/nolangs_exec',
'share/nolangs/cmake/nolangsConfig.cmake')
# also test make help
succeed(MAKE_CMD + ['help'], cwd=self.builddir)
def test_noproject(self):
# create workspace with just catkin and 'noproject' project
dstdir = os.path.join(self.workspacedir, 'noproject')
shutil.copytree(os.path.join(MOCK_DIR, 'src-fail', 'noproject'), dstdir)
# test with whitelist
out = self.cmake(CATKIN_WHITELIST_PACKAGES='catkin')
out = succeed(MAKE_CMD + ['install'], cwd=self.builddir)
shutil.rmtree(self.builddir)
# fail if we try to build noproject stack
os.makedirs(self.builddir)
out = self.cmake(CMAKE_PREFIX_PATH=self.installdir,
expect=fail)
print('failed as expected, out={}'.format(out))
self.assertTrue(b"catkin_package() PROJECT_NAME is set to 'Project'" in out, out)
# assert 'You must call project() with the same name before.' in out
# Test was not finished apparently
# def test_help_bad_changelog(self):
# self.cmake(CATKIN_ENABLE_DEBBUILDING='TRUE',
# CMAKE_PREFIX_PATH=diskprefix,
# srcdir=os.path.join(MOCK_DIR,
# 'src-fail', 'badly_specified_changelog'),
# CATKIN='YES')
# succeed(MAKE_CMD + ['help'], cwd=self.builddir)
def test_env_cached_static(self):
# hack to fix empy nosetests clash
sys.stdout = em.ProxyFile(sys.stdout)
dstdir = os.path.join(self.workspacedir, 'catkin_test')
shutil.copytree(os.path.join(MOCK_DIR, 'src', 'catkin_test'), dstdir)
template_file = os.path.join(os.path.dirname(__file__), '..', '..', 'cmake', 'em', 'order_packages.cmake.em')
with open(template_file, 'r') as fhand:
template = fhand.read()
gdict = {'CATKIN_DEVEL_PREFIX': '/foo',
'CMAKE_PREFIX_PATH': ['/bar'],
'CATKIN_GLOBAL_LIB_DESTINATION': '/glob-dest/lib',
'CATKIN_GLOBAL_BIN_DESTINATION': '/glob-dest/bin',
'PYTHON_INSTALL_DIR': '/foo/dist-packages'}
result = em.expand(template, gdict,
source_root_dir=self.workspacedir,
whitelisted_packages=None,
blacklisted_packages=None,
underlay_workspaces=None)
self.assertTrue('set(CATKIN_ORDERED_PACKAGES "")' in result, result)
self.assertTrue('set(CATKIN_ORDERED_PACKAGE_PATHS "")' in result, result)
self.assertTrue('set(CATKIN_ORDERED_PACKAGES_IS_META "")' in result, result)
self.assertTrue('set(CATKIN_MESSAGE_GENERATORS' in result, result)
self.assertTrue("""\
list(APPEND CATKIN_ORDERED_PACKAGES "catkin_test")
list(APPEND CATKIN_ORDERED_PACKAGE_PATHS "catkin_test/catkin_test")
list(APPEND CATKIN_ORDERED_PACKAGES_IS_META "True")
list(APPEND CATKIN_ORDERED_PACKAGES_BUILD_TYPE "catkin")""" in result, result)
self.assertTrue("""\
list(APPEND CATKIN_ORDERED_PACKAGES "a")
list(APPEND CATKIN_ORDERED_PACKAGE_PATHS "catkin_test/a")
list(APPEND CATKIN_ORDERED_PACKAGES_IS_META "False")
list(APPEND CATKIN_ORDERED_PACKAGES_BUILD_TYPE "catkin")""" in result, result)
# catkin itself filtered out
self.assertFalse('list(APPEND CATKIN_ORDERED_PACKAGES "catkin"' in result, result)
self.assertEqual(38, len(result.splitlines()))