From 935c37f2083e748f612caeaec6e0258362249119 Mon Sep 17 00:00:00 2001 From: Kay Jan Date: Tue, 26 Sep 2023 10:29:20 +0800 Subject: [PATCH 1/6] Added: Test cases for groot --- tests/utils/test_groot.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/utils/test_groot.py diff --git a/tests/utils/test_groot.py b/tests/utils/test_groot.py new file mode 100644 index 00000000..09229f35 --- /dev/null +++ b/tests/utils/test_groot.py @@ -0,0 +1,15 @@ +import pytest + +from bigtree.utils.groot import speak_like_groot, whoami + + +def test_whoami(): + assert whoami() == "I am Groot!" + + +@pytest.mark.parametrize( + ["sentence", "expected_output"], + [("Hi!", "I am Groot!"), ("Hi there!", "I am Groot! I am Groot!")], +) +def test_speak_like_groot(sentence, expected_output): + assert speak_like_groot(sentence) == expected_output From 453b6c999504417da80867ca1b0f4f312a93204f Mon Sep 17 00:00:00 2001 From: Kay Jan Date: Tue, 26 Sep 2023 10:30:03 +0800 Subject: [PATCH 2/6] v0.12.5 --- bigtree/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bigtree/__init__.py b/bigtree/__init__.py index 26902c1e..800e68b9 100644 --- a/bigtree/__init__.py +++ b/bigtree/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.12.4" +__version__ = "0.12.5" from bigtree.binarytree.construct import list_to_binarytree from bigtree.dag.construct import dataframe_to_dag, dict_to_dag, list_to_dag From 4d42b2f4076ad6d1db4ff71727aab252c2269aa8 Mon Sep 17 00:00:00 2001 From: Kay Jan Date: Tue, 26 Sep 2023 11:06:30 +0800 Subject: [PATCH 3/6] Fixed: Font family to point to online file instead of relative path --- bigtree/tree/export.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bigtree/tree/export.py b/bigtree/tree/export.py index 366cce11..796884ef 100644 --- a/bigtree/tree/export.py +++ b/bigtree/tree/export.py @@ -2,6 +2,7 @@ import collections from typing import Any, Dict, Iterable, List, Optional, Tuple, TypeVar, Union +from urllib.request import urlopen from bigtree.node.node import Node from bigtree.tree.search import find_path @@ -772,7 +773,7 @@ def tree_to_pillow( width: int = 0, height: int = 0, start_pos: Tuple[int, int] = (10, 10), - font_family: str = "assets/DejaVuSans.ttf", + font_family: str = "", font_size: int = 12, font_colour: Union[Tuple[int, int, int], str] = "black", bg_colour: Union[Tuple[int, int, int], str] = "white", @@ -808,7 +809,15 @@ def tree_to_pillow( (PIL.Image.Image) """ # Initialize font - font = ImageFont.truetype(font_family, font_size) + if not font_family: + dejavusans_url = "https://github.com/kayjan/bigtree/raw/master/assets/DejaVuSans.ttf?raw=true" + font_family = urlopen(dejavusans_url) + try: + font = ImageFont.truetype(font_family, font_size) + except OSError: + raise ValueError( + f"Font file {font_family} is not found, set `font_family` parameter to point to a valid .ttf file." + ) # Initialize text image_text = [] From 9e525a5f01a002f0e23f00e81a89aaca0e7f7484 Mon Sep 17 00:00:00 2001 From: Kay Jan Date: Tue, 26 Sep 2023 11:08:10 +0800 Subject: [PATCH 4/6] Added: Test for font family --- tests/constants.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/constants.py b/tests/constants.py index fd376cc8..2801a395 100644 --- a/tests/constants.py +++ b/tests/constants.py @@ -144,6 +144,7 @@ class Constants: ERROR_NODE_EXPORT_PRINT_INVALID_PATH = ( "Node name or path {node_name_or_path} not found" ) + ERROR_NODE_EXPORT_PILLOW_FONT_FAMILY = "Font file {font_family} is not found, set `font_family` parameter to point to a valid .ttf file." ERROR_NODE_EXPORT_PRINT_INVALID_STYLE = "Choose one of " From f7dc3bbaaf322a5b6304efb4130688bd64b149df Mon Sep 17 00:00:00 2001 From: Kay Jan Date: Tue, 26 Sep 2023 11:12:18 +0800 Subject: [PATCH 5/6] Added: Test for font family --- tests/tree/test_export.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/tree/test_export.py b/tests/tree/test_export.py index dc6094ab..b8a1cfd5 100644 --- a/tests/tree/test_export.py +++ b/tests/tree/test_export.py @@ -979,3 +979,14 @@ def test_tree_to_pillow_kwargs(tree_node): pillow_image = tree_to_pillow(tree_node, max_depth=2, style="const_bold") if LOCAL: pillow_image.save("tests/tree_pillow_style.png") + + @staticmethod + def test_tree_to_pillow_font_family(tree_node): + font_family = "invalid.ttf" + with pytest.raises(ValueError) as exc_info: + tree_to_pillow(tree_node, font_family=font_family) + assert str( + exc_info.value + ) == Constants.ERROR_NODE_EXPORT_PILLOW_FONT_FAMILY.format( + font_family=font_family + ) From 4d5db8971441c41ecb6dbed33e157b5d6d47377a Mon Sep 17 00:00:00 2001 From: Kay Jan Date: Tue, 26 Sep 2023 11:14:53 +0800 Subject: [PATCH 6/6] Changed: Update CHANGELOG --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6f0a8f9..f83aa8ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.12.5] - 2023-09-26 +### Added +- Utility Groot: Add test cases. +### Fixed +- Tree Exporter: `tree_to_pillow` function to reference online font file instead of relative path. + ## [0.12.4] - 2023-09-25 ### Added - Utility Groot: Add groot utility functions. @@ -327,6 +333,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Utility Iterator: Tree traversal methods. - Workflow To Do App: Tree use case with to-do list implementation. +[0.12.5]: https://github.com/kayjan/bigtree/compare/0.12.4...0.12.5 [0.12.4]: https://github.com/kayjan/bigtree/compare/0.12.3...0.12.4 [0.12.3]: https://github.com/kayjan/bigtree/compare/0.12.2...0.12.3 [0.12.2]: https://github.com/kayjan/bigtree/compare/0.12.1...0.12.2