Skip to content

Commit 6413e09

Browse files
committed
Fix metadata test.
1 parent ef9de96 commit 6413e09

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

pdal/plang/Environment.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,21 @@ void addMetadata(PyObject *dict, MetadataNode m)
299299
if (type.empty())
300300
type = Metadata::inferType(value);
301301

302-
m = m.addWithType(name, value, type, description);
302+
m.addWithType(name, value, type, description);
303303
PyObject *submeta = PyDict_GetItemString(dict, "children");
304304
if (submeta)
305305
{
306306
if (!PyList_Check(submeta))
307307
throw pdal::pdal_error("Ouput metadata 'children' must be a list.");
308-
for (Py_ssize_t i = 0; i < PyList_Size(submeta); ++i)
308+
Py_ssize_t size = PyList_Size(submeta);
309+
if (size)
309310
{
310-
PyObject* p = PyList_GetItem(submeta, i);
311-
addMetadata(p, m);
311+
m = m.add("children");
312+
for (Py_ssize_t i = 0; i < PyList_Size(submeta); ++i)
313+
{
314+
PyObject* p = PyList_GetItem(submeta, i);
315+
addMetadata(p, m);
316+
}
312317
}
313318
}
314319
}

pdal/test/PythonFilterTest.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ TEST_F(PythonFilterTest, metadata)
223223
"import sys\n"
224224
"import redirector\n"
225225
"def myfunc(ins,outs):\n"
226-
" global metadata\n"
226+
" global out_metadata\n"
227227
" #print('before', globals(), file=sys.stderr,)\n"
228228
" out_metadata = {'name': 'root', 'value': 'a string', 'type': 'string', 'description': 'a description', 'children': [{'name': 'somechildren', 'value': 52, 'type': 'integer', 'description': 'a filter description', 'children': []}, {'name': 'otherchildren', 'value': 'another string', 'type': 'string', 'description': 'a reader description', 'children': []}]}\n"
229229
" # print ('schema', schema, file=sys.stderr,)\n"
@@ -248,13 +248,13 @@ TEST_F(PythonFilterTest, metadata)
248248

249249
PointLayoutPtr layout(table.layout());
250250
MetadataNode m = table.metadata();
251-
m = m.findChild("somechildren");
252-
Utils::toJSON(m, std::cerr);
251+
m = m.findChild("filters.python");
253252
MetadataNodeList l = m.children();
254-
EXPECT_EQ(l.size(), 3u);
255-
EXPECT_EQ(l[0].name(), "filters.python");
256-
EXPECT_EQ(l[0].value(), "52");
257-
EXPECT_EQ(l[0].description(), "a filter description");
253+
EXPECT_EQ(l.size(), 2u);
254+
m = m.findChild("children");
255+
EXPECT_EQ(m.children().size(), 2u);
256+
m = m.findChild("somechildren");
257+
EXPECT_EQ(m.value(), "52");
258258
}
259259

260260
TEST_F(PythonFilterTest, pdalargs)

0 commit comments

Comments
 (0)