1616# under the License.
1717import datetime as dt
1818import gzip
19- import os
2019import pathlib
2120
2221import pyarrow as pa
@@ -45,7 +44,7 @@ def test_create_context_runtime_config_only():
4544 SessionContext (runtime = RuntimeEnvBuilder ())
4645
4746
48- @pytest .mark .parametrize ("path_to_str" , ( True , False ) )
47+ @pytest .mark .parametrize ("path_to_str" , [ True , False ] )
4948def test_runtime_configs (tmp_path , path_to_str ):
5049 path1 = tmp_path / "dir1"
5150 path2 = tmp_path / "dir2"
@@ -62,7 +61,7 @@ def test_runtime_configs(tmp_path, path_to_str):
6261 assert db is not None
6362
6463
65- @pytest .mark .parametrize ("path_to_str" , ( True , False ) )
64+ @pytest .mark .parametrize ("path_to_str" , [ True , False ] )
6665def test_temporary_files (tmp_path , path_to_str ):
6766 path = str (tmp_path ) if path_to_str else tmp_path
6867
@@ -79,14 +78,14 @@ def test_create_context_with_all_valid_args():
7978 runtime = RuntimeEnvBuilder ().with_disk_manager_os ().with_fair_spill_pool (10000000 )
8079 config = (
8180 SessionConfig ()
82- .with_create_default_catalog_and_schema (True )
81+ .with_create_default_catalog_and_schema (enabled = True )
8382 .with_default_catalog_and_schema ("foo" , "bar" )
8483 .with_target_partitions (1 )
85- .with_information_schema (True )
86- .with_repartition_joins (False )
87- .with_repartition_aggregations (False )
88- .with_repartition_windows (False )
89- .with_parquet_pruning (False )
84+ .with_information_schema (enabled = True )
85+ .with_repartition_joins (enabled = False )
86+ .with_repartition_aggregations (enabled = False )
87+ .with_repartition_windows (enabled = False )
88+ .with_parquet_pruning (enabled = False )
9089 )
9190
9291 ctx = SessionContext (config , runtime )
@@ -167,7 +166,7 @@ def test_from_arrow_table(ctx):
167166
168167def record_batch_generator (num_batches : int ):
169168 schema = pa .schema ([("a" , pa .int64 ()), ("b" , pa .int64 ())])
170- for i in range (num_batches ):
169+ for _i in range (num_batches ):
171170 yield pa .RecordBatch .from_arrays (
172171 [pa .array ([1 , 2 , 3 ]), pa .array ([4 , 5 , 6 ])], schema = schema
173172 )
@@ -492,10 +491,10 @@ def test_table_not_found(ctx):
492491
493492
494493def test_read_json (ctx ):
495- path = os . path . dirname ( os . path . abspath ( __file__ ) )
494+ path = pathlib . Path ( __file__ ). parent . resolve ( )
496495
497496 # Default
498- test_data_path = os . path . join ( path , "data_test_context" , "data.json" )
497+ test_data_path = path / "data_test_context" / "data.json"
499498 df = ctx .read_json (test_data_path )
500499 result = df .collect ()
501500
@@ -515,7 +514,7 @@ def test_read_json(ctx):
515514 assert result [0 ].schema == schema
516515
517516 # File extension
518- test_data_path = os . path . join ( path , "data_test_context" , "data.json" )
517+ test_data_path = path / "data_test_context" / "data.json"
519518 df = ctx .read_json (test_data_path , file_extension = ".json" )
520519 result = df .collect ()
521520
@@ -524,15 +523,16 @@ def test_read_json(ctx):
524523
525524
526525def test_read_json_compressed (ctx , tmp_path ):
527- path = os . path . dirname ( os . path . abspath ( __file__ ) )
528- test_data_path = os . path . join ( path , "data_test_context" , "data.json" )
526+ path = pathlib . Path ( __file__ ). parent . resolve ( )
527+ test_data_path = path / "data_test_context" / "data.json"
529528
530529 # File compression type
531530 gzip_path = tmp_path / "data.json.gz"
532531
533- with open (test_data_path , "rb" ) as csv_file :
534- with gzip .open (gzip_path , "wb" ) as gzipped_file :
535- gzipped_file .writelines (csv_file )
532+ with pathlib .Path .open (test_data_path , "rb" ) as csv_file , gzip .open (
533+ gzip_path , "wb"
534+ ) as gzipped_file :
535+ gzipped_file .writelines (csv_file )
536536
537537 df = ctx .read_json (gzip_path , file_extension = ".gz" , file_compression_type = "gz" )
538538 result = df .collect ()
@@ -563,14 +563,15 @@ def test_read_csv_list(ctx):
563563
564564
565565def test_read_csv_compressed (ctx , tmp_path ):
566- test_data_path = "testing/data/csv/aggregate_test_100.csv"
566+ test_data_path = pathlib . Path ( "testing/data/csv/aggregate_test_100.csv" )
567567
568568 # File compression type
569569 gzip_path = tmp_path / "aggregate_test_100.csv.gz"
570570
571- with open (test_data_path , "rb" ) as csv_file :
572- with gzip .open (gzip_path , "wb" ) as gzipped_file :
573- gzipped_file .writelines (csv_file )
571+ with pathlib .Path .open (test_data_path , "rb" ) as csv_file , gzip .open (
572+ gzip_path , "wb"
573+ ) as gzipped_file :
574+ gzipped_file .writelines (csv_file )
574575
575576 csv_df = ctx .read_csv (gzip_path , file_extension = ".gz" , file_compression_type = "gz" )
576577 csv_df .select (column ("c1" )).show ()
@@ -603,7 +604,7 @@ def test_create_sql_options():
603604def test_sql_with_options_no_ddl (ctx ):
604605 sql = "CREATE TABLE IF NOT EXISTS valuetable AS VALUES(1,'HELLO'),(12,'DATAFUSION')"
605606 ctx .sql (sql )
606- options = SQLOptions ().with_allow_ddl (False )
607+ options = SQLOptions ().with_allow_ddl (allow = False )
607608 with pytest .raises (Exception , match = "DDL" ):
608609 ctx .sql_with_options (sql , options = options )
609610
@@ -618,14 +619,14 @@ def test_sql_with_options_no_dml(ctx):
618619 ctx .register_dataset (table_name , dataset )
619620 sql = f'INSERT INTO "{ table_name } " VALUES (1, 2), (2, 3);'
620621 ctx .sql (sql )
621- options = SQLOptions ().with_allow_dml (False )
622+ options = SQLOptions ().with_allow_dml (allow = False )
622623 with pytest .raises (Exception , match = "DML" ):
623624 ctx .sql_with_options (sql , options = options )
624625
625626
626627def test_sql_with_options_no_statements (ctx ):
627628 sql = "SET time zone = 1;"
628629 ctx .sql (sql )
629- options = SQLOptions ().with_allow_statements (False )
630+ options = SQLOptions ().with_allow_statements (allow = False )
630631 with pytest .raises (Exception , match = "SetVariable" ):
631632 ctx .sql_with_options (sql , options = options )
0 commit comments