Catalog support for minimum-fg-version
Extend test coverage with a minimal aircraft to exercise more code paths for this.
This commit is contained in:
parent
25a9835014
commit
89948603de
6 changed files with 70 additions and 9 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -21,3 +21,4 @@ osgbuild
|
|||
CMakeCache.txt
|
||||
*.pyc
|
||||
build-*
|
||||
testOutput*
|
||||
|
|
|
@ -38,7 +38,11 @@ def scan_set_file(aircraft_dir, set_file, includes):
|
|||
variant = {}
|
||||
variant['name'] = sim_node.getValue("description", None)
|
||||
variant['status'] = sim_node.getValue("status", None)
|
||||
|
||||
if sim_node.hasChild('author'):
|
||||
variant['author'] = sim_node.getValue("author", None)
|
||||
|
||||
if sim_node.hasChild('long-description'):
|
||||
variant['description'] = sim_node.getValue("long-description", None)
|
||||
variant['id'] = base_id
|
||||
|
||||
|
@ -64,6 +68,10 @@ def scan_set_file(aircraft_dir, set_file, includes):
|
|||
variant['thumbnail'] = sim_node.getValue("thumbnail", None)
|
||||
|
||||
variant['variant-of'] = sim_node.getValue("variant-of", None)
|
||||
|
||||
if sim_node.hasChild('minimum-fg-version'):
|
||||
variant['minimum-fg-version'] = sim_node.getValue('minimum-fg-version', None)
|
||||
|
||||
#print ' ', variant
|
||||
return variant
|
||||
|
||||
|
@ -128,6 +136,7 @@ def scan_aircraft_dir(aircraft_dir, includes):
|
|||
|
||||
package = primaryAircraft[0]
|
||||
if not 'thumbnail' in package:
|
||||
if (os.path.exists(os.path.join(aircraft_dir, "thumbnail.jpg"))):
|
||||
package['thumbnail'] = "thumbnail.jpg"
|
||||
|
||||
# variants is just all the set dicts except the first one
|
||||
|
@ -172,8 +181,16 @@ def make_aircraft_node(aircraftDirName, package, variants, downloadBase):
|
|||
package_node = ET.Element('package')
|
||||
package_node.append( make_xml_leaf('name', package['name']) )
|
||||
package_node.append( make_xml_leaf('status', package['status']) )
|
||||
|
||||
if 'author' in package:
|
||||
package_node.append( make_xml_leaf('author', package['author']) )
|
||||
|
||||
if 'description' in package:
|
||||
package_node.append( make_xml_leaf('description', package['description']) )
|
||||
|
||||
if 'minimum-fg-version' in package:
|
||||
package_node.append( make_xml_leaf('minimum-fg-version', package['minimum-fg-version']) )
|
||||
|
||||
if 'rating_FDM' in package or 'rating_systems' in package \
|
||||
or 'rating_cockpit' in package or 'rating_model' in package:
|
||||
rating_node = ET.Element('rating')
|
||||
|
@ -217,9 +234,10 @@ def make_aircraft_node(aircraftDirName, package, variants, downloadBase):
|
|||
package_node.append( make_xml_leaf('dir', aircraftDirName) )
|
||||
|
||||
download_url = downloadBase + aircraftDirName + '.zip'
|
||||
thumbnail_url = downloadBase + 'thumbnails/' + aircraftDirName + '_' + package['thumbnail']
|
||||
|
||||
package_node.append( make_xml_leaf('url', download_url) )
|
||||
|
||||
if 'thumbnail' in package:
|
||||
thumbnail_url = downloadBase + 'thumbnails/' + aircraftDirName + '_' + package['thumbnail']
|
||||
package_node.append( make_xml_leaf('thumbnail', thumbnail_url) )
|
||||
package_node.append( make_xml_leaf('thumbnail-path', package['thumbnail']))
|
||||
|
||||
|
|
8
catalog/testData/Aircraft/c150/c150-set.xml
Normal file
8
catalog/testData/Aircraft/c150/c150-set.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<PropertyList>
|
||||
<sim>
|
||||
<name>c150</name>
|
||||
<description>Cessna 150</description>
|
||||
</sim>
|
||||
|
||||
</PropertyList>
|
|
@ -7,6 +7,7 @@
|
|||
<tag>1980s</tag>
|
||||
<tag>glass-cockpit</tag>
|
||||
</tags>
|
||||
<minimum-fg-version>2017.4</minimum-fg-version>
|
||||
</sim>
|
||||
|
||||
</PropertyList>
|
||||
|
|
0
catalog/testData/Aircraft/f16/thumbnail.jpg
Normal file
0
catalog/testData/Aircraft/f16/thumbnail.jpg
Normal file
|
@ -17,6 +17,7 @@ class UpdateCatalogTests(unittest.TestCase):
|
|||
self.assertEqual(info['rating_FDM'], 3)
|
||||
self.assertEqual(info['rating_model'], 5)
|
||||
self.assertEqual(len(info['tags']), 3)
|
||||
self.assertEqual(info['minimum-fg-version'], '2017.4')
|
||||
|
||||
def test_scan_dir(self):
|
||||
(pkg, variants) = catalog.scan_aircraft_dir("testData/Aircraft/f16", ["testData/OtherDir"])
|
||||
|
@ -25,6 +26,7 @@ class UpdateCatalogTests(unittest.TestCase):
|
|||
f16trainer = next(v for v in variants if v['id'] == 'f16-trainer')
|
||||
self.assertEqual(pkg['author'], 'Wilbur Wright')
|
||||
self.assertEqual(len(variants), 3)
|
||||
self.assertEqual(pkg['minimum-fg-version'], '2017.4')
|
||||
|
||||
# test variant relatonship between
|
||||
self.assertEqual(pkg['variant-of'], None)
|
||||
|
@ -90,6 +92,8 @@ class UpdateCatalogTests(unittest.TestCase):
|
|||
self.assertEqual(parsedPkgNode.getValue('description'), pkg['description']);
|
||||
self.assertEqual(parsedPkgNode.getValue('author'), "Wilbur Wright");
|
||||
|
||||
self.assertEqual(parsedPkgNode.getValue('minimum-fg-version'), "2017.4");
|
||||
|
||||
parsedVariants = parsedPkgNode.getChildren("variant")
|
||||
self.assertEqual(len(parsedVariants), 3)
|
||||
|
||||
|
@ -109,8 +113,37 @@ class UpdateCatalogTests(unittest.TestCase):
|
|||
self.assertEqual(pv.getValue('description'), 'The F16-B is an upgraded version of the F16A.')
|
||||
self.assertEqual(pv.getValue('author'), "James T Kirk");
|
||||
|
||||
def test_minimalAircraft(self):
|
||||
# test an aircraft with a deliberately spartan -set.xml file with
|
||||
# most interesting data missing
|
||||
(pkg, variants) = catalog.scan_aircraft_dir("testData/Aircraft/c150", ["testData/OtherDir"])
|
||||
|
||||
catalog_node = ET.Element('PropertyList')
|
||||
catalog_root = ET.ElementTree(catalog_node)
|
||||
|
||||
pkgNode = catalog.make_aircraft_node('c150', pkg, variants, "http://foo.com/testOutput/")
|
||||
catalog_node.append(pkgNode)
|
||||
|
||||
if not os.path.isdir("testOutput2"):
|
||||
os.mkdir("testOutput2")
|
||||
|
||||
cat_file = os.path.join("testOutput2", 'catalog_fragment.xml')
|
||||
catalog_root.write(cat_file, encoding='utf-8', xml_declaration=True, pretty_print=True)
|
||||
|
||||
parsed = sgprops.readProps(cat_file)
|
||||
parsedPkgNode = parsed.getChild("package")
|
||||
|
||||
self.assertEqual(parsedPkgNode.getValue('id'), pkg['id'])
|
||||
self.assertEqual(parsedPkgNode.getValue('dir'), 'c150')
|
||||
self.assertEqual(parsedPkgNode.getValue('url'), 'http://foo.com/testOutput/c150.zip')
|
||||
self.assertFalse(parsedPkgNode.hasChild('thumbnail'))
|
||||
self.assertFalse(parsedPkgNode.hasChild('thumbnail-path'));
|
||||
|
||||
self.assertEqual(parsedPkgNode.getValue('name'), pkg['name']);
|
||||
self.assertFalse(parsedPkgNode.hasChild('description'));
|
||||
self.assertFalse(parsedPkgNode.hasChild('author'));
|
||||
self.assertFalse(parsedPkgNode.hasChild('minimum-fg-version'));
|
||||
self.assertFalse(parsedPkgNode.hasChild('variant'));
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in a new issue