@@ -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,21 @@ 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 (
1961+ CrossSync , "_ReadRowsOperation"
1962+ ) as mock_op_constructor :
1963+ mock_op = mock .Mock ()
19631964 expected_result = object ()
1964- read_rows .side_effect = lambda * args , ** kwargs : [expected_result ]
1965+
1966+ if CrossSync .is_async :
1967+
1968+ async def mock_generator ():
1969+ yield expected_result
1970+
1971+ mock_op .start_operation .return_value = mock_generator ()
1972+ else :
1973+ mock_op .start_operation .return_value = [expected_result ]
1974+ mock_op_constructor .return_value = mock_op
19651975 expected_op_timeout = 8
19661976 expected_req_timeout = 4
19671977 row = await table .read_row (
@@ -1970,43 +1980,54 @@ async def test_read_row(self):
19701980 attempt_timeout = expected_req_timeout ,
19711981 )
19721982 assert row == expected_result
1973- assert read_rows .call_count == 1
1974- args , kwargs = read_rows .call_args_list [0 ]
1983+ assert mock_op_constructor .call_count == 1
1984+ args , kwargs = mock_op_constructor .call_args_list [0 ]
19751985 assert kwargs ["operation_timeout" ] == expected_op_timeout
19761986 assert kwargs ["attempt_timeout" ] == expected_req_timeout
1977- assert len (args ) == 1
1987+ assert len (args ) == 2
19781988 assert isinstance (args [0 ], ReadRowsQuery )
19791989 query = args [0 ]
19801990 assert query .row_keys == [row_key ]
19811991 assert query .row_ranges == []
19821992 assert query .limit == 1
1993+ assert args [1 ] is table
19831994
19841995 @CrossSync .pytest
19851996 async def test_read_row_w_filter (self ):
19861997 """Test reading a single row with an added filter"""
19871998 async with self ._make_client () as client :
19881999 table = client .get_table ("instance" , "table" )
19892000 row_key = b"test_1"
1990- with mock .patch .object (table , "read_rows" ) as read_rows :
2001+ with mock .patch .object (
2002+ CrossSync , "_ReadRowsOperation"
2003+ ) as mock_op_constructor :
2004+ mock_op = mock .Mock ()
19912005 expected_result = object ()
1992- read_rows .side_effect = lambda * args , ** kwargs : [expected_result ]
2006+
2007+ if CrossSync .is_async :
2008+
2009+ async def mock_generator ():
2010+ yield expected_result
2011+
2012+ mock_op .start_operation .return_value = mock_generator ()
2013+ else :
2014+ mock_op .start_operation .return_value = [expected_result ]
2015+ mock_op_constructor .return_value = mock_op
19932016 expected_op_timeout = 8
19942017 expected_req_timeout = 4
1995- mock_filter = mock .Mock ()
1996- expected_filter = {"filter" : "mock filter" }
1997- mock_filter ._to_dict .return_value = expected_filter
2018+ expected_filter = mock .Mock ()
19982019 row = await table .read_row (
19992020 row_key ,
20002021 operation_timeout = expected_op_timeout ,
20012022 attempt_timeout = expected_req_timeout ,
20022023 row_filter = expected_filter ,
20032024 )
20042025 assert row == expected_result
2005- assert read_rows .call_count == 1
2006- args , kwargs = read_rows .call_args_list [0 ]
2026+ assert mock_op_constructor .call_count == 1
2027+ args , kwargs = mock_op_constructor .call_args_list [0 ]
20072028 assert kwargs ["operation_timeout" ] == expected_op_timeout
20082029 assert kwargs ["attempt_timeout" ] == expected_req_timeout
2009- assert len (args ) == 1
2030+ assert len (args ) == 2
20102031 assert isinstance (args [0 ], ReadRowsQuery )
20112032 query = args [0 ]
20122033 assert query .row_keys == [row_key ]
@@ -2020,9 +2041,21 @@ async def test_read_row_no_response(self):
20202041 async with self ._make_client () as client :
20212042 table = client .get_table ("instance" , "table" )
20222043 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 : []
2044+ with mock .patch .object (
2045+ CrossSync , "_ReadRowsOperation"
2046+ ) as mock_op_constructor :
2047+ mock_op = mock .Mock ()
2048+
2049+ if CrossSync .is_async :
2050+
2051+ async def mock_generator ():
2052+ if False :
2053+ yield
2054+
2055+ mock_op .start_operation .return_value = mock_generator ()
2056+ else :
2057+ mock_op .start_operation .return_value = []
2058+ mock_op_constructor .return_value = mock_op
20262059 expected_op_timeout = 8
20272060 expected_req_timeout = 4
20282061 result = await table .read_row (
@@ -2031,8 +2064,8 @@ async def test_read_row_no_response(self):
20312064 attempt_timeout = expected_req_timeout ,
20322065 )
20332066 assert result is None
2034- assert read_rows .call_count == 1
2035- args , kwargs = read_rows .call_args_list [0 ]
2067+ assert mock_op_constructor .call_count == 1
2068+ args , kwargs = mock_op_constructor .call_args_list [0 ]
20362069 assert kwargs ["operation_timeout" ] == expected_op_timeout
20372070 assert kwargs ["attempt_timeout" ] == expected_req_timeout
20382071 assert isinstance (args [0 ], ReadRowsQuery )
@@ -2055,22 +2088,36 @@ async def test_row_exists(self, return_value, expected_result):
20552088 async with self ._make_client () as client :
20562089 table = client .get_table ("instance" , "table" )
20572090 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
2091+ with mock .patch .object (
2092+ CrossSync , "_ReadRowsOperation"
2093+ ) as mock_op_constructor :
2094+ mock_op = mock .Mock ()
2095+ if CrossSync .is_async :
2096+
2097+ async def mock_generator ():
2098+ for item in return_value :
2099+ yield item
2100+
2101+ mock_op .start_operation .return_value = mock_generator ()
2102+ else :
2103+ mock_op .start_operation .return_value = return_value
2104+ mock_op_constructor .return_value = mock_op
2105+ expected_op_timeout = 2
2106+ expected_req_timeout = 1
20632107 result = await table .row_exists (
20642108 row_key ,
20652109 operation_timeout = expected_op_timeout ,
20662110 attempt_timeout = expected_req_timeout ,
20672111 )
20682112 assert expected_result == result
2069- assert read_rows .call_count == 1
2070- args , kwargs = read_rows .call_args_list [0 ]
2113+ assert mock_op_constructor .call_count == 1
2114+ args , kwargs = mock_op_constructor .call_args_list [0 ]
20712115 assert kwargs ["operation_timeout" ] == expected_op_timeout
20722116 assert kwargs ["attempt_timeout" ] == expected_req_timeout
2073- assert isinstance (args [0 ], ReadRowsQuery )
2117+ query = args [0 ]
2118+ assert isinstance (query , ReadRowsQuery )
2119+ assert query .row_keys == [row_key ]
2120+ assert query .limit == 1
20742121 expected_filter = {
20752122 "chain" : {
20762123 "filters" : [
@@ -2079,10 +2126,6 @@ async def test_row_exists(self, return_value, expected_result):
20792126 ]
20802127 }
20812128 }
2082- query = args [0 ]
2083- assert query .row_keys == [row_key ]
2084- assert query .row_ranges == []
2085- assert query .limit == 1
20862129 assert query .filter ._to_dict () == expected_filter
20872130
20882131
0 commit comments