Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Remove dependency on Manim for tests
Disable tests which are not supported
  • Loading branch information
naveen521kk committed Jun 2, 2021
1 parent 94d730a commit 2d89912
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 351 deletions.
4 changes: 4 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ def delete_media_dir():
delete_media_dir()
CASES_DIR = Path(Path(__file__).parent, "cases").absolute()
FONT_DIR = Path(__file__).parent / "fonts"

# avoid fail due to env vars.
os.environ["PANGOCAIRO_BACKEND"] = ""
os.environ["FONTCONFIG_PATH"] = ""
219 changes: 0 additions & 219 deletions tests/_manim.py

This file was deleted.

20 changes: 20 additions & 0 deletions tests/test_font_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from manimpango import FontProperties


def test_init():
FontProperties()


def test_family_property():
desc = FontProperties()
assert desc.family is None
desc.family = "Roboto"
assert desc.family == "Roboto"


def test_size_property():
desc = FontProperties()
assert desc.size is None
desc.size = 20
assert desc.size == 20
88 changes: 88 additions & 0 deletions tests/test_font_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# -*- coding: utf-8 -*-
import sys
from pathlib import Path

import pytest
from attr.exceptions import FrozenInstanceError

from manimpango import FontProperties, RegisterFont, Style, Variant, Weight, list_fonts

from .test_fonts import font_lists


def test_invalid_size():
with pytest.raises(ValueError):
FontProperties(size=0)


def test_font_properties_attributes():
fp = FontProperties(
family="Hello",
size=10,
style=Style.ITALIC,
variant=Variant.NORMAL,
weight=Weight.BOLD,
)
assert fp.family == "Hello"
assert fp.size == 10
assert fp.style == Style.ITALIC
assert fp.variant == Variant.NORMAL
assert fp.weight == Weight.BOLD


def test_Register_Font_wrapper_frozen():
a = RegisterFont(list(font_lists.keys())[0])
with pytest.raises(FrozenInstanceError):
a.family = ""
a.unregister()


def test_Register_Font():
a = RegisterFont(list(font_lists.keys())[1])
fonts = list_fonts()
assert a.family[0] in fonts
assert isinstance(a.family, list)
a.unregister()
# below one fails due to caching in Pango.
# Maybe we can disable it?
# assert a.family[0] not in fonts


@pytest.mark.skipif(sys.platform.startswith("linux"), reason="uses fc by default.")
def test_fc_in_Register_Font():
a = RegisterFont(list(font_lists.keys())[1], use_fontconfig=True)
fonts = list_fonts()
assert a.family is not None
assert list(font_lists.values())[1] not in fonts
assert a.family[0] not in fonts
a.unregister()


def test_fc_in_Register_Font_with_rendering(setup_fontconfig):
a = RegisterFont(list(font_lists.keys())[1], use_fontconfig=True)
fonts = list_fonts()
assert a.family is not None
assert a.family[0] in fonts
a.unregister()


def test_Register_Font_without_calculating_family():
a = RegisterFont(list(font_lists.keys())[1], calculate_family=False)
assert a.family is None
a.unregister()


@pytest.mark.parametrize("fontconfig", [True, False])
def test_Register_Font_invalid_font_raise(tmpdir, fontconfig):
tmpfile = Path(tmpdir) / "nice.ttf"
with tmpfile.open("w") as f:
f.write("test font")
with pytest.raises(RuntimeError):
RegisterFont(tmpfile, use_fontconfig=fontconfig)


def test_Register_Font_file_not_found(tmpdir):
with pytest.raises(FileNotFoundError):
RegisterFont(Path(tmpdir) / "test")
with pytest.raises(FileNotFoundError):
RegisterFont(Path(tmpdir))
Loading

0 comments on commit 2d89912

Please sign in to comment.