data: add a test for the svg lookup ini file

Checks for required keys, that the SVG files actually exist and that
we don't have duplicate device matches.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2019-07-30 21:04:50 +10:00
parent 20b45f6bbf
commit 482f911ddb
2 changed files with 67 additions and 0 deletions

View File

@@ -77,6 +77,14 @@ test('check-svg', test_svg_files,
args: svgs,
env: ['BASEDIR=@0@'.format(meson.current_source_dir())])
test('svg-lookup-check',
find_program('svg-lookup-ini-test.py'),
args: [
svg_mapping,
join_paths(meson.source_root(), 'data/svgs/')
],
)
gresource = configure_file(input: 'piper.gresource.xml.in',
output: 'piper.gresource.xml',
command: ['generate-piper-gresource.xml.py',

59
data/svg-lookup-ini-test.py Executable file
View File

@@ -0,0 +1,59 @@
#!/usr/bin/env python3
import argparse
import configparser
import unittest
import sys
from pathlib import Path
path = None
svgdir = None
config = None
class TestSVGLookup(unittest.TestCase):
def test_has_sections(self):
self.assertTrue(config.sections())
def test_required(self):
for name in config.sections():
s = config[name]
self.assertIn('DeviceMatch', s)
self.assertIn('Svg', s)
def test_svg_filename(self):
svgs = [config[s]['Svg'] for s in config.sections()]
for svg in svgs:
self.assertTrue(Path(svgdir, svg).exists(), msg=svg)
def test_uniq_match(self):
matches = [config[s]['DeviceMatch'] for s in config.sections()]
d = {}
for match in matches:
self.assertNotIn(match, d, msg='Duplicate match "{}"'.format(match))
d[match] = True
def setUpModule():
global config, path
config = configparser.ConfigParser(strict=True)
config.optionxform = lambda option: option
config.read(path)
assert(config.sections())
def main():
global path, svgdir
parser = argparse.ArgumentParser(description="Device data-file checker")
parser.add_argument('file', nargs=1, help='Absolute path to svg-lookup.ini')
parser.add_argument('svgdir', nargs=1, help='Directory containing svg files')
args, remainder = parser.parse_known_args()
path = args.file[0]
svgdir = args.svgdir[0]
unittest.main(argv=[sys.argv[0], *remainder])
if __name__ == "__main__":
main()