Skip to content

Tests for simulation reduction in upload() #2587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2025
Merged
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
31 changes: 31 additions & 0 deletions tests/test_web/test_webapi_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,22 @@ def mock_upload(monkeypatch, set_api_key):
status=200,
)

# store the uploaded stub for verification
uploaded_stub = {}

def mock_upload_simulation(self, stub, **kwargs):
uploaded_stub["stub"] = stub

def mock_upload_file(*args, **kwargs):
pass

monkeypatch.setattr(
"tidy3d.web.core.task_core.SimulationTask.upload_simulation", mock_upload_simulation
)
monkeypatch.setattr("tidy3d.web.core.task_core.upload_file", mock_upload_file)

return uploaded_stub


@pytest.fixture
def mock_get_info(monkeypatch, set_api_key):
Expand Down Expand Up @@ -269,6 +280,26 @@ def test_upload(monkeypatch, mock_upload, mock_get_info, mock_metadata):
assert upload(sim, TASK_NAME, PROJECT_NAME, reduce_simulation=True)


@pytest.mark.parametrize("reduce_simulation", [True, False])
@responses.activate
def test_upload_with_reduction_parameter(
monkeypatch, mock_upload, mock_get_info, mock_metadata, reduce_simulation
):
"""Test that simulation reduction is properly applied before upload based on reduce_simulation parameter."""
sim = make_mode_sim()

upload(sim, TASK_NAME, PROJECT_NAME, reduce_simulation=reduce_simulation)

if reduce_simulation:
expected_sim = get_reduced_simulation(sim, reduce_simulation=True)
assert sim != expected_sim
else:
expected_sim = sim

uploaded_sim = mock_upload["stub"].simulation
assert uploaded_sim == expected_sim
Comment on lines +299 to +300
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding a failure message to the assertion to clarify the error when the test fails

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion in principle but in this test it's quite obvious what would be failing so not necessary I would say.



@responses.activate
def test_get_info(mock_get_info):
assert get_info(TASK_ID).taskId == TASK_ID
Expand Down
31 changes: 31 additions & 0 deletions tests/test_web/test_webapi_mode_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,22 @@ def mock_upload(monkeypatch, set_api_key):
status=200,
)

# store the uploaded stub for verification
uploaded_stub = {}

def mock_upload_simulation(self, stub, **kwargs):
uploaded_stub["stub"] = stub

def mock_upload_file(*args, **kwargs):
pass

monkeypatch.setattr(
"tidy3d.web.core.task_core.SimulationTask.upload_simulation", mock_upload_simulation
)
monkeypatch.setattr("tidy3d.web.core.task_core.upload_file", mock_upload_file)

return uploaded_stub


@pytest.fixture
def mock_get_info(monkeypatch, set_api_key):
Expand Down Expand Up @@ -265,6 +276,26 @@ def test_upload(monkeypatch, mock_upload, mock_get_info, mock_metadata):
assert upload(sim, TASK_NAME, PROJECT_NAME, reduce_simulation=True)


@pytest.mark.parametrize("reduce_simulation", [True, False])
@responses.activate
def test_upload_with_reduction_parameter(
monkeypatch, mock_upload, mock_get_info, mock_metadata, reduce_simulation
):
"""Test that simulation reduction is properly applied before upload based on reduce_simulation parameter."""
sim = make_mode_sim()

upload(sim, TASK_NAME, PROJECT_NAME, reduce_simulation=reduce_simulation)

if reduce_simulation:
expected_sim = get_reduced_simulation(sim, reduce_simulation=True)
assert sim != expected_sim
else:
expected_sim = sim

uploaded_sim = mock_upload["stub"].simulation
assert uploaded_sim == expected_sim


@responses.activate
def test_get_info(mock_get_info):
assert get_info(TASK_ID).taskId == TASK_ID
Expand Down