99import  logging 
1010
1111import  numpy  as  np 
12+ import  pytest 
1213
1314from  distutils .version  import  StrictVersion 
1415from  pandas  import  compat 
@@ -375,7 +376,7 @@ def test_import_google_api_python_client(self):
375376                        "using google-api-python-client==1.2" )
376377
377378        if  compat .PY2 :
378-             with  tm . assertRaises (ImportError ):
379+             with  pytest . raises (ImportError ):
379380                from  googleapiclient .discovery  import  build   # noqa 
380381                from  googleapiclient .errors  import  HttpError   # noqa 
381382            from  apiclient .discovery  import  build   # noqa 
@@ -405,15 +406,15 @@ def test_should_return_bigquery_strings_as_python_strings(self):
405406        tm .assert_equal (result , 'STRING' )
406407
407408    def  test_to_gbq_should_fail_if_invalid_table_name_passed (self ):
408-         with  tm . assertRaises (gbq .NotFoundException ):
409+         with  pytest . raises (gbq .NotFoundException ):
409410            gbq .to_gbq (DataFrame (), 'invalid_table_name' , project_id = "1234" )
410411
411412    def  test_to_gbq_with_no_project_id_given_should_fail (self ):
412-         with  tm . assertRaises (TypeError ):
413+         with  pytest . raises (TypeError ):
413414            gbq .to_gbq (DataFrame (), 'dataset.tablename' )
414415
415416    def  test_read_gbq_with_no_project_id_given_should_fail (self ):
416-         with  tm . assertRaises (TypeError ):
417+         with  pytest . raises (TypeError ):
417418            gbq .read_gbq ('SELECT 1' )
418419
419420    def  test_that_parse_data_works_properly (self ):
@@ -426,29 +427,29 @@ def test_that_parse_data_works_properly(self):
426427        tm .assert_frame_equal (test_output , correct_output )
427428
428429    def  test_read_gbq_with_invalid_private_key_json_should_fail (self ):
429-         with  tm . assertRaises (gbq .InvalidPrivateKeyFormat ):
430+         with  pytest . raises (gbq .InvalidPrivateKeyFormat ):
430431            gbq .read_gbq ('SELECT 1' , project_id = 'x' , private_key = 'y' )
431432
432433    def  test_read_gbq_with_empty_private_key_json_should_fail (self ):
433-         with  tm . assertRaises (gbq .InvalidPrivateKeyFormat ):
434+         with  pytest . raises (gbq .InvalidPrivateKeyFormat ):
434435            gbq .read_gbq ('SELECT 1' , project_id = 'x' , private_key = '{}' )
435436
436437    def  test_read_gbq_with_private_key_json_wrong_types_should_fail (self ):
437-         with  tm . assertRaises (gbq .InvalidPrivateKeyFormat ):
438+         with  pytest . raises (gbq .InvalidPrivateKeyFormat ):
438439            gbq .read_gbq (
439440                'SELECT 1' , project_id = 'x' ,
440441                private_key = '{ "client_email" : 1, "private_key" : True }' )
441442
442443    def  test_read_gbq_with_empty_private_key_file_should_fail (self ):
443444        with  tm .ensure_clean () as  empty_file_path :
444-             with  tm . assertRaises (gbq .InvalidPrivateKeyFormat ):
445+             with  pytest . raises (gbq .InvalidPrivateKeyFormat ):
445446                gbq .read_gbq ('SELECT 1' , project_id = 'x' ,
446447                             private_key = empty_file_path )
447448
448449    def  test_read_gbq_with_corrupted_private_key_json_should_fail (self ):
449450        _skip_if_no_private_key_contents ()
450451
451-         with  tm . assertRaises (gbq .InvalidPrivateKeyFormat ):
452+         with  pytest . raises (gbq .InvalidPrivateKeyFormat ):
452453            gbq .read_gbq (
453454                'SELECT 1' , project_id = 'x' ,
454455                private_key = re .sub ('[a-z]' , '9' , _get_private_key_contents ()))
@@ -725,7 +726,7 @@ def test_read_gbq_raises_invalid_column_order(self):
725726        col_order  =  ['string_aaa' , 'string_1' , 'string_2' ]
726727
727728        # Column string_aaa does not exist. Should raise InvalidColumnOrder 
728-         with  tm . assertRaises (gbq .InvalidColumnOrder ):
729+         with  pytest . raises (gbq .InvalidColumnOrder ):
729730            gbq .read_gbq (query , project_id = _get_project_id (),
730731                         col_order = col_order ,
731732                         private_key = _get_private_key_path ())
@@ -747,24 +748,24 @@ def test_read_gbq_raises_invalid_index_column(self):
747748        col_order  =  ['string_3' , 'string_2' ]
748749
749750        # Column string_bbb does not exist. Should raise InvalidIndexColumn 
750-         with  tm . assertRaises (gbq .InvalidIndexColumn ):
751+         with  pytest . raises (gbq .InvalidIndexColumn ):
751752            gbq .read_gbq (query , project_id = _get_project_id (),
752753                         index_col = 'string_bbb' , col_order = col_order ,
753754                         private_key = _get_private_key_path ())
754755
755756    def  test_malformed_query (self ):
756-         with  tm . assertRaises (gbq .GenericGBQException ):
757+         with  pytest . raises (gbq .GenericGBQException ):
757758            gbq .read_gbq ("SELCET * FORM [publicdata:samples.shakespeare]" ,
758759                         project_id = _get_project_id (),
759760                         private_key = _get_private_key_path ())
760761
761762    def  test_bad_project_id (self ):
762-         with  tm . assertRaises (gbq .GenericGBQException ):
763+         with  pytest . raises (gbq .GenericGBQException ):
763764            gbq .read_gbq ("SELECT 1" , project_id = '001' ,
764765                         private_key = _get_private_key_path ())
765766
766767    def  test_bad_table_name (self ):
767-         with  tm . assertRaises (gbq .GenericGBQException ):
768+         with  pytest . raises (gbq .GenericGBQException ):
768769            gbq .read_gbq ("SELECT * FROM [publicdata:samples.nope]" ,
769770                         project_id = _get_project_id (),
770771                         private_key = _get_private_key_path ())
@@ -800,7 +801,7 @@ def test_legacy_sql(self):
800801
801802        # Test that a legacy sql statement fails when 
802803        # setting dialect='standard' 
803-         with  tm . assertRaises (gbq .GenericGBQException ):
804+         with  pytest . raises (gbq .GenericGBQException ):
804805            gbq .read_gbq (legacy_sql , project_id = _get_project_id (),
805806                         dialect = 'standard' ,
806807                         private_key = _get_private_key_path ())
@@ -818,7 +819,7 @@ def test_standard_sql(self):
818819
819820        # Test that a standard sql statement fails when using 
820821        # the legacy SQL dialect (default value) 
821-         with  tm . assertRaises (gbq .GenericGBQException ):
822+         with  pytest . raises (gbq .GenericGBQException ):
822823            gbq .read_gbq (standard_sql , project_id = _get_project_id (),
823824                         private_key = _get_private_key_path ())
824825
@@ -834,7 +835,7 @@ def test_invalid_option_for_sql_dialect(self):
834835                        "`publicdata.samples.wikipedia` LIMIT 10" 
835836
836837        # Test that an invalid option for `dialect` raises ValueError 
837-         with  tm . assertRaises (ValueError ):
838+         with  pytest . raises (ValueError ):
838839            gbq .read_gbq (sql_statement , project_id = _get_project_id (),
839840                         dialect = 'invalid' ,
840841                         private_key = _get_private_key_path ())
@@ -874,7 +875,7 @@ def test_query_with_parameters(self):
874875        }
875876        # Test that a query that relies on parameters fails 
876877        # when parameters are not supplied via configuration 
877-         with  tm . assertRaises (ValueError ):
878+         with  pytest . raises (ValueError ):
878879            gbq .read_gbq (sql_statement , project_id = _get_project_id (),
879880                         private_key = _get_private_key_path ())
880881
@@ -896,7 +897,7 @@ def test_query_inside_configuration(self):
896897        }
897898        # Test that it can't pass query both 
898899        # inside config and as parameter 
899-         with  tm . assertRaises (ValueError ):
900+         with  pytest . raises (ValueError ):
900901            gbq .read_gbq (query_no_use , project_id = _get_project_id (),
901902                         private_key = _get_private_key_path (),
902903                         configuration = config )
@@ -924,7 +925,7 @@ def test_configuration_without_query(self):
924925        }
925926        # Test that only 'query' configurations are supported 
926927        # nor 'copy','load','extract' 
927-         with  tm . assertRaises (ValueError ):
928+         with  pytest . raises (ValueError ):
928929            gbq .read_gbq (sql_statement , project_id = _get_project_id (),
929930                         private_key = _get_private_key_path (),
930931                         configuration = config )
@@ -1034,12 +1035,12 @@ def test_upload_data_if_table_exists_fail(self):
10341035        self .table .create (TABLE_ID  +  test_id , gbq ._generate_bq_schema (df ))
10351036
10361037        # Test the default value of if_exists is 'fail' 
1037-         with  tm . assertRaises (gbq .TableCreationError ):
1038+         with  pytest . raises (gbq .TableCreationError ):
10381039            gbq .to_gbq (df , self .destination_table  +  test_id , _get_project_id (),
10391040                       private_key = _get_private_key_path ())
10401041
10411042        # Test the if_exists parameter with value 'fail' 
1042-         with  tm . assertRaises (gbq .TableCreationError ):
1043+         with  pytest . raises (gbq .TableCreationError ):
10431044            gbq .to_gbq (df , self .destination_table  +  test_id , _get_project_id (),
10441045                       if_exists = 'fail' , private_key = _get_private_key_path ())
10451046
@@ -1066,7 +1067,7 @@ def test_upload_data_if_table_exists_append(self):
10661067        assert  result ['num_rows' ][0 ] ==  test_size  *  2 
10671068
10681069        # Try inserting with a different schema, confirm failure 
1069-         with  tm . assertRaises (gbq .InvalidSchema ):
1070+         with  pytest . raises (gbq .InvalidSchema ):
10701071            gbq .to_gbq (df_different_schema , self .destination_table  +  test_id ,
10711072                       _get_project_id (), if_exists = 'append' ,
10721073                       private_key = _get_private_key_path ())
@@ -1100,7 +1101,7 @@ def test_upload_data_if_table_exists_raises_value_error(self):
11001101        df  =  make_mixed_dataframe_v2 (test_size )
11011102
11021103        # Test invalid value for if_exists parameter raises value error 
1103-         with  tm . assertRaises (ValueError ):
1104+         with  pytest . raises (ValueError ):
11041105            gbq .to_gbq (df , self .destination_table  +  test_id , _get_project_id (),
11051106                       if_exists = 'xxxxx' , private_key = _get_private_key_path ())
11061107
@@ -1114,7 +1115,7 @@ def test_google_upload_errors_should_raise_exception(self):
11141115                            'times' : [test_timestamp , test_timestamp ]},
11151116                           index = range (2 ))
11161117
1117-         with  tm . assertRaises (gbq .StreamingInsertError ):
1118+         with  pytest . raises (gbq .StreamingInsertError ):
11181119            gbq .to_gbq (bad_df , self .destination_table  +  test_id ,
11191120                       _get_project_id (), private_key = _get_private_key_path ())
11201121
0 commit comments