@@ -375,7 +375,7 @@ def test_import_google_api_python_client(self):
375
375
"using google-api-python-client==1.2" )
376
376
377
377
if compat .PY2 :
378
- with tm . assertRaises (ImportError ):
378
+ with pytest . raises (ImportError ):
379
379
from googleapiclient .discovery import build # noqa
380
380
from googleapiclient .errors import HttpError # noqa
381
381
from apiclient .discovery import build # noqa
@@ -386,34 +386,34 @@ def test_import_google_api_python_client(self):
386
386
387
387
def test_should_return_bigquery_integers_as_python_ints (self ):
388
388
result = gbq ._parse_entry (1 , 'INTEGER' )
389
- tm . assert_equal ( result , int (1 ) )
389
+ assert result == int (1 )
390
390
391
391
def test_should_return_bigquery_floats_as_python_floats (self ):
392
392
result = gbq ._parse_entry (1 , 'FLOAT' )
393
- tm . assert_equal ( result , float (1 ) )
393
+ assert result == float (1 )
394
394
395
395
def test_should_return_bigquery_timestamps_as_numpy_datetime (self ):
396
396
result = gbq ._parse_entry ('0e9' , 'TIMESTAMP' )
397
- tm . assert_equal ( result , np_datetime64_compat ('1970-01-01T00:00:00Z' ) )
397
+ assert result == np_datetime64_compat ('1970-01-01T00:00:00Z' )
398
398
399
399
def test_should_return_bigquery_booleans_as_python_booleans (self ):
400
400
result = gbq ._parse_entry ('false' , 'BOOLEAN' )
401
- tm . assert_equal ( result , False )
401
+ assert not result
402
402
403
403
def test_should_return_bigquery_strings_as_python_strings (self ):
404
404
result = gbq ._parse_entry ('STRING' , 'STRING' )
405
- tm . assert_equal ( result , 'STRING' )
405
+ assert result == 'STRING'
406
406
407
407
def test_to_gbq_should_fail_if_invalid_table_name_passed (self ):
408
- with tm . assertRaises (gbq .NotFoundException ):
408
+ with pytest . raises (gbq .NotFoundException ):
409
409
gbq .to_gbq (DataFrame (), 'invalid_table_name' , project_id = "1234" )
410
410
411
411
def test_to_gbq_with_no_project_id_given_should_fail (self ):
412
- with tm . assertRaises (TypeError ):
412
+ with pytest . raises (TypeError ):
413
413
gbq .to_gbq (DataFrame (), 'dataset.tablename' )
414
414
415
415
def test_read_gbq_with_no_project_id_given_should_fail (self ):
416
- with tm . assertRaises (TypeError ):
416
+ with pytest . raises (TypeError ):
417
417
gbq .read_gbq ('SELECT 1' )
418
418
419
419
def test_that_parse_data_works_properly (self ):
@@ -426,29 +426,29 @@ def test_that_parse_data_works_properly(self):
426
426
tm .assert_frame_equal (test_output , correct_output )
427
427
428
428
def test_read_gbq_with_invalid_private_key_json_should_fail (self ):
429
- with tm . assertRaises (gbq .InvalidPrivateKeyFormat ):
429
+ with pytest . raises (gbq .InvalidPrivateKeyFormat ):
430
430
gbq .read_gbq ('SELECT 1' , project_id = 'x' , private_key = 'y' )
431
431
432
432
def test_read_gbq_with_empty_private_key_json_should_fail (self ):
433
- with tm . assertRaises (gbq .InvalidPrivateKeyFormat ):
433
+ with pytest . raises (gbq .InvalidPrivateKeyFormat ):
434
434
gbq .read_gbq ('SELECT 1' , project_id = 'x' , private_key = '{}' )
435
435
436
436
def test_read_gbq_with_private_key_json_wrong_types_should_fail (self ):
437
- with tm . assertRaises (gbq .InvalidPrivateKeyFormat ):
437
+ with pytest . raises (gbq .InvalidPrivateKeyFormat ):
438
438
gbq .read_gbq (
439
439
'SELECT 1' , project_id = 'x' ,
440
440
private_key = '{ "client_email" : 1, "private_key" : True }' )
441
441
442
442
def test_read_gbq_with_empty_private_key_file_should_fail (self ):
443
443
with tm .ensure_clean () as empty_file_path :
444
- with tm . assertRaises (gbq .InvalidPrivateKeyFormat ):
444
+ with pytest . raises (gbq .InvalidPrivateKeyFormat ):
445
445
gbq .read_gbq ('SELECT 1' , project_id = 'x' ,
446
446
private_key = empty_file_path )
447
447
448
448
def test_read_gbq_with_corrupted_private_key_json_should_fail (self ):
449
449
_skip_if_no_private_key_contents ()
450
450
451
- with tm . assertRaises (gbq .InvalidPrivateKeyFormat ):
451
+ with pytest . raises (gbq .InvalidPrivateKeyFormat ):
452
452
gbq .read_gbq (
453
453
'SELECT 1' , project_id = 'x' ,
454
454
private_key = re .sub ('[a-z]' , '9' , _get_private_key_contents ()))
@@ -708,7 +708,7 @@ def test_index_column(self):
708
708
private_key = _get_private_key_path ())
709
709
correct_frame = DataFrame (
710
710
{'string_1' : ['a' ], 'string_2' : ['b' ]}).set_index ("string_1" )
711
- tm . assert_equal ( result_frame .index .name , correct_frame .index .name )
711
+ assert result_frame .index .name == correct_frame .index .name
712
712
713
713
def test_column_order (self ):
714
714
query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3"
@@ -725,7 +725,7 @@ def test_read_gbq_raises_invalid_column_order(self):
725
725
col_order = ['string_aaa' , 'string_1' , 'string_2' ]
726
726
727
727
# Column string_aaa does not exist. Should raise InvalidColumnOrder
728
- with tm . assertRaises (gbq .InvalidColumnOrder ):
728
+ with pytest . raises (gbq .InvalidColumnOrder ):
729
729
gbq .read_gbq (query , project_id = _get_project_id (),
730
730
col_order = col_order ,
731
731
private_key = _get_private_key_path ())
@@ -747,24 +747,24 @@ def test_read_gbq_raises_invalid_index_column(self):
747
747
col_order = ['string_3' , 'string_2' ]
748
748
749
749
# Column string_bbb does not exist. Should raise InvalidIndexColumn
750
- with tm . assertRaises (gbq .InvalidIndexColumn ):
750
+ with pytest . raises (gbq .InvalidIndexColumn ):
751
751
gbq .read_gbq (query , project_id = _get_project_id (),
752
752
index_col = 'string_bbb' , col_order = col_order ,
753
753
private_key = _get_private_key_path ())
754
754
755
755
def test_malformed_query (self ):
756
- with tm . assertRaises (gbq .GenericGBQException ):
756
+ with pytest . raises (gbq .GenericGBQException ):
757
757
gbq .read_gbq ("SELCET * FORM [publicdata:samples.shakespeare]" ,
758
758
project_id = _get_project_id (),
759
759
private_key = _get_private_key_path ())
760
760
761
761
def test_bad_project_id (self ):
762
- with tm . assertRaises (gbq .GenericGBQException ):
762
+ with pytest . raises (gbq .GenericGBQException ):
763
763
gbq .read_gbq ("SELECT 1" , project_id = '001' ,
764
764
private_key = _get_private_key_path ())
765
765
766
766
def test_bad_table_name (self ):
767
- with tm . assertRaises (gbq .GenericGBQException ):
767
+ with pytest . raises (gbq .GenericGBQException ):
768
768
gbq .read_gbq ("SELECT * FROM [publicdata:samples.nope]" ,
769
769
project_id = _get_project_id (),
770
770
private_key = _get_private_key_path ())
@@ -800,7 +800,7 @@ def test_legacy_sql(self):
800
800
801
801
# Test that a legacy sql statement fails when
802
802
# setting dialect='standard'
803
- with tm . assertRaises (gbq .GenericGBQException ):
803
+ with pytest . raises (gbq .GenericGBQException ):
804
804
gbq .read_gbq (legacy_sql , project_id = _get_project_id (),
805
805
dialect = 'standard' ,
806
806
private_key = _get_private_key_path ())
@@ -818,7 +818,7 @@ def test_standard_sql(self):
818
818
819
819
# Test that a standard sql statement fails when using
820
820
# the legacy SQL dialect (default value)
821
- with tm . assertRaises (gbq .GenericGBQException ):
821
+ with pytest . raises (gbq .GenericGBQException ):
822
822
gbq .read_gbq (standard_sql , project_id = _get_project_id (),
823
823
private_key = _get_private_key_path ())
824
824
@@ -834,7 +834,7 @@ def test_invalid_option_for_sql_dialect(self):
834
834
"`publicdata.samples.wikipedia` LIMIT 10"
835
835
836
836
# Test that an invalid option for `dialect` raises ValueError
837
- with tm . assertRaises (ValueError ):
837
+ with pytest . raises (ValueError ):
838
838
gbq .read_gbq (sql_statement , project_id = _get_project_id (),
839
839
dialect = 'invalid' ,
840
840
private_key = _get_private_key_path ())
@@ -874,7 +874,7 @@ def test_query_with_parameters(self):
874
874
}
875
875
# Test that a query that relies on parameters fails
876
876
# when parameters are not supplied via configuration
877
- with tm . assertRaises (ValueError ):
877
+ with pytest . raises (ValueError ):
878
878
gbq .read_gbq (sql_statement , project_id = _get_project_id (),
879
879
private_key = _get_private_key_path ())
880
880
@@ -896,7 +896,7 @@ def test_query_inside_configuration(self):
896
896
}
897
897
# Test that it can't pass query both
898
898
# inside config and as parameter
899
- with tm . assertRaises (ValueError ):
899
+ with pytest . raises (ValueError ):
900
900
gbq .read_gbq (query_no_use , project_id = _get_project_id (),
901
901
private_key = _get_private_key_path (),
902
902
configuration = config )
@@ -924,7 +924,7 @@ def test_configuration_without_query(self):
924
924
}
925
925
# Test that only 'query' configurations are supported
926
926
# nor 'copy','load','extract'
927
- with tm . assertRaises (ValueError ):
927
+ with pytest . raises (ValueError ):
928
928
gbq .read_gbq (sql_statement , project_id = _get_project_id (),
929
929
private_key = _get_private_key_path (),
930
930
configuration = config )
@@ -1034,12 +1034,12 @@ def test_upload_data_if_table_exists_fail(self):
1034
1034
self .table .create (TABLE_ID + test_id , gbq ._generate_bq_schema (df ))
1035
1035
1036
1036
# Test the default value of if_exists is 'fail'
1037
- with tm . assertRaises (gbq .TableCreationError ):
1037
+ with pytest . raises (gbq .TableCreationError ):
1038
1038
gbq .to_gbq (df , self .destination_table + test_id , _get_project_id (),
1039
1039
private_key = _get_private_key_path ())
1040
1040
1041
1041
# Test the if_exists parameter with value 'fail'
1042
- with tm . assertRaises (gbq .TableCreationError ):
1042
+ with pytest . raises (gbq .TableCreationError ):
1043
1043
gbq .to_gbq (df , self .destination_table + test_id , _get_project_id (),
1044
1044
if_exists = 'fail' , private_key = _get_private_key_path ())
1045
1045
@@ -1066,7 +1066,7 @@ def test_upload_data_if_table_exists_append(self):
1066
1066
assert result ['num_rows' ][0 ] == test_size * 2
1067
1067
1068
1068
# Try inserting with a different schema, confirm failure
1069
- with tm . assertRaises (gbq .InvalidSchema ):
1069
+ with pytest . raises (gbq .InvalidSchema ):
1070
1070
gbq .to_gbq (df_different_schema , self .destination_table + test_id ,
1071
1071
_get_project_id (), if_exists = 'append' ,
1072
1072
private_key = _get_private_key_path ())
@@ -1100,7 +1100,7 @@ def test_upload_data_if_table_exists_raises_value_error(self):
1100
1100
df = make_mixed_dataframe_v2 (test_size )
1101
1101
1102
1102
# Test invalid value for if_exists parameter raises value error
1103
- with tm . assertRaises (ValueError ):
1103
+ with pytest . raises (ValueError ):
1104
1104
gbq .to_gbq (df , self .destination_table + test_id , _get_project_id (),
1105
1105
if_exists = 'xxxxx' , private_key = _get_private_key_path ())
1106
1106
@@ -1114,7 +1114,7 @@ def test_google_upload_errors_should_raise_exception(self):
1114
1114
'times' : [test_timestamp , test_timestamp ]},
1115
1115
index = range (2 ))
1116
1116
1117
- with tm . assertRaises (gbq .StreamingInsertError ):
1117
+ with pytest . raises (gbq .StreamingInsertError ):
1118
1118
gbq .to_gbq (bad_df , self .destination_table + test_id ,
1119
1119
_get_project_id (), private_key = _get_private_key_path ())
1120
1120
0 commit comments