Using with `matplotlib.testing.decorators.image_comparison`
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 38/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- matplotlib, python
調査の方向性
まず src/mplfinance/_styles.py、特に _apply_mpfstyle を読み、matplotlib.testing.setup() および set_font_settings_for_testing() と比較してください。画像比較テストを確認し、各テストでカスタムスタイルを渡すことなく、ローカルの Dev Containers と GitHub Actions の間でレンダリングされるフォントの一貫性を保てるアプローチを判断してください。既存のベースライン比較が両方の環境で成功すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
The problem is that the baseline images generated locally (in a Dev Container) don't match the ones on CI (GitHub Actions running the latest Ubuntu LTS) and thus my tests fail. When I compared the images I figured out that different fonts are being used: CI's Ubuntu has more fonts pre-installed than a Dev Container so the text was rendered with Liberation Sans instead of DejaVu Sans.
To quick fix it:
- Install Liberation fonts locally
sudo apt install fonts-liberation - Drop
matplotlibfonts cache (file location and name can be different)
rm ~/.cache/matplotlib/fontlist-v330.json - Re-generate baseline images
Also to find a solution that won't fail when some font is added/removed locally/remotely, I dug deeper and figured out that matpltolib has a solution for this well-known issue: matplotlib.testing.setup() that calls set_font_settings_for_testing() that sets font.family to DejaVu Sans.
But for mplfinance that makes no difference because the font.family gets overridden by _apply_mpfstyle call. For example, the default style sets it to sans-serif (comes from base_mpl_style='seaborn-darkgrid'), and then nobody knows which font maptlotlib is going to use for rendering.
Here I came up with two solutions:
pytest fixture
Pros:
- uses only public API
Cons:
- need to pass to every
.plot(...)
@pytest.fixture
def mpf_style():
return mpf.make_mpf_style(
base_mpf_style="default", rc={"font.family": "DejaVu Sans"}
)
@image_comparison(baseline_images=["test.png"])
def test(mpf_style):
mpf.plot(..., style=mpf_style)
pytest before-all hook that mutates default style
Pros:
- all the existing tests left untouched
- never forget passing
style=...in new ones
Cons:
- gets broken on the underlying
mplfinanceimplementation changes
def pytest_configure() -> None:
mpf._styledata.default.style["rc"].append(("font.family", "DejaVu Sans"))
- 主要言語
- Python
- スター
- 4.4k
- フォーク
- 678
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
matplotlib/mplfinance のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
matplotlib/mplfinance#672 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
matplotlib/mplfinance#700 ·
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
matplotlib/mplfinance#695 ·
-
question
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
matplotlib/mplfinance#691 · コメント 1 件 ·
-
question
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
matplotlib/mplfinance#690 · コメント 5 件 ·
matplotlib/mplfinance の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
stephrobert/dsoxlab#238 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
sublimehq/package_control#1780 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
nwg-piotr/nwg-displays#145 ·