|
| 1 | +import io |
| 2 | +import xml |
1 | 3 | import functools
|
2 | 4 | import itertools
|
3 | 5 | import warnings
|
4 |
| -import imghdr |
5 | 6 |
|
6 | 7 | import numpy as np
|
7 | 8 | import pandas as pd
|
8 | 9 | import matplotlib as mpl
|
9 | 10 | import matplotlib.pyplot as plt
|
| 11 | +from PIL import Image |
10 | 12 |
|
11 | 13 | import pytest
|
12 | 14 | from pandas.testing import assert_frame_equal, assert_series_equal
|
@@ -864,12 +866,18 @@ def test_theme_default(self):
|
864 | 866 | p = Plot().plot()
|
865 | 867 | assert mpl.colors.same_color(p._figure.axes[0].get_facecolor(), "#EAEAF2")
|
866 | 868 |
|
867 |
| - def test_theme(self): |
| 869 | + def test_theme_params(self): |
868 | 870 |
|
869 | 871 | color = "r"
|
870 | 872 | p = Plot().theme({"axes.facecolor": color}).plot()
|
871 | 873 | assert mpl.colors.same_color(p._figure.axes[0].get_facecolor(), color)
|
872 | 874 |
|
| 875 | + def test_theme_error(self): |
| 876 | + |
| 877 | + p = Plot() |
| 878 | + with pytest.raises(TypeError, match=r"theme\(\) takes 1 positional"): |
| 879 | + p.theme("arg1", "arg2") |
| 880 | + |
873 | 881 | def test_move(self, long_df):
|
874 | 882 |
|
875 | 883 | orig_df = long_df.copy(deep=True)
|
@@ -960,21 +968,31 @@ def test_show(self):
|
960 | 968 | if not gui_backend:
|
961 | 969 | assert msg
|
962 | 970 |
|
963 |
| - def test_png_representation(self): |
| 971 | + def test_png_repr(self): |
964 | 972 |
|
965 | 973 | p = Plot()
|
966 | 974 | data, metadata = p._repr_png_()
|
| 975 | + img = Image.open(io.BytesIO(data)) |
967 | 976 |
|
968 | 977 | assert not hasattr(p, "_figure")
|
969 | 978 | assert isinstance(data, bytes)
|
970 |
| - assert imghdr.what("", data) == "png" |
| 979 | + assert img.format == "PNG" |
971 | 980 | assert sorted(metadata) == ["height", "width"]
|
972 | 981 | # TODO test retina scaling
|
973 | 982 |
|
974 |
| - @pytest.mark.xfail(reason="Plot.save not yet implemented") |
975 | 983 | def test_save(self):
|
976 | 984 |
|
977 |
| - Plot().save() |
| 985 | + buf = io.BytesIO() |
| 986 | + |
| 987 | + p = Plot().save(buf) |
| 988 | + assert isinstance(p, Plot) |
| 989 | + img = Image.open(buf) |
| 990 | + assert img.format == "PNG" |
| 991 | + |
| 992 | + buf = io.StringIO() |
| 993 | + Plot().save(buf, format="svg") |
| 994 | + tag = xml.etree.ElementTree.fromstring(buf.getvalue()).tag |
| 995 | + assert tag == "{http://www.w3.org/2000/svg}svg" |
978 | 996 |
|
979 | 997 | def test_on_axes(self):
|
980 | 998 |
|
|
0 commit comments