Using with `matplotlib.testing.decorators.image_comparison`
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 38/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- matplotlib, python
- Ambito
- data-visualization, testing
Direzione di ricerca
Inizia leggendo src/mplfinance/_styles.py, in particolare _apply_mpfstyle, e confrontalo con matplotlib.testing.setup() e set_font_settings_for_testing(). Esamina i test di confronto delle immagini e determina quale approccio mantiene coerenti i font renderizzati tra i Dev Containers locali e GitHub Actions senza richiedere che ogni test passi uno stile personalizzato; il lavoro è completato quando i confronti di baseline esistenti hanno esito positivo in entrambi gli ambienti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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"))
- Lingua principale
- Python
- Stelle
- 4.4k
- Fork
- 678
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di matplotlib/mplfinance
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
matplotlib/mplfinance#672 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 10/100
matplotlib/mplfinance#700 ·
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
matplotlib/mplfinance#695 ·
-
question
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
matplotlib/mplfinance#691 · 1 commento ·
-
question
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
matplotlib/mplfinance#690 · 5 commenti ·
Tutte le issue di matplotlib/mplfinance
Issue simili
-
Broken links found in docsApertadocs pydanty:is-working
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
pydantic/pydantic-ai#8863 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
run-llama/llama_index#23278 ·
I maintainer di solito rispondono entro 2 giorni
-
documentation from-review-extraction github-actions priority: low severity:nit
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
LearningCircuit/local-deep-research#6946 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
oracle/langchain-oracle#323 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
tenstorrent/tt-metal#58057 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno