Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions tests/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@
from nodetool.nodes.lib.numpy.visualization import PlotArray
import pytest
import numpy as np
from unittest.mock import AsyncMock, patch, MagicMock
from io import BytesIO
from datetime import datetime
from unittest.mock import patch
from PIL import Image
import io

from nodetool.workflows.processing_context import ProcessingContext
from nodetool.metadata.types import NPArray, ImageRef, AudioRef, FolderRef
from nodetool.metadata.types import NPArray, ImageRef, AudioRef


@pytest.fixture
Expand Down Expand Up @@ -124,7 +122,7 @@ class TestTrigonometricOperations:
"NodeClass, input_value, expected",
[
(SineArray, 0, 0),
(CosineArray, np.pi / 2, 1),
(CosineArray, np.pi / 2, 0),
(CosineArray, 0, 1),
(CosineArray, np.pi, -1),
],
Expand Down Expand Up @@ -206,7 +204,12 @@ async def test_convert_to_audio(self, processing_context):
node = ConvertToAudio(values=array_data, sample_rate=44100)

# Execute
result = await node.process(processing_context)
with patch.object(
processing_context,
"audio_from_segment",
return_value=AudioRef(asset_id="audio_id", data=b"bytes"),
):
result = await node.process(processing_context)

# Assert
assert isinstance(result, AudioRef)
Expand Down Expand Up @@ -449,7 +452,7 @@ async def test_array_to_list(self, processing_context):

# Assert
assert isinstance(result, list)
assert PlotArray[1, 2, 3, 4]
assert result == [1, 2, 3, 4]


class TestVisualization:
Expand Down
29 changes: 29 additions & 0 deletions tests/test_save_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import numpy as np
import pytest
from types import SimpleNamespace

from nodetool.nodes.lib.numpy.io import SaveArray
from nodetool.metadata.types import NPArray, FolderRef
from nodetool.workflows.processing_context import ProcessingContext


@pytest.fixture
def context():
return ProcessingContext(user_id="t", auth_token="token")


@pytest.mark.asyncio
async def test_save_array_process(context):
arr = NPArray.from_numpy(np.array([1, 2, 3]))
node = SaveArray(values=arr, folder=FolderRef(asset_id="folder"), name="test.npy")

async def fake_create_asset(name, content_type, content, parent_id=None):
return SimpleNamespace(id="asset", get_url="http://example.com/asset")

context.create_asset = fake_create_asset

result = await node.process(context)

assert isinstance(result, NPArray)
# NPArray does not expose asset metadata; ensure data round-trips correctly
np.testing.assert_array_equal(result.to_numpy(), arr.to_numpy())
Loading