File: test_items.py

package info (click to toggle)
gftools 0.9.991%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,568 kB
  • sloc: python: 15,959; sh: 33; makefile: 6
file content (105 lines) | stat: -rw-r--r-- 4,065 bytes parent folder | download | duplicates (2)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import pytest
import os
from pathlib import Path

from gftools.push.items import Family, FamilyMeta, Designer, Axis, AxisFallback
from importlib.resources import files, as_file
import json
import atexit
from contextlib import ExitStack

file_manager = ExitStack()
atexit.register(file_manager.close)


CWD = os.path.dirname(__file__)
TEST_DIR = os.path.join(CWD, "..", "..", "data", "test", "gf_fonts")
SERVER_DIR = os.path.join(CWD, "..", "..", "data", "test", "servers")
TEST_FAMILY_DIR = Path(TEST_DIR) / "ofl" / "mavenpro"
DESIGNER_DIR = Path(TEST_DIR) / "joeprince"
WEIGHT_AXIS = file_manager.enter_context(
    as_file(files("axisregistry") / "data" / "weight.textproto")
)
FAMILY_JSON = json.load(open(os.path.join(SERVER_DIR, "family.json"), encoding="utf8"))
FONTS_JSON = json.load(open(os.path.join(SERVER_DIR, "fonts.json"), encoding="utf8"))


@pytest.mark.parametrize(
    "type_, fp, gf_data, res",
    [
        (
            Family,
            TEST_FAMILY_DIR,
            next(
                f
                for f in FONTS_JSON["familyMetadataList"]
                if f["family"] == "Maven Pro"
            ),
            Family(
                name="Maven Pro",
                version="Version 2.103",
            ),
        ),
        (
            FamilyMeta,
            TEST_FAMILY_DIR,
            FAMILY_JSON,
            FamilyMeta(
                name="Maven Pro",
                designer=["Joe Prince"],
                license="ofl",
                category="SANS_SERIF",
                subsets=["latin", "latin-ext", "vietnamese"],
                stroke="SANS_SERIF",
                classifications=[],
                description="Maven Pro is a sans-serif typeface with unique "
                "curvature and flowing rhythm. Its forms make it very "
                "distinguishable and legible when in context. It blends "
                "styles of many great typefaces and is suitable for any "
                "design medium. Maven Pro’s modern design is great for "
                "the web and fits in any environment. Updated in "
                'January 2019 with a Variable Font "Weight" axis. The '
                "Maven Pro project was initiated by Joe Price, a type "
                "designer based in the USA. To contribute, see "
                "github.com/googlefonts/mavenproFont",
                primary_script=None,
                article=None,
                minisite_url=None,
            ),
        ),
        (
            Designer,
            DESIGNER_DIR,
            FAMILY_JSON["designers"][0],
            Designer(name="Joe Prince", bio=None),
        ),
        (
            Axis,
            WEIGHT_AXIS,
            next(a for a in FONTS_JSON["axisRegistry"] if a["tag"] == "wght"),
            Axis(
                tag="wght",
                display_name="Weight",
                min_value=1.0,
                default_value=400.0,
                max_value=1000.0,
                precision=0,
                fallback=[
                    AxisFallback(name="Thin", value=100.0),
                    AxisFallback(name="ExtraLight", value=200.0),
                    AxisFallback(name="Light", value=300.0),
                    AxisFallback(name="Regular", value=400.0),
                    AxisFallback(name="Medium", value=500.0),
                    AxisFallback(name="SemiBold", value=600.0),
                    AxisFallback(name="Bold", value=700.0),
                    AxisFallback(name="ExtraBold", value=800.0),
                    AxisFallback(name="Black", value=900.0),
                ],
                fallback_only=False,
                description="Adjust the style from lighter to bolder in typographic color, by varying stroke weights, spacing and kerning, and other aspects of the type. This typically changes overall width, and so may be used in conjunction with Width and Grade axes.",
            ),
        ),
    ],
)
def test_item_from_fp_and_gf_data(type_, fp, gf_data, res):
    assert type_.from_fp(fp) == type_.from_gf_json(gf_data) == res