diff --git a/b_asic/signal_generator.py b/b_asic/signal_generator.py index c236a1cb58ccbb1c4abd32111ffe25a7492ae07b..69f7acbc16978655d24787c3aebd6474e5e5d05c 100644 --- a/b_asic/signal_generator.py +++ b/b_asic/signal_generator.py @@ -165,7 +165,7 @@ class ZeroPad(SignalGenerator): class FromFile(SignalGenerator): """ Signal generator that reads from file and pads a sequence with zeros. - + File should be of type .txt or .csv and contain a single column vector Parameters ---------- path : string @@ -173,20 +173,10 @@ class FromFile(SignalGenerator): """ def __init__(self, path) -> None: - try: - Path(path).resolve(strict=True) - except FileNotFoundError: - raise Exception("Selected input file not found.") - - try: - data = np.loadtxt(path, dtype=complex).tolist() - self._data = data - self._len = len(data) - except ValueError: - raise Exception( - "Selected input file is not of the right format, should be of filetype" - " .txt or .csv and contain single column input vector." - ) + self._path = path + data = np.loadtxt(path, dtype=complex).tolist() + self._data = data + self._len = len(data) def __call__(self, time: int) -> complex: if 0 <= time < self._len: @@ -194,7 +184,7 @@ class FromFile(SignalGenerator): return 0.0 def __repr__(self) -> str: - return f"FromFile({self._data})" + return f"FromFile({self._path!r})" class Sinusoid(SignalGenerator): diff --git a/test/test_gui.py b/test/test_gui.py index e8d16e3f3b9e1fa2a480da370a2e17f274d511f1..95902995e7ab6be5985ef51be0edca945ab1d1bd 100644 --- a/test/test_gui.py +++ b/test/test_gui.py @@ -148,6 +148,22 @@ def test_help_dialogs(qtbot): widget.exit_app() +def test_simulate(qtbot, datadir): + # Smoke test to open up the "Simulate SFG" and run default simulation + # Should really test all different tests + widget = GUI.MainWindow() + qtbot.addWidget(widget) + widget._load_from_file(datadir.join('twotapfir.py')) + assert 'twotapfir' in widget.sfg_dict + widget.simulate_sfg() + qtbot.wait(100) + widget.dialog.save_properties() + qtbot.wait(100) + widget.dialog.close() + + widget.exit_app() + + def test_properties_window_smoke_test(qtbot, datadir): # Smoke test to open up the properties window # Should really check that the contents are correct and changes works etc @@ -159,9 +175,7 @@ def test_properties_window_smoke_test(qtbot, datadir): dragbutton = widget.operationDragDict[op] dragbutton.show_properties_window() assert dragbutton._properties_window.operation == dragbutton - qtbot.mouseClick( - dragbutton._properties_window.ok, QtCore.Qt.MouseButton.LeftButton - ) + qtbot.mouseClick(dragbutton._properties_window.ok, QtCore.Qt.MouseButton.LeftButton) widget.exit_app() @@ -179,9 +193,7 @@ def test_properties_window_change_name(qtbot, datadir): dragbutton.show_properties_window() assert dragbutton._properties_window.edit_name.text() == "cmul2" dragbutton._properties_window.edit_name.setText("cmul73") - qtbot.mouseClick( - dragbutton._properties_window.ok, QtCore.Qt.MouseButton.LeftButton - ) + qtbot.mouseClick(dragbutton._properties_window.ok, QtCore.Qt.MouseButton.LeftButton) dragbutton._properties_window.save_properties() assert dragbutton.name == "cmul73" assert dragbutton.operation.name == "cmul73" diff --git a/test/test_signal_generator.py b/test/test_signal_generator.py index 213e7062f00c6039977a0951eb99f1abf4d57994..4f9d02c85d4ddb2712485b46b4242a4511fbe235 100644 --- a/test/test_signal_generator.py +++ b/test/test_signal_generator.py @@ -273,12 +273,15 @@ def test_division(): assert isinstance(g, _DivGenerator) -def test_fromfile(): - absolute_path = os.path.dirname(__file__) - relative_path = "../examples/input.csv" - full_path = os.path.join(absolute_path, relative_path) - g = FromFile(full_path) +def test_fromfile(datadir): + g = FromFile(datadir.join('input.csv')) assert g(-1) == 0.0 assert g(0) == 0 assert g(1) == 1 assert g(2) == 0 + + with pytest.raises(FileNotFoundError, match="tset.py not found"): + g = FromFile(datadir.join('tset.py')) + + with pytest.raises(ValueError, match="could not convert string"): + g = FromFile(datadir.join('test.py')) diff --git a/test/test_signal_generator/input.csv b/test/test_signal_generator/input.csv new file mode 100644 index 0000000000000000000000000000000000000000..b0917c8e2523298b91f0612287acd0150219ca53 --- /dev/null +++ b/test/test_signal_generator/input.csv @@ -0,0 +1,5 @@ +0 +1 +0 +0 +0 diff --git a/test/test_signal_generator/test.py b/test/test_signal_generator/test.py new file mode 100644 index 0000000000000000000000000000000000000000..147e61fc20bcaaf9acc081fb35b5647617b3a831 --- /dev/null +++ b/test/test_signal_generator/test.py @@ -0,0 +1,25 @@ +""" +B-ASIC automatically generated SFG file. +Name: test +Last saved: 2023-02-15 16:45:16.836909. +""" +from b_asic import SFG, Delay, Input, Output, Signal + +# Inputs: +in1 = Input(name="") + +# Outputs: +out1 = Output(name="") + +# Operations: +t1 = Delay(name="") + +# Signals: + +Signal(source=t1.output(0), destination=out1.input(0)) +Signal(source=in1.output(0), destination=t1.input(0)) +test = SFG(inputs=[in1], outputs=[out1], name='test') + +# SFG Properties: +prop = {'name': test} +positions = {'t1': (114, 38, False), 'in1': (-57, 38, False), 'out1': (304, 38, False)}