File: test_qtawesome.py

package info (click to toggle)
python-qtawesome 1.2.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,892 kB
  • sloc: python: 1,435; makefile: 177; sh: 14
file content (78 lines) | stat: -rw-r--r-- 2,571 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
r"""
Tests for QtAwesome.
"""
# Standard library imports
import collections
import os
import subprocess
import sys

# Test Library imports
import pytest

# Local imports
from qtawesome.iconic_font import IconicFont
import qtawesome as qta


def test_segfault_import():
    output_number = subprocess.call(sys.executable + ' -c "import qtawesome '
                                    '; qtawesome.icon()"', shell=True)
    assert output_number == 0


def test_unique_font_family_name(qtbot):
    """
    Test that each font used by qtawesome has a unique name. If this test
    fails, this probably means that you need to rename the family name of
    some fonts. Please see PR #98 for more details on why it is necessary and
    on how to do this.

    Regression test for Issue #107
    """
    resource = qta._instance()
    assert isinstance(resource, IconicFont)

    # Check that the fonts were loaded successfully.
    fontnames = resource.fontname.values()
    assert fontnames

    # Check that qtawesome does not load fonts with duplicate family names.
    duplicates = [fontname for fontname, count in
                  collections.Counter(fontnames).items() if count > 1]
    assert not duplicates


@pytest.mark.skipif(os.name != "nt", reason="Only meant for Windows")
def test_bundled_font_installation():
    """
    Test that the bundled fonts are being installed on Windows.
    
    See spyder-ide/qtawesome#167 and spyder-ide/spyder#18642
    """
    qta._instance()
    fonts_expected = [
        ("codicon", "codicon.ttf"),
        ("elusiveicons-webfont", "elusiveicons-webfont.ttf"),
        ("fontawesome4.7-webfont", "fontawesome4.7-webfont.ttf"),
        ("fontawesome5-brands-webfont", "fontawesome5-brands-webfont.ttf"),
        ("fontawesome5-regular-webfont", "fontawesome5-regular-webfont.ttf"),
        ("fontawesome5-solid-webfont", "fontawesome5-solid-webfont.ttf"),
        ("materialdesignicons5-webfont", "materialdesignicons5-webfont.ttf"),
        ("materialdesignicons6-webfont ", "materialdesignicons6-webfont.ttf"),
        ("phosphor", "phosphor.ttf"),
        ("remixicon", "remixicon.ttf")
    ]
    fonts_command = [
        "powershell.exe",
        r'Get-ItemProperty "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"'
    ]
    fonts_result = subprocess.run(fonts_command, capture_output=True, check=True, text=True).stdout
    
    for font_name, font_filename in fonts_expected:
        assert font_name in fonts_result
        assert font_filename in fonts_result


if __name__ == "__main__":
    pytest.main()