File: test_appdata_files.py

package info (click to toggle)
quodlibet 4.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,228 kB
  • sloc: python: 89,728; sh: 381; xml: 110; makefile: 91
file content (63 lines) | stat: -rw-r--r-- 1,826 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Copyright 2014 Christoph Reiter
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

import os
import subprocess
import functools

from quodlibet import util

from tests import TestCase, skipIf


QLDATA_DIR = os.path.join(os.path.dirname(util.get_module_dir()), "data")


@functools.lru_cache
def get_appstream_cli_version():
    try:
        result = subprocess.run(
            ["appstreamcli", "--version"],
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
        )
        data = result.stdout
    except FileNotFoundError:
        return (0, 0, 0)

    text = data.decode("utf-8", "replace")
    return tuple([int(p) for p in text.rsplit()[-1].split(".")])


def is_too_old_appstream_cli_version():
    return get_appstream_cli_version() < (0, 12, 0)


class _TAppDataFileMixin:
    PATH = None

    def test_filename(self):
        assert self.PATH.endswith(".appdata.xml.in")

    def test_validate(self):
        try:
            subprocess.check_output(
                ["appstreamcli", "validate", "--no-net", self.PATH],
                stderr=subprocess.STDOUT,
            )
        except subprocess.CalledProcessError as e:
            raise Exception(e.output) from e


@skipIf(is_too_old_appstream_cli_version(), "appstreamcli is too old")
class TQLAppDataFile(TestCase, _TAppDataFileMixin):
    PATH = os.path.join(QLDATA_DIR, "io.github.quodlibet.QuodLibet.appdata.xml.in")


@skipIf(is_too_old_appstream_cli_version(), "appstreamcli is too old")
class TEFAppDataFile(TestCase, _TAppDataFileMixin):
    PATH = os.path.join(QLDATA_DIR, "io.github.quodlibet.ExFalso.appdata.xml.in")