Completed
Push — master ( 912dc8...6b82ea )
by Ryan
19s
created

test_add_metpy_logo_small()   A

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
1
# Copyright (c) 2008-2016 MetPy Developers.
2
# Distributed under the terms of the BSD 3-Clause License.
3
# SPDX-License-Identifier: BSD-3-Clause
4
"""Tests for the `_util` module."""
5
6
from datetime import datetime
7
8
import matplotlib
9
import matplotlib.pyplot as plt
10
import pytest
11
12
from metpy.plots import add_metpy_logo, add_timestamp, add_unidata_logo
13
# Fixture to make sure we have the right backend
14
from metpy.testing import set_agg_backend  # noqa: F401
15
16
MPL_VERSION = matplotlib.__version__[:3]
17
18
19
@pytest.mark.mpl_image_compare(tolerance={'1.4': 5.58}.get(MPL_VERSION, 0.01),
20
                               remove_text=True)
21
def test_add_timestamp():
22
    """Test adding a timestamp to an axes object."""
23
    fig = plt.figure(figsize=(9, 9))
24
    ax = plt.subplot(1, 1, 1)
25
    add_timestamp(ax, time=datetime(2017, 1, 1))
26
    return fig
27
28
29
@pytest.mark.mpl_image_compare(tolerance={'1.4': 0.004}.get(MPL_VERSION, 0.01),
30
                               remove_text=True)
31
def test_add_metpy_logo_small():
32
    """Test adding a MetPy logo to a figure."""
33
    fig = plt.figure(figsize=(9, 9))
34
    add_metpy_logo(fig)
35
    return fig
36
37
38
@pytest.mark.mpl_image_compare(tolerance={'1.4': 0.004}.get(MPL_VERSION, 0.01),
39
                               remove_text=True)
40
def test_add_metpy_logo_large():
41
    """Test adding a large MetPy logo to a figure."""
42
    fig = plt.figure(figsize=(9, 9))
43
    add_metpy_logo(fig, size='large')
44
    return fig
45
46
47
@pytest.mark.mpl_image_compare(tolerance={'1.4': 0.004}.get(MPL_VERSION, 0.01),
48
                               remove_text=True)
49
def test_add_unidata_logo():
50
    """Test adding a Unidata logo to a figure."""
51
    fig = plt.figure(figsize=(9, 9))
52
    add_unidata_logo(fig)
53
    return fig
54
55
56
def test_add_logo_invalid_size():
57
    """Test adding a logo to a figure with an invalid size specification."""
58
    fig = plt.figure(figsize=(9, 9))
59
    with pytest.raises(ValueError):
60
        add_metpy_logo(fig, size='jumbo')
61