@@ -375,7 +375,7 @@ def test_import_google_api_python_client(self):
375375 "using google-api-python-client==1.2" )
376376
377377 if compat .PY2 :
378- with tm . assertRaises (ImportError ):
378+ with pytest . raises (ImportError ):
379379 from googleapiclient .discovery import build # noqa
380380 from googleapiclient .errors import HttpError # noqa
381381 from apiclient .discovery import build # noqa
@@ -386,34 +386,34 @@ def test_import_google_api_python_client(self):
386386
387387 def test_should_return_bigquery_integers_as_python_ints (self ):
388388 result = gbq ._parse_entry (1 , 'INTEGER' )
389- tm . assert_equal ( result , int (1 ) )
389+ assert result == int (1 )
390390
391391 def test_should_return_bigquery_floats_as_python_floats (self ):
392392 result = gbq ._parse_entry (1 , 'FLOAT' )
393- tm . assert_equal ( result , float (1 ) )
393+ assert result == float (1 )
394394
395395 def test_should_return_bigquery_timestamps_as_numpy_datetime (self ):
396396 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' )
398398
399399 def test_should_return_bigquery_booleans_as_python_booleans (self ):
400400 result = gbq ._parse_entry ('false' , 'BOOLEAN' )
401- tm . assert_equal ( result , False )
401+ assert not result
402402
403403 def test_should_return_bigquery_strings_as_python_strings (self ):
404404 result = gbq ._parse_entry ('STRING' , 'STRING' )
405- tm . assert_equal ( result , 'STRING' )
405+ assert result == 'STRING'
406406
407407 def test_to_gbq_should_fail_if_invalid_table_name_passed (self ):
408- with tm . assertRaises (gbq .NotFoundException ):
408+ with pytest . raises (gbq .NotFoundException ):
409409 gbq .to_gbq (DataFrame (), 'invalid_table_name' , project_id = "1234" )
410410
411411 def test_to_gbq_with_no_project_id_given_should_fail (self ):
412- with tm . assertRaises (TypeError ):
412+ with pytest . raises (TypeError ):
413413 gbq .to_gbq (DataFrame (), 'dataset.tablename' )
414414
415415 def test_read_gbq_with_no_project_id_given_should_fail (self ):
416- with tm . assertRaises (TypeError ):
416+ with pytest . raises (TypeError ):
417417 gbq .read_gbq ('SELECT 1' )
418418
419419 def test_that_parse_data_works_properly (self ):
@@ -426,29 +426,29 @@ def test_that_parse_data_works_properly(self):
426426 tm .assert_frame_equal (test_output , correct_output )
427427
428428 def test_read_gbq_with_invalid_private_key_json_should_fail (self ):
429- with tm . assertRaises (gbq .InvalidPrivateKeyFormat ):
429+ with pytest . raises (gbq .InvalidPrivateKeyFormat ):
430430 gbq .read_gbq ('SELECT 1' , project_id = 'x' , private_key = 'y' )
431431
432432 def test_read_gbq_with_empty_private_key_json_should_fail (self ):
433- with tm . assertRaises (gbq .InvalidPrivateKeyFormat ):
433+ with pytest . raises (gbq .InvalidPrivateKeyFormat ):
434434 gbq .read_gbq ('SELECT 1' , project_id = 'x' , private_key = '{}' )
435435
436436 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 ):
438438 gbq .read_gbq (
439439 'SELECT 1' , project_id = 'x' ,
440440 private_key = '{ "client_email" : 1, "private_key" : True }' )
441441
442442 def test_read_gbq_with_empty_private_key_file_should_fail (self ):
443443 with tm .ensure_clean () as empty_file_path :
444- with tm . assertRaises (gbq .InvalidPrivateKeyFormat ):
444+ with pytest . raises (gbq .InvalidPrivateKeyFormat ):
445445 gbq .read_gbq ('SELECT 1' , project_id = 'x' ,
446446 private_key = empty_file_path )
447447
448448 def test_read_gbq_with_corrupted_private_key_json_should_fail (self ):
449449 _skip_if_no_private_key_contents ()
450450
451- with tm . assertRaises (gbq .InvalidPrivateKeyFormat ):
451+ with pytest . raises (gbq .InvalidPrivateKeyFormat ):
452452 gbq .read_gbq (
453453 'SELECT 1' , project_id = 'x' ,
454454 private_key = re .sub ('[a-z]' , '9' , _get_private_key_contents ()))
@@ -708,7 +708,7 @@ def test_index_column(self):
708708 private_key = _get_private_key_path ())
709709 correct_frame = DataFrame (
710710 {'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
712712
713713 def test_column_order (self ):
714714 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):
725725 col_order = ['string_aaa' , 'string_1' , 'string_2' ]
726726
727727 # Column string_aaa does not exist. Should raise InvalidColumnOrder
728- with tm . assertRaises (gbq .InvalidColumnOrder ):
728+ with pytest . raises (gbq .InvalidColumnOrder ):
729729 gbq .read_gbq (query , project_id = _get_project_id (),
730730 col_order = col_order ,
731731 private_key = _get_private_key_path ())
@@ -747,24 +747,24 @@ def test_read_gbq_raises_invalid_index_column(self):
747747 col_order = ['string_3' , 'string_2' ]
748748
749749 # Column string_bbb does not exist. Should raise InvalidIndexColumn
750- with tm . assertRaises (gbq .InvalidIndexColumn ):
750+ with pytest . raises (gbq .InvalidIndexColumn ):
751751 gbq .read_gbq (query , project_id = _get_project_id (),
752752 index_col = 'string_bbb' , col_order = col_order ,
753753 private_key = _get_private_key_path ())
754754
755755 def test_malformed_query (self ):
756- with tm . assertRaises (gbq .GenericGBQException ):
756+ with pytest . raises (gbq .GenericGBQException ):
757757 gbq .read_gbq ("SELCET * FORM [publicdata:samples.shakespeare]" ,
758758 project_id = _get_project_id (),
759759 private_key = _get_private_key_path ())
760760
761761 def test_bad_project_id (self ):
762- with tm . assertRaises (gbq .GenericGBQException ):
762+ with pytest . raises (gbq .GenericGBQException ):
763763 gbq .read_gbq ("SELECT 1" , project_id = '001' ,
764764 private_key = _get_private_key_path ())
765765
766766 def test_bad_table_name (self ):
767- with tm . assertRaises (gbq .GenericGBQException ):
767+ with pytest . raises (gbq .GenericGBQException ):
768768 gbq .read_gbq ("SELECT * FROM [publicdata:samples.nope]" ,
769769 project_id = _get_project_id (),
770770 private_key = _get_private_key_path ())
@@ -800,7 +800,7 @@ def test_legacy_sql(self):
800800
801801 # Test that a legacy sql statement fails when
802802 # setting dialect='standard'
803- with tm . assertRaises (gbq .GenericGBQException ):
803+ with pytest . raises (gbq .GenericGBQException ):
804804 gbq .read_gbq (legacy_sql , project_id = _get_project_id (),
805805 dialect = 'standard' ,
806806 private_key = _get_private_key_path ())
@@ -818,7 +818,7 @@ def test_standard_sql(self):
818818
819819 # Test that a standard sql statement fails when using
820820 # the legacy SQL dialect (default value)
821- with tm . assertRaises (gbq .GenericGBQException ):
821+ with pytest . raises (gbq .GenericGBQException ):
822822 gbq .read_gbq (standard_sql , project_id = _get_project_id (),
823823 private_key = _get_private_key_path ())
824824
@@ -834,7 +834,7 @@ def test_invalid_option_for_sql_dialect(self):
834834 "`publicdata.samples.wikipedia` LIMIT 10"
835835
836836 # Test that an invalid option for `dialect` raises ValueError
837- with tm . assertRaises (ValueError ):
837+ with pytest . raises (ValueError ):
838838 gbq .read_gbq (sql_statement , project_id = _get_project_id (),
839839 dialect = 'invalid' ,
840840 private_key = _get_private_key_path ())
@@ -874,7 +874,7 @@ def test_query_with_parameters(self):
874874 }
875875 # Test that a query that relies on parameters fails
876876 # when parameters are not supplied via configuration
877- with tm . assertRaises (ValueError ):
877+ with pytest . raises (ValueError ):
878878 gbq .read_gbq (sql_statement , project_id = _get_project_id (),
879879 private_key = _get_private_key_path ())
880880
@@ -896,7 +896,7 @@ def test_query_inside_configuration(self):
896896 }
897897 # Test that it can't pass query both
898898 # inside config and as parameter
899- with tm . assertRaises (ValueError ):
899+ with pytest . raises (ValueError ):
900900 gbq .read_gbq (query_no_use , project_id = _get_project_id (),
901901 private_key = _get_private_key_path (),
902902 configuration = config )
@@ -924,7 +924,7 @@ def test_configuration_without_query(self):
924924 }
925925 # Test that only 'query' configurations are supported
926926 # nor 'copy','load','extract'
927- with tm . assertRaises (ValueError ):
927+ with pytest . raises (ValueError ):
928928 gbq .read_gbq (sql_statement , project_id = _get_project_id (),
929929 private_key = _get_private_key_path (),
930930 configuration = config )
@@ -1034,12 +1034,12 @@ def test_upload_data_if_table_exists_fail(self):
10341034 self .table .create (TABLE_ID + test_id , gbq ._generate_bq_schema (df ))
10351035
10361036 # Test the default value of if_exists is 'fail'
1037- with tm . assertRaises (gbq .TableCreationError ):
1037+ with pytest . raises (gbq .TableCreationError ):
10381038 gbq .to_gbq (df , self .destination_table + test_id , _get_project_id (),
10391039 private_key = _get_private_key_path ())
10401040
10411041 # Test the if_exists parameter with value 'fail'
1042- with tm . assertRaises (gbq .TableCreationError ):
1042+ with pytest . raises (gbq .TableCreationError ):
10431043 gbq .to_gbq (df , self .destination_table + test_id , _get_project_id (),
10441044 if_exists = 'fail' , private_key = _get_private_key_path ())
10451045
@@ -1066,7 +1066,7 @@ def test_upload_data_if_table_exists_append(self):
10661066 assert result ['num_rows' ][0 ] == test_size * 2
10671067
10681068 # Try inserting with a different schema, confirm failure
1069- with tm . assertRaises (gbq .InvalidSchema ):
1069+ with pytest . raises (gbq .InvalidSchema ):
10701070 gbq .to_gbq (df_different_schema , self .destination_table + test_id ,
10711071 _get_project_id (), if_exists = 'append' ,
10721072 private_key = _get_private_key_path ())
@@ -1100,7 +1100,7 @@ def test_upload_data_if_table_exists_raises_value_error(self):
11001100 df = make_mixed_dataframe_v2 (test_size )
11011101
11021102 # Test invalid value for if_exists parameter raises value error
1103- with tm . assertRaises (ValueError ):
1103+ with pytest . raises (ValueError ):
11041104 gbq .to_gbq (df , self .destination_table + test_id , _get_project_id (),
11051105 if_exists = 'xxxxx' , private_key = _get_private_key_path ())
11061106
@@ -1114,7 +1114,7 @@ def test_google_upload_errors_should_raise_exception(self):
11141114 'times' : [test_timestamp , test_timestamp ]},
11151115 index = range (2 ))
11161116
1117- with tm . assertRaises (gbq .StreamingInsertError ):
1117+ with pytest . raises (gbq .StreamingInsertError ):
11181118 gbq .to_gbq (bad_df , self .destination_table + test_id ,
11191119 _get_project_id (), private_key = _get_private_key_path ())
11201120
0 commit comments