MTGProxyPrinter

Changes On Branch test_resources
Login

Changes On Branch test_resources

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch test_resources Excluding Merge-Ins

This is equivalent to a diff from 9078e65f80 to b71a681306

2022-04-04
16:34
Add tests to validate the content of mtg_proxy_printer/resources/resources.qrc check-in: 88e51d7771 user: thomas tags: trunk
14:25
Benchmark script: Add method CardInfoDownloadWorker._parse_single_printing() to the measured functions. check-in: cecb6c6160 user: thomas tags: trunk
13:42
Test the resource file registry resources.qrc. Implements [cd3d553b7abf099d]. Closed-Leaf check-in: b71a681306 user: thomas tags: test_resources
2022-04-03
18:43
Release v0.15.0 check-in: 9078e65f80 user: thomas tags: trunk, release, v0.15.0
17:19
The DeckImportWizard now has button icons on Windows. The FinishRole button icon and tooltip is updated, depending whether the user wants to replace the document or append the deck list. The oversized card warning takes precedence over this. Added changelog entries. check-in: b9c0942530 user: thomas tags: trunk

Added tests/test_resources.py.




































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
64
65
66
# Copyright (C) 2022 Thomas Hess <thomas.hess@udo.edu>

# 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 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import xml.etree.ElementTree
import os
import typing
from pathlib import Path


from hamcrest import *
import pytest

def list_dir(directory: Path) -> typing.Iterable[Path]:
    walker = os.walk(directory)
    for subdir, _, files in walker:
        for file_name in files:
            yield Path(os.path.relpath(subdir, directory), file_name)


@pytest.fixture()
def resource_path() -> Path:
    import mtg_proxy_printer.resources
    directory = Path(mtg_proxy_printer.resources.__path__._path[0])
    qrc_file = directory / "resources.qrc"
    return qrc_file




def test_all_resources_listed_in_resources_qrc_exist_as_files(resource_path: Path):
    resource_document = xml.etree.ElementTree.ElementTree(file=resource_path)
    file_nodes = resource_document.findall("qresource/file")
    base_dir = resource_path.parent
    for node in file_nodes:
        assert_that((base_dir/node.text).exists(), reason="Listed entry does not exist")
        assert_that((base_dir/node.text).is_file(), reason="Listed entry not a regular file")


def test_no_duplicates_in_resources_qrc(resource_path: Path):
    resource_document = xml.etree.ElementTree.ElementTree(file=resource_path)
    listed_paths = list(node.text for node in resource_document.findall("qresource/file"))
    deduplicated = set(listed_paths)
    assert_that(listed_paths, has_length(len(deduplicated)), "resources.qrc contains unexpected duplicates")


def test_all_resource_files_are_listed_in_resources_qrc(resource_path: Path):
    base_dir = resource_path.parent
    resource_document = xml.etree.ElementTree.ElementTree(file=resource_path)
    listed_paths = set(Path(node.text) for node in resource_document.findall("qresource/file"))
    existing_files = list_dir(base_dir)
    for file in existing_files:
        if file.name == "resources.qrc":
            continue
        assert_that(file, is_in(listed_paths), "File not listed in resources.qrc")