1# Copyright 2014 Christoph Reiter 2# 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 2 of the License, or 6# (at your option) any later version. 7 8import os 9import subprocess 10 11from quodlibet import util 12 13from tests import TestCase, skipIf 14 15 16QLDATA_DIR = os.path.join(os.path.dirname(util.get_module_dir()), "data") 17 18 19def get_appstream_util_version(): 20 try: 21 result = subprocess.run( 22 ["appstream-util", "--version"], 23 stdout=subprocess.PIPE, 24 stderr=subprocess.STDOUT) 25 data = result.stdout 26 except FileNotFoundError: 27 return (0, 0, 0) 28 29 text = data.decode("utf-8", "replace") 30 return tuple([int(p) for p in text.rsplit()[-1].split(".")]) 31 32 33def is_too_old_appstream_util_version(): 34 return get_appstream_util_version() < (0, 7, 0) 35 36 37class _TAppDataFileMixin(object): 38 PATH = None 39 40 def test_filename(self): 41 self.assertTrue(self.PATH.endswith(".appdata.xml.in")) 42 43 def test_validate(self): 44 try: 45 subprocess.check_output( 46 ["appstream-util", "validate", "--nonet", self.PATH], 47 stderr=subprocess.STDOUT) 48 except subprocess.CalledProcessError as e: 49 raise Exception(e.output) 50 51 52@skipIf(is_too_old_appstream_util_version(), "appstream-util is too old") 53class TQLAppDataFile(TestCase, _TAppDataFileMixin): 54 PATH = os.path.join( 55 QLDATA_DIR, 56 "io.github.quodlibet.QuodLibet.appdata.xml.in") 57 58 59@skipIf(is_too_old_appstream_util_version(), "appstream-util is too old") 60class TEFAppDataFile(TestCase, _TAppDataFileMixin): 61 PATH = os.path.join( 62 QLDATA_DIR, 63 "io.github.quodlibet.ExFalso.appdata.xml.in") 64