-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This paves the way towards writing instances of NamedStructs.
- Loading branch information
1 parent
42e0e3f
commit 81891ed
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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' |