@@ -37,39 +37,17 @@ def connection_config(request, database):
37
37
)
38
38
39
39
40
- @pytest .fixture (params = [_SENTINEL ])
41
- def credentials_config (request , database ):
42
- return (
43
- None
44
- if request .param is _SENTINEL # `None` is a valid value to test
45
- else request .param
46
- )
47
-
48
-
49
40
@pytest .fixture (params = [_SENTINEL ])
50
41
def table_name (request ):
51
42
# Default table name when not explicitly parametrized
52
43
return "test" if request .param is _SENTINEL else request .param
53
44
54
45
55
- # @pytest.fixture(params=['test'])
56
- # def table_name(request):
57
- # return request.param
58
-
59
-
60
46
@pytest .fixture
61
- def table_dataset (
62
- database_name ,
63
- credentials_config ,
64
- connection_config ,
65
- load_args ,
66
- save_args ,
67
- table_name ,
68
- ):
47
+ def table_dataset (table_name , database_name , connection_config , load_args , save_args ):
69
48
return TableDataset (
70
49
table_name = table_name ,
71
50
database = database_name ,
72
- credentials = credentials_config ,
73
51
connection = connection_config ,
74
52
load_args = load_args ,
75
53
save_args = save_args ,
@@ -260,17 +238,6 @@ def test_describe_includes_backend_mode_and_materialized(self, table_dataset):
260
238
assert "database" not in desc ["load_args" ]
261
239
assert "database" not in desc ["save_args" ]
262
240
263
- @pytest .mark .parametrize (
264
- "save_args" ,
265
- [{"materialized" : "table" }],
266
- indirect = True ,
267
- )
268
- def test_save_empty_dataframe_is_noop (self , table_dataset ):
269
- """Saving an empty DataFrame should be a no-op (no table created)."""
270
- empty_table = ibis .memtable (pd .DataFrame ({"col1" : [], "col2" : [], "col3" : []}))
271
- table_dataset .save (empty_table )
272
- assert not table_dataset .exists ()
273
-
274
241
@pytest .mark .parametrize ("load_args" , [{"database" : "test" }], indirect = True )
275
242
def test_load_extra_params (self , table_dataset , load_args ):
276
243
"""Test overriding the default load arguments."""
@@ -378,100 +345,9 @@ def test_connection_config(self, mocker, table_dataset, connection_config, key):
378
345
table_dataset .load ()
379
346
assert ("ibis" , key ) in table_dataset ._connections
380
347
381
- @pytest .mark .parametrize (
382
- ("credentials_config" , "key" ),
383
- [
384
- (
385
- "postgres://xxxxxx.postgres.database.azure.com:5432/postgres" ,
386
- (
387
- ("backend" , "postgres" ),
388
- (
389
- "con" ,
390
- "postgres://xxxxxx.postgres.database.azure.com:5432/postgres" ,
391
- ),
392
- ),
393
- ),
394
- (
395
- {
396
- "con" : "postgres://[email protected] :5432/postgres"
397
- },
398
- (
399
- ("backend" , "postgres" ),
400
- (
401
- "con" ,
402
- "postgres://[email protected] :5432/postgres" ,
403
- ),
404
- ),
405
- ),
406
- (
407
- {
408
- "backend" : "postgres" ,
409
- "database" : "postgres" ,
410
- "host" : "xxxx.postgres.database.azure.com" ,
411
- },
412
- (
413
- ("backend" , "postgres" ),
414
- ("database" , "postgres" ),
415
- ("host" , "xxxx.postgres.database.azure.com" ),
416
- ),
417
- ),
418
- ],
419
- )
420
- @pytest .mark .parametrize ("connection_config" , [None ], indirect = True )
421
- def test_connection_config_with_credentials (
422
- self , mocker , table_dataset , credentials_config , key
423
- ):
424
- # 1) isolate the cache so parametrized cases don't reuse connections
425
-
426
- if isinstance (credentials_config , str ) or "backend" not in credentials_config :
427
- backend = "postgres"
428
- else :
429
- backend = credentials_config ["backend" ]
430
-
431
- mocker .patch (f"ibis.{ backend } " )
432
- conn = table_dataset .connection
433
- assert conn is not None
434
- table_dataset .load ()
435
- assert ("ibis" , key ) in table_dataset ._connections
436
-
437
348
def test_save_data_loaded_using_file_dataset (self , file_dataset , table_dataset ):
438
349
"""Test interoperability of Ibis datasets sharing a database."""
439
350
dummy_table = file_dataset .load ()
440
351
assert not table_dataset .exists ()
441
352
table_dataset .save (dummy_table )
442
353
assert table_dataset .exists ()
443
-
444
- # Additional tests for _get_backend_name branch coverage
445
- class TestGetBackendName :
446
- def test_get_backend_name_dict_with_backend (self ):
447
- ds = TableDataset (table_name = "t" )
448
- ds ._credentials = {"backend" : "postgres" , "database" : "db" }
449
- assert ds ._get_backend_name () == "postgres"
450
-
451
- def test_get_backend_name_dict_without_backend_or_con (self ):
452
- ds = TableDataset (table_name = "t" )
453
- ds ._credentials = {"user" : "u" , "password" : "p" }
454
- assert ds ._get_backend_name () is None
455
-
456
- def test_get_backend_name_string_with_scheme (self ):
457
- ds = TableDataset (table_name = "t" )
458
- ds ._credentials = "mysql://xxxxxx@host:3306/dbname"
459
- assert ds ._get_backend_name () == "mysql"
460
-
461
- def test_get_backend_name_string_without_scheme (self ):
462
- ds = TableDataset (table_name = "t" )
463
- ds ._credentials = "not_a_url_string"
464
- assert ds ._get_backend_name () is None
465
-
466
- def test_get_backend_name_dict_with_con_and_scheme (self ):
467
- ds = TableDataset (table_name = "t" )
468
- ds ._credentials = {
469
- "con" : "postgres://xxxxxx@host:5432/dbname" ,
470
- "some_other" : "value" ,
471
- }
472
- assert ds ._get_backend_name () == "postgres"
473
-
474
- def test_get_backend_name_dict_with_con_without_scheme (self ):
475
- ds = TableDataset (table_name = "t" )
476
- ds ._credentials = {"con" : "sqlite_memory" }
477
- assert ds ._get_backend_name () is None
0 commit comments