Skip to content

Commit b112cff

Browse files
1 parent 6f9ddce commit b112cff

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

‎bigquery_magics/graph_server.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ def convert_graph_data(query_results: Dict[str, Dict[str, str]]):
6666
if not isinstance(key, str):
6767
raise ValueError(f"Expected outer key to be str, got {type(key)}")
6868
if not isinstance(value, dict):
69-
raise ValueError(f"Expected outer value to be dict, got {type(value)}")
69+
raise ValueError(
70+
f"Expected outer value to be dict, got {type(value)}"
71+
)
7072
column_name = key
7173
column_value = value
7274
else:
@@ -88,7 +90,9 @@ def convert_graph_data(query_results: Dict[str, Dict[str, str]]):
8890
if not isinstance(value_key, str):
8991
raise ValueError(f"Expected inner key to be str, got {type(value_key)}")
9092
if not isinstance(value_value, str):
91-
raise ValueError(f"Expected inner value to be str, got {type(value_value)}")
93+
raise ValueError(
94+
f"Expected inner value to be str, got {type(value_value)}"
95+
)
9296
row_index = int(value_key)
9397
row_json = json.loads(value_value)
9498

‎tests/unit/test_graph_server.py‎

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -222,22 +222,20 @@ def test_convert_nongraph_json():
222222
)
223223
def test_convert_outer_key_not_string():
224224
result = convert_graph_data(
225-
{
226-
0: {
227-
'0': json.dumps({"foo": 1, "bar": 2}),
228-
}
229-
})
225+
{
226+
0: {
227+
"0": json.dumps({"foo": 1, "bar": 2}),
228+
}
229+
}
230+
)
230231
assert result == {"error": "Expected outer key to be str, got <class 'int'>"}
231232

232233

233234
@pytest.mark.skipif(
234235
graph_visualization is None, reason="Requires `spanner-graph-notebook`"
235236
)
236237
def test_convert_outer_value_not_dict():
237-
result = convert_graph_data(
238-
{
239-
'result': 0
240-
})
238+
result = convert_graph_data({"result": 0})
241239
assert result == {"error": "Expected outer value to be dict, got <class 'int'>"}
242240

243241

@@ -246,11 +244,12 @@ def test_convert_outer_value_not_dict():
246244
)
247245
def test_convert_inner_key_not_string():
248246
result = convert_graph_data(
249-
{
250-
'result': {
251-
0: json.dumps({"foo": 1, "bar": 2}),
252-
}
253-
})
247+
{
248+
"result": {
249+
0: json.dumps({"foo": 1, "bar": 2}),
250+
}
251+
}
252+
)
254253
assert result == {"error": "Expected inner key to be str, got <class 'int'>"}
255254

256255

@@ -259,11 +258,12 @@ def test_convert_inner_key_not_string():
259258
)
260259
def test_convert_inner_value_not_string():
261260
result = convert_graph_data(
262-
{
263-
'result': {
264-
'0': 1,
265-
}
266-
})
261+
{
262+
"result": {
263+
"0": 1,
264+
}
265+
}
266+
)
267267
assert result == {"error": "Expected inner value to be str, got <class 'int'>"}
268268

269269

@@ -278,19 +278,22 @@ def test_convert_one_column_one_row_two_columns():
278278
},
279279
"result2": {
280280
"0": json.dumps(row_alex_owns_account),
281-
}
282-
281+
},
283282
}
284283
)
285-
assert result == {"error": "Query has multiple columns - graph visualization not supported"}
284+
assert result == {
285+
"error": "Query has multiple columns - graph visualization not supported"
286+
}
286287

287288

288289
@pytest.mark.skipif(
289290
graph_visualization is None, reason="Requires `spanner-graph-notebook`"
290291
)
291292
def test_convert_empty_dict():
292293
result = convert_graph_data({})
293-
assert result == {"error": "query result with no columns is not supported for graph visualization"}
294+
assert result == {
295+
"error": "query result with no columns is not supported for graph visualization"
296+
}
294297

295298

296299
class TestGraphServer(unittest.TestCase):

0 commit comments

Comments
 (0)