Skip to content

Commit 130e9fc

Browse files
Lingling PengLingling Peng
authored andcommitted
fix test in sync folder just like async; remove confusing comment; update docstring
1 parent 17782f0 commit 130e9fc

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

synapseclient/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7724,8 +7724,7 @@ def _uploadCsv(
77247724
```python
77257725
import asyncio
77267726
from synapseclient import Synapse
7727-
from synapseclient.models import Table
7728-
from synapseclient.models.mixins.table_components import CsvTableDescriptor
7727+
from synapseclient.models import Table, CsvTableDescriptor
77297728
77307729
TABLE_ID ="syn123" # Replace with your table ID
77317730
PATH = "/path/to/table.csv"

tests/integration/synapseclient/models/async/test_table_async.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,6 @@ async def test_upsert_operations_with_various_data_sources(
10791079
}
10801080
)
10811081

1082-
# Reset the spy to count just this operation
10831082
spy_table_update = mocker.spy(table_module, "_push_row_updates_to_synapse")
10841083

10851084
await table.upsert_rows_async(

tests/integration/synapseclient/models/synchronous/test_entityview.py

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,42 @@ async def test_update_rows_and_annotations(
236236
entityview = entityview.store(synapse_client=self.syn)
237237
self.schedule_for_cleanup(entityview.id)
238238

239-
# SPY on the CSV conversion function to verify different input paths
240-
spy_csv_file_conversion = mocker.spy(table_module, "csv_to_pandas_df")
239+
# Custom wrapper to capture call stack
240+
original_csv_to_pandas_df = table_module.csv_to_pandas_df
241+
call_info = []
242+
243+
def csv_wrapper(*args, **kwargs):
244+
import traceback
245+
246+
stack = traceback.extract_stack()
247+
248+
# Find the calling function (skip the wrapper itself)
249+
calling_function = None
250+
for frame in reversed(stack[:-1]): # Skip current frame
251+
if "_upsert_rows_async" in frame.name:
252+
calling_function = "_upsert_rows_async"
253+
break
254+
elif "query_async" in frame.name:
255+
calling_function = "query_async"
256+
break
257+
else:
258+
pass
259+
260+
call_info.append(
261+
{
262+
"caller": calling_function,
263+
"args": args,
264+
"kwargs": kwargs,
265+
"filepath": kwargs.get("filepath", args[0] if args else None),
266+
}
267+
)
268+
269+
return original_csv_to_pandas_df(*args, **kwargs)
270+
271+
# Patch the csv_to_pandas_df function to use the wrapper
272+
mock_csv_to_pandas_df = mocker.patch.object(
273+
table_module, "csv_to_pandas_df", side_effect=csv_wrapper
274+
)
241275

242276
# Create test data for all files
243277
test_data = {
@@ -257,7 +291,7 @@ async def test_update_rows_and_annotations(
257291

258292
for method in update_methods:
259293
# Reset the spy for each method
260-
spy_csv_file_conversion.reset_mock()
294+
call_info.clear()
261295

262296
# WHEN I update rows using different input types
263297
if method == "csv":
@@ -276,7 +310,10 @@ async def test_update_rows_and_annotations(
276310
)
277311

278312
# THEN the CSV conversion function should be called
279-
spy_csv_file_conversion.assert_called_once()
313+
_upsert_rows_async_calls = [
314+
call for call in call_info if call["caller"] == "_upsert_rows_async"
315+
]
316+
assert len(_upsert_rows_async_calls) == 1
280317

281318
elif method == "dataframe":
282319
# Use DataFrame
@@ -288,7 +325,10 @@ async def test_update_rows_and_annotations(
288325
)
289326

290327
# THEN the CSV conversion function should NOT be called
291-
spy_csv_file_conversion.assert_not_called()
328+
_upsert_rows_async_calls = [
329+
call for call in call_info if call["caller"] == "_upsert_rows_async"
330+
]
331+
assert len(_upsert_rows_async_calls) == 0
292332

293333
else: # dict
294334
# Use dictionary
@@ -300,7 +340,10 @@ async def test_update_rows_and_annotations(
300340
)
301341

302342
# THEN the CSV conversion function should NOT be called
303-
spy_csv_file_conversion.assert_not_called()
343+
_upsert_rows_async_calls = [
344+
call for call in call_info if call["caller"] == "_upsert_rows_async"
345+
]
346+
assert len(_upsert_rows_async_calls) == 0
304347

305348
# THEN the columns should exist in the entity view
306349
assert "column_string" in entityview.columns

0 commit comments

Comments
 (0)