File: test_cbook.py

package info (click to toggle)
metpy 1.7.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,584 kB
  • sloc: python: 41,853; makefile: 111; javascript: 57
file content (32 lines) | stat: -rw-r--r-- 857 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Copyright (c) 2018 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""Test functionality of MetPy's utility code."""

import pytest

from metpy.cbook import example_data, Registry, validate_choice


def test_registry():
    """Test that the registry properly registers things."""
    reg = Registry()

    a = 'foo'
    reg.register('mine')(a)

    assert reg['mine'] is a


def test_example_data():
    """Test that the example data has the proper keys."""
    ds = example_data()
    var_names = list(ds.variables)

    assert 'temperature' in var_names


def test_validate_choice():
    """Test that validation is functioning and error is useful."""
    with pytest.raises(ValueError, match='is not a valid option'):
        validate_choice({'red', 'yellow', 'green'}, color='blue')