File: test_flake8_metpy.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 (28 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download | duplicates (2)
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
# Copyright (c) 2021 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""Tests for custom Flake8 plugin for MetPy."""

import ast

import pytest

from flake8_metpy import MetPyChecker


@pytest.mark.parametrize('source, errs', [
    ('5 * pressure.units', 1),
    ('pw = -1. * (np.trapz(w.magnitude, pressure.magnitude) * (w.units * pressure.units))', 1),
    ("""def foo():
    return ret * moist_adiabat_temperatures.units""", 1),
    ('p_interp = np.sort(np.append(p_interp.m, top_pressure.m)) * pressure.units', 1),
    ('parameter = data[ob_type][subset].values * units(self.data.units[ob_type])', 1),
    ('np.nan * pressure.units', 1),
    ('np.array([1, 2, 3]) * units.m', 1),
    ('np.arange(4) * units.s', 1),
    ('np.ma.array([1, 2, 3]) * units.hPa', 1)
])
def test_plugin(source, errs):
    """Test that the flake8 checker works correctly."""
    checker = MetPyChecker(ast.parse(source))
    assert len(list(checker.run())) == errs