Skip to content

Commit c889239

Browse files
aic1994Kyle A Logue
andauthored
Add basic I/O test for sigmf_convert_wav (fixes #50) (#123)
* Add basic I/O test for sigmf_convert_wav (fixes #50) * black & isort --------- Co-authored-by: Kyle A Logue <kyle.a.logue@aero.org>
1 parent 63ccc70 commit c889239

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/test_convert_wav.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright: Multiple Authors
2+
#
3+
# This file is part of sigmf-python. https://github.com/sigmf/sigmf-python
4+
#
5+
# SPDX-License-Identifier: LGPL-3.0-or-later
6+
7+
"""Tests wav formatted audio conversion"""
8+
9+
import os
10+
import tempfile
11+
12+
import numpy as np
13+
import pytest
14+
from scipy.io import wavfile
15+
16+
from sigmf.apps.convert_wav import convert_wav
17+
18+
19+
def test_wav_to_sigmf_basic():
20+
"""Basic smoke-test: convert a tiny WAV → SIGMF, assert file created."""
21+
fs = 48_000
22+
t = np.linspace(0, 0.1, int(fs * 0.1)) # 0.1 s
23+
sine = np.sin(2 * np.pi * 1000 * t)
24+
sine_int = (sine * 32767).astype(np.int16)
25+
26+
# Create temp file and close it before use
27+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_wav:
28+
tmp_wav_path = tmp_wav.name
29+
30+
# Write to the closed file
31+
wavfile.write(tmp_wav_path, fs, sine_int)
32+
tmp_sigmf = tmp_wav_path.replace(".wav", ".sigmf")
33+
34+
try:
35+
# Run converter
36+
convert_wav(tmp_wav_path, tmp_sigmf)
37+
38+
# Assert SIGMF file exists and non-zero
39+
assert os.path.exists(tmp_sigmf), "SIGMF file not created"
40+
assert os.path.getsize(tmp_sigmf) > 0, "SIGMF file is empty"
41+
finally:
42+
# Clean up both files
43+
if os.path.exists(tmp_wav_path):
44+
os.remove(tmp_wav_path)
45+
if os.path.exists(tmp_sigmf):
46+
os.remove(tmp_sigmf)

0 commit comments

Comments
 (0)