File: test_tools.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 (23 lines) | stat: -rw-r--r-- 674 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
# Copyright (c) 2020 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""Test the `_tools` module."""

from metpy.io._tools import NamedStruct


def test_unpack():
    """Test unpacking a NamedStruct from bytes."""
    struct = NamedStruct([('field1', 'i'), ('field2', 'h')], '>')

    s = struct.unpack(b'\x00\x01\x00\x01\x00\x02')
    assert s.field1 == 65537
    assert s.field2 == 2


def test_pack():
    """Test packing a NamedStruct into bytes."""
    struct = NamedStruct([('field1', 'i'), ('field2', 'h')], '>')

    b = struct.pack(field1=8, field2=3)
    assert b == b'\x00\x00\x00\x08\x00\x03'