8028ce2888
- Move test_catalog.py, test_sgprops.py and catalog/testData/ to python3-flightgear/flightgear/meta/tests/. - Copy catalog/fgaddon-catalog/ to the same place (it is needed by test_catalog.py). - Adapt test_catalog.py and test_sgprops.py accordingly. - Remove the executable bits from test_catalog.py and test_sgprops.py: this is because test_catalog.py can't be run directly anymore; well, it can but 3 tests would fail in this setup. No time to investigate why (sorry), but this commit adds a README.txt in python3-flightgear/flightgear/meta/tests/README.txt that explains how to run the tests in a way that works (basically, run 'python3 -m unittest' from the python3-flightgear directory). For a bit more context, see <https://sourceforge.net/p/flightgear/mailman/message/37042247/>.
70 lines
2 KiB
Python
70 lines
2 KiB
Python
#! /usr/bin/env python3
|
|
|
|
import os
|
|
import unittest
|
|
|
|
from flightgear.meta import sgprops
|
|
|
|
|
|
baseDir = os.path.dirname(__file__)
|
|
|
|
def testData(*args):
|
|
return os.path.join(baseDir, "testData", *args)
|
|
|
|
|
|
class SGProps(unittest.TestCase):
|
|
|
|
def test_parse(self):
|
|
parsed = sgprops.readProps(testData("props1.xml"))
|
|
|
|
self.assertEqual(parsed.getValue("value"), 42)
|
|
self.assertEqual(type(parsed.getValue("value")), int)
|
|
|
|
valNode = parsed.getChild("value")
|
|
self.assertEqual(valNode.parent, parsed)
|
|
self.assertEqual(valNode.name, "value")
|
|
|
|
self.assertEqual(valNode.value, 42)
|
|
self.assertEqual(type(valNode.value), int)
|
|
|
|
with self.assertRaises(IndexError):
|
|
missingNode = parsed.getChild("missing")
|
|
|
|
things = parsed.getChildren("thing")
|
|
self.assertEqual(len(things), 3)
|
|
|
|
self.assertEqual(things[0], parsed.getChild("thing", 0));
|
|
self.assertEqual(things[1], parsed.getChild("thing", 1));
|
|
self.assertEqual(things[2], parsed.getChild("thing", 2));
|
|
|
|
self.assertEqual(things[0].getValue("value"), "apple");
|
|
self.assertEqual(things[1].getValue("value"), "lemon");
|
|
self.assertEqual(things[2].getValue("value"), "pear");
|
|
|
|
def test_create(self):
|
|
pass
|
|
|
|
|
|
def test_invalidIndex(self):
|
|
with self.assertRaises(IndexError):
|
|
parsed = sgprops.readProps(testData("bad-index.xml"))
|
|
|
|
def test_include(self):
|
|
parsed = sgprops.readProps(testData("props2.xml"))
|
|
|
|
# test that value in main file over-rides the one in the include
|
|
self.assertEqual(parsed.getValue("value"), 33)
|
|
|
|
# but these come from the included file
|
|
self.assertEqual(parsed.getValue("value[1]"), 43)
|
|
self.assertEqual(parsed.getValue("value[2]"), 44)
|
|
|
|
subNode = parsed.getChild("sub")
|
|
widgets = subNode.getChildren("widget")
|
|
self.assertEqual(len(widgets), 4)
|
|
|
|
self.assertEqual(widgets[2].value, 44)
|
|
self.assertEqual(widgets[3].value, 99)
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|