@@ -1205,7 +1205,6 @@ async def test_ctor(self):
12051205 assert instance_key in client ._active_instances
12061206 assert client ._instance_owners [instance_key ] == {id (table )}
12071207 assert isinstance (table ._metrics , BigtableClientSideMetricsController )
1208- assert table ._metrics .interceptor == client ._metrics_interceptor
12091208 assert table .default_operation_timeout == expected_operation_timeout
12101209 assert table .default_attempt_timeout == expected_attempt_timeout
12111210 assert (
@@ -1547,7 +1546,6 @@ async def test_ctor(self):
15471546 assert instance_key in client ._active_instances
15481547 assert client ._instance_owners [instance_key ] == {id (view )}
15491548 assert isinstance (view ._metrics , BigtableClientSideMetricsController )
1550- assert view ._metrics .interceptor == client ._metrics_interceptor
15511549 assert view .default_operation_timeout == expected_operation_timeout
15521550 assert view .default_attempt_timeout == expected_attempt_timeout
15531551 assert (
@@ -1959,9 +1957,19 @@ async def test_read_row(self):
19591957 async with self ._make_client () as client :
19601958 table = client .get_table ("instance" , "table" )
19611959 row_key = b"test_1"
1962- with mock .patch .object (table , "read_rows" ) as read_rows :
1960+ with mock .patch .object (CrossSync , "_ReadRowsOperation" ) as mock_op_constructor :
1961+ mock_op = mock .Mock ()
19631962 expected_result = object ()
1964- read_rows .side_effect = lambda * args , ** kwargs : [expected_result ]
1963+
1964+ if CrossSync .is_async :
1965+
1966+ async def mock_generator ():
1967+ yield expected_result
1968+
1969+ mock_op .start_operation .return_value = mock_generator ()
1970+ else :
1971+ mock_op .start_operation .return_value = [expected_result ]
1972+ mock_op_constructor .return_value = mock_op
19651973 expected_op_timeout = 8
19661974 expected_req_timeout = 4
19671975 row = await table .read_row (
@@ -1970,43 +1978,52 @@ async def test_read_row(self):
19701978 attempt_timeout = expected_req_timeout ,
19711979 )
19721980 assert row == expected_result
1973- assert read_rows .call_count == 1
1974- args , kwargs = read_rows .call_args_list [0 ]
1981+ assert mock_op_constructor .call_count == 1
1982+ args , kwargs = mock_op_constructor .call_args_list [0 ]
19751983 assert kwargs ["operation_timeout" ] == expected_op_timeout
19761984 assert kwargs ["attempt_timeout" ] == expected_req_timeout
1977- assert len (args ) == 1
1985+ assert len (args ) == 2
19781986 assert isinstance (args [0 ], ReadRowsQuery )
19791987 query = args [0 ]
19801988 assert query .row_keys == [row_key ]
19811989 assert query .row_ranges == []
19821990 assert query .limit == 1
1991+ assert args [1 ] is table
19831992
19841993 @CrossSync .pytest
19851994 async def test_read_row_w_filter (self ):
19861995 """Test reading a single row with an added filter"""
19871996 async with self ._make_client () as client :
19881997 table = client .get_table ("instance" , "table" )
19891998 row_key = b"test_1"
1990- with mock .patch .object (table , "read_rows" ) as read_rows :
1999+ with mock .patch .object (CrossSync , "_ReadRowsOperation" ) as mock_op_constructor :
2000+ mock_op = mock .Mock ()
19912001 expected_result = object ()
1992- read_rows .side_effect = lambda * args , ** kwargs : [expected_result ]
2002+
2003+ if CrossSync .is_async :
2004+
2005+ async def mock_generator ():
2006+ yield expected_result
2007+
2008+ mock_op .start_operation .return_value = mock_generator ()
2009+ else :
2010+ mock_op .start_operation .return_value = [expected_result ]
2011+ mock_op_constructor .return_value = mock_op
19932012 expected_op_timeout = 8
19942013 expected_req_timeout = 4
1995- mock_filter = mock .Mock ()
1996- expected_filter = {"filter" : "mock filter" }
1997- mock_filter ._to_dict .return_value = expected_filter
2014+ expected_filter = mock .Mock ()
19982015 row = await table .read_row (
19992016 row_key ,
20002017 operation_timeout = expected_op_timeout ,
20012018 attempt_timeout = expected_req_timeout ,
20022019 row_filter = expected_filter ,
20032020 )
20042021 assert row == expected_result
2005- assert read_rows .call_count == 1
2006- args , kwargs = read_rows .call_args_list [0 ]
2022+ assert mock_op_constructor .call_count == 1
2023+ args , kwargs = mock_op_constructor .call_args_list [0 ]
20072024 assert kwargs ["operation_timeout" ] == expected_op_timeout
20082025 assert kwargs ["attempt_timeout" ] == expected_req_timeout
2009- assert len (args ) == 1
2026+ assert len (args ) == 2
20102027 assert isinstance (args [0 ], ReadRowsQuery )
20112028 query = args [0 ]
20122029 assert query .row_keys == [row_key ]
@@ -2020,9 +2037,19 @@ async def test_read_row_no_response(self):
20202037 async with self ._make_client () as client :
20212038 table = client .get_table ("instance" , "table" )
20222039 row_key = b"test_1"
2023- with mock .patch .object (table , "read_rows" ) as read_rows :
2024- # return no rows
2025- read_rows .side_effect = lambda * args , ** kwargs : []
2040+ with mock .patch .object (CrossSync , "_ReadRowsOperation" ) as mock_op_constructor :
2041+ mock_op = mock .Mock ()
2042+
2043+ if CrossSync .is_async :
2044+
2045+ async def mock_generator ():
2046+ if False :
2047+ yield
2048+
2049+ mock_op .start_operation .return_value = mock_generator ()
2050+ else :
2051+ mock_op .start_operation .return_value = []
2052+ mock_op_constructor .return_value = mock_op
20262053 expected_op_timeout = 8
20272054 expected_req_timeout = 4
20282055 result = await table .read_row (
@@ -2031,8 +2058,8 @@ async def test_read_row_no_response(self):
20312058 attempt_timeout = expected_req_timeout ,
20322059 )
20332060 assert result is None
2034- assert read_rows .call_count == 1
2035- args , kwargs = read_rows .call_args_list [0 ]
2061+ assert mock_op_constructor .call_count == 1
2062+ args , kwargs = mock_op_constructor .call_args_list [0 ]
20362063 assert kwargs ["operation_timeout" ] == expected_op_timeout
20372064 assert kwargs ["attempt_timeout" ] == expected_req_timeout
20382065 assert isinstance (args [0 ], ReadRowsQuery )
@@ -2055,22 +2082,34 @@ async def test_row_exists(self, return_value, expected_result):
20552082 async with self ._make_client () as client :
20562083 table = client .get_table ("instance" , "table" )
20572084 row_key = b"test_1"
2058- with mock .patch .object (table , "read_rows" ) as read_rows :
2059- # return no rows
2060- read_rows .side_effect = lambda * args , ** kwargs : return_value
2061- expected_op_timeout = 1
2062- expected_req_timeout = 2
2085+ with mock .patch .object (CrossSync , "_ReadRowsOperation" ) as mock_op_constructor :
2086+ mock_op = mock .Mock ()
2087+ if CrossSync .is_async :
2088+
2089+ async def mock_generator ():
2090+ for item in return_value :
2091+ yield item
2092+
2093+ mock_op .start_operation .return_value = mock_generator ()
2094+ else :
2095+ mock_op .start_operation .return_value = return_value
2096+ mock_op_constructor .return_value = mock_op
2097+ expected_op_timeout = 2
2098+ expected_req_timeout = 1
20632099 result = await table .row_exists (
20642100 row_key ,
20652101 operation_timeout = expected_op_timeout ,
20662102 attempt_timeout = expected_req_timeout ,
20672103 )
20682104 assert expected_result == result
2069- assert read_rows .call_count == 1
2070- args , kwargs = read_rows .call_args_list [0 ]
2105+ assert mock_op_constructor .call_count == 1
2106+ args , kwargs = mock_op_constructor .call_args_list [0 ]
20712107 assert kwargs ["operation_timeout" ] == expected_op_timeout
20722108 assert kwargs ["attempt_timeout" ] == expected_req_timeout
2073- assert isinstance (args [0 ], ReadRowsQuery )
2109+ query = args [0 ]
2110+ assert isinstance (query , ReadRowsQuery )
2111+ assert query .row_keys == [row_key ]
2112+ assert query .limit == 1
20742113 expected_filter = {
20752114 "chain" : {
20762115 "filters" : [
@@ -2079,10 +2118,6 @@ async def test_row_exists(self, return_value, expected_result):
20792118 ]
20802119 }
20812120 }
2082- query = args [0 ]
2083- assert query .row_keys == [row_key ]
2084- assert query .row_ranges == []
2085- assert query .limit == 1
20862121 assert query .filter ._to_dict () == expected_filter
20872122
20882123
0 commit comments