Using with `matplotlib.testing.decorators.image_comparison`
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 38/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- matplotlib, python
- Lĩnh vực
- data-visualization, testing
Hướng nghiên cứu
Bắt đầu bằng cách đọc src/mplfinance/_styles.py, đặc biệt là _apply_mpfstyle, và so sánh nó với matplotlib.testing.setup() và set_font_settings_for_testing(). Xem xét các bài kiểm thử so sánh hình ảnh và xác định cách tiếp cận nào giữ cho các font được kết xuất nhất quán giữa các Dev Containers cục bộ và GitHub Actions mà không yêu cầu mỗi bài kiểm thử phải truyền một style tùy chỉnh; được xem là hoàn tất khi các phép so sánh baseline hiện có đều vượt qua trong cả hai môi trường.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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"))
- Ngôn ngữ chính
- Python
- Star
- 4.4k
- Fork
- 678
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của matplotlib/mplfinance
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
matplotlib/mplfinance#672 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
matplotlib/mplfinance#700 ·
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
matplotlib/mplfinance#695 ·
-
question
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
matplotlib/mplfinance#691 · 1 bình luận ·
-
question
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
matplotlib/mplfinance#690 · 5 bình luận ·
Tất cả issue của matplotlib/mplfinance
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
stephrobert/dsoxlab#238 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
sublimehq/package_control#1780 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
nwg-piotr/nwg-displays#145 ·