38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
"""Waveform data helpers run independently of SETGUI and Qt."""
|
|
import io
|
|
import json
|
|
import unittest
|
|
from set_devices.generator_data import (
|
|
parse_signal_csv, signal_csv_channels, preset_points, generate,
|
|
load_recipe, resample_signal, nearest_f407_sample_rate,
|
|
)
|
|
from set_devices.waveform import recipe
|
|
from set_devices.plot_processing import Axis, Series, Snapshot, prepare, process, write_csv
|
|
|
|
|
|
class GeneratorDataTests(unittest.TestCase):
|
|
def test_processing_csv_roundtrip_into_generator(self):
|
|
request = prepare(Snapshot((Series('a', 'A', [(1000, 0), (1010, 2), (1020, 0)]),),
|
|
Axis('Время', 'мс', 'unix_ms')), 'a', 'linear', 21)
|
|
output = io.StringIO()
|
|
write_csv(process(request), output)
|
|
self.assertEqual(1, len(signal_csv_channels(output.getvalue())))
|
|
points, rate = parse_signal_csv(output.getvalue())
|
|
self.assertEqual((0, 0), points[0])
|
|
self.assertEqual((20, 0), points[-1])
|
|
self.assertIsNone(rate)
|
|
|
|
def test_samples_recipe_and_resampling(self):
|
|
points = preset_points(0, 3.3)
|
|
samples = resample_signal(points, 10000)
|
|
self.assertEqual(200, len(samples))
|
|
wave = generate(samples, 10000, method='samples')
|
|
restored, settings = load_recipe(json.dumps(recipe(wave.points, 10000, 3.3, 'samples', 2)))
|
|
self.assertEqual(wave.points, restored)
|
|
self.assertEqual('samples', settings['method'])
|
|
self.assertEqual(10000, nearest_f407_sample_rate(10001))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|