From 482f911ddb59bca2bc5e6947fc21452bba01c9ef Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 30 Jul 2019 21:04:50 +1000 Subject: [PATCH] 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 --- data/meson.build | 8 +++++ data/svg-lookup-ini-test.py | 59 +++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100755 data/svg-lookup-ini-test.py diff --git a/data/meson.build b/data/meson.build index fd9d91a..6a95dbf 100644 --- a/data/meson.build +++ b/data/meson.build @@ -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', diff --git a/data/svg-lookup-ini-test.py b/data/svg-lookup-ini-test.py new file mode 100755 index 0000000..71b8fed --- /dev/null +++ b/data/svg-lookup-ini-test.py @@ -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()