Skip to content

Commit

Permalink
Fix issue #641: Python methods FGFDMExec.query_property_catalog() a…
Browse files Browse the repository at this point in the history
…nd `FGFDMExec.get_property_catalog()` now behave like their C++ counterpart.
  • Loading branch information
bcoconni committed Jun 12, 2022
1 parent bbb09c9 commit 880d092
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
18 changes: 5 additions & 13 deletions python/jsbsim.pyx.in
Original file line number Diff line number Diff line change
Expand Up @@ -523,19 +523,11 @@ cdef class FGFDMExec(FGJSBBase):

def query_property_catalog(self, check):
"""@Dox(JSBSim::FGFDMExec::QueryPropertyCatalog)"""
catalog = (self.thisptr.QueryPropertyCatalog(check.encode())).decode('utf-8').rstrip().split('\n')
if len(catalog) == 1 and catalog[0] == "No matches found":
return []
else:
return catalog

def get_property_catalog(self, check):
"""Retrieves the property catalog as a dictionary."""
catalog = {}
for item in self.query_property_catalog(check):
property_name = item.split(" ")[0] # remove any (RW) flags
catalog[property_name] = self.get_property_value(property_name)
return catalog
return (self.thisptr.QueryPropertyCatalog(check.encode())).decode('utf-8')

def get_property_catalog(self):
"""Retrieves the property catalog as a list."""
return self.query_property_catalog('').rstrip().split('\n')

def print_property_catalog(self):
"""@Dox(JSBSim::FGFDMExec::PrintPropertyCatalog)"""
Expand Down
17 changes: 8 additions & 9 deletions tests/TestMiscellaneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ def test_property_catalog(self):
fdm.run_ic()

catalog = fdm.query_property_catalog('geod-deg')
self.assertEqual(len(catalog), 2)
self.assertEqual(catalog[0], 'position/lat-geod-deg (R)')
self.assertEqual(catalog[1], 'ic/lat-geod-deg (RW)')

values = fdm.get_property_catalog('geod-deg')
item = 'position/lat-geod-deg'
self.assertEqual(values[item], fdm[item])
item = 'ic/lat-geod-deg'
self.assertEqual(values[item], fdm[item])
self.assertIsInstance(catalog, str)
self.assertEqual(catalog, 'position/lat-geod-deg (R)\nic/lat-geod-deg (RW)\n')

catalog = fdm.get_property_catalog()
self.assertIsInstance(catalog, list)
self.assertGreater(len(catalog), 2)
self.assertIn('position/lat-geod-deg (R)', catalog)
self.assertIn('ic/lat-geod-deg (RW)', catalog)

def test_FG_reset(self):
# This test reproduces how FlightGear resets. The important thing is
Expand Down

0 comments on commit 880d092

Please sign in to comment.