Skip to content

Commit ff265c5

Browse files
committed
MAINT: pandas.util.testing.assertRaises removed
This method was removed in pandas-dev/pandas#16089 in favor of pytest.raises.
1 parent f9e3b70 commit ff265c5

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

pandas_gbq/tests/test_gbq.py

+26-25
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import logging
1010

1111
import numpy as np
12+
import pytest
1213

1314
from distutils.version import StrictVersion
1415
from pandas import compat
@@ -403,7 +404,7 @@ def test_import_google_api_python_client(self):
403404
"using google-api-python-client==1.2")
404405

405406
if compat.PY2:
406-
with tm.assertRaises(ImportError):
407+
with pytest.raises(ImportError):
407408
from googleapiclient.discovery import build # noqa
408409
from googleapiclient.errors import HttpError # noqa
409410
from apiclient.discovery import build # noqa
@@ -433,15 +434,15 @@ def test_should_return_bigquery_strings_as_python_strings(self):
433434
tm.assert_equal(result, 'STRING')
434435

435436
def test_to_gbq_should_fail_if_invalid_table_name_passed(self):
436-
with tm.assertRaises(gbq.NotFoundException):
437+
with pytest.raises(gbq.NotFoundException):
437438
gbq.to_gbq(DataFrame(), 'invalid_table_name', project_id="1234")
438439

439440
def test_to_gbq_with_no_project_id_given_should_fail(self):
440-
with tm.assertRaises(TypeError):
441+
with pytest.raises(TypeError):
441442
gbq.to_gbq(DataFrame(), 'dataset.tablename')
442443

443444
def test_read_gbq_with_no_project_id_given_should_fail(self):
444-
with tm.assertRaises(TypeError):
445+
with pytest.raises(TypeError):
445446
gbq.read_gbq('SELECT 1')
446447

447448
def test_that_parse_data_works_properly(self):
@@ -454,29 +455,29 @@ def test_that_parse_data_works_properly(self):
454455
tm.assert_frame_equal(test_output, correct_output)
455456

456457
def test_read_gbq_with_invalid_private_key_json_should_fail(self):
457-
with tm.assertRaises(gbq.InvalidPrivateKeyFormat):
458+
with pytest.raises(gbq.InvalidPrivateKeyFormat):
458459
gbq.read_gbq('SELECT 1', project_id='x', private_key='y')
459460

460461
def test_read_gbq_with_empty_private_key_json_should_fail(self):
461-
with tm.assertRaises(gbq.InvalidPrivateKeyFormat):
462+
with pytest.raises(gbq.InvalidPrivateKeyFormat):
462463
gbq.read_gbq('SELECT 1', project_id='x', private_key='{}')
463464

464465
def test_read_gbq_with_private_key_json_wrong_types_should_fail(self):
465-
with tm.assertRaises(gbq.InvalidPrivateKeyFormat):
466+
with pytest.raises(gbq.InvalidPrivateKeyFormat):
466467
gbq.read_gbq(
467468
'SELECT 1', project_id='x',
468469
private_key='{ "client_email" : 1, "private_key" : True }')
469470

470471
def test_read_gbq_with_empty_private_key_file_should_fail(self):
471472
with tm.ensure_clean() as empty_file_path:
472-
with tm.assertRaises(gbq.InvalidPrivateKeyFormat):
473+
with pytest.raises(gbq.InvalidPrivateKeyFormat):
473474
gbq.read_gbq('SELECT 1', project_id='x',
474475
private_key=empty_file_path)
475476

476477
def test_read_gbq_with_corrupted_private_key_json_should_fail(self):
477478
_skip_if_no_private_key_contents()
478479

479-
with tm.assertRaises(gbq.InvalidPrivateKeyFormat):
480+
with pytest.raises(gbq.InvalidPrivateKeyFormat):
480481
gbq.read_gbq(
481482
'SELECT 1', project_id='x',
482483
private_key=re.sub('[a-z]', '9', _get_private_key_contents()))
@@ -753,7 +754,7 @@ def test_read_gbq_raises_invalid_column_order(self):
753754
col_order = ['string_aaa', 'string_1', 'string_2']
754755

755756
# Column string_aaa does not exist. Should raise InvalidColumnOrder
756-
with tm.assertRaises(gbq.InvalidColumnOrder):
757+
with pytest.raises(gbq.InvalidColumnOrder):
757758
gbq.read_gbq(query, project_id=_get_project_id(),
758759
col_order=col_order,
759760
private_key=_get_private_key_path())
@@ -775,24 +776,24 @@ def test_read_gbq_raises_invalid_index_column(self):
775776
col_order = ['string_3', 'string_2']
776777

777778
# Column string_bbb does not exist. Should raise InvalidIndexColumn
778-
with tm.assertRaises(gbq.InvalidIndexColumn):
779+
with pytest.raises(gbq.InvalidIndexColumn):
779780
gbq.read_gbq(query, project_id=_get_project_id(),
780781
index_col='string_bbb', col_order=col_order,
781782
private_key=_get_private_key_path())
782783

783784
def test_malformed_query(self):
784-
with tm.assertRaises(gbq.GenericGBQException):
785+
with pytest.raises(gbq.GenericGBQException):
785786
gbq.read_gbq("SELCET * FORM [publicdata:samples.shakespeare]",
786787
project_id=_get_project_id(),
787788
private_key=_get_private_key_path())
788789

789790
def test_bad_project_id(self):
790-
with tm.assertRaises(gbq.GenericGBQException):
791+
with pytest.raises(gbq.GenericGBQException):
791792
gbq.read_gbq("SELECT 1", project_id='001',
792793
private_key=_get_private_key_path())
793794

794795
def test_bad_table_name(self):
795-
with tm.assertRaises(gbq.GenericGBQException):
796+
with pytest.raises(gbq.GenericGBQException):
796797
gbq.read_gbq("SELECT * FROM [publicdata:samples.nope]",
797798
project_id=_get_project_id(),
798799
private_key=_get_private_key_path())
@@ -828,7 +829,7 @@ def test_legacy_sql(self):
828829

829830
# Test that a legacy sql statement fails when
830831
# setting dialect='standard'
831-
with tm.assertRaises(gbq.GenericGBQException):
832+
with pytest.raises(gbq.GenericGBQException):
832833
gbq.read_gbq(legacy_sql, project_id=_get_project_id(),
833834
dialect='standard',
834835
private_key=_get_private_key_path())
@@ -846,7 +847,7 @@ def test_standard_sql(self):
846847

847848
# Test that a standard sql statement fails when using
848849
# the legacy SQL dialect (default value)
849-
with tm.assertRaises(gbq.GenericGBQException):
850+
with pytest.raises(gbq.GenericGBQException):
850851
gbq.read_gbq(standard_sql, project_id=_get_project_id(),
851852
private_key=_get_private_key_path())
852853

@@ -862,7 +863,7 @@ def test_invalid_option_for_sql_dialect(self):
862863
"`publicdata.samples.wikipedia` LIMIT 10"
863864

864865
# Test that an invalid option for `dialect` raises ValueError
865-
with tm.assertRaises(ValueError):
866+
with pytest.raises(ValueError):
866867
gbq.read_gbq(sql_statement, project_id=_get_project_id(),
867868
dialect='invalid',
868869
private_key=_get_private_key_path())
@@ -902,7 +903,7 @@ def test_query_with_parameters(self):
902903
}
903904
# Test that a query that relies on parameters fails
904905
# when parameters are not supplied via configuration
905-
with tm.assertRaises(ValueError):
906+
with pytest.raises(ValueError):
906907
gbq.read_gbq(sql_statement, project_id=_get_project_id(),
907908
private_key=_get_private_key_path())
908909

@@ -924,7 +925,7 @@ def test_query_inside_configuration(self):
924925
}
925926
# Test that it can't pass query both
926927
# inside config and as parameter
927-
with tm.assertRaises(ValueError):
928+
with pytest.raises(ValueError):
928929
gbq.read_gbq(query_no_use, project_id=_get_project_id(),
929930
private_key=_get_private_key_path(),
930931
configuration=config)
@@ -952,7 +953,7 @@ def test_configuration_without_query(self):
952953
}
953954
# Test that only 'query' configurations are supported
954955
# nor 'copy','load','extract'
955-
with tm.assertRaises(ValueError):
956+
with pytest.raises(ValueError):
956957
gbq.read_gbq(sql_statement, project_id=_get_project_id(),
957958
private_key=_get_private_key_path(),
958959
configuration=config)
@@ -1062,12 +1063,12 @@ def test_upload_data_if_table_exists_fail(self):
10621063
self.table.create(TABLE_ID + test_id, gbq._generate_bq_schema(df))
10631064

10641065
# Test the default value of if_exists is 'fail'
1065-
with tm.assertRaises(gbq.TableCreationError):
1066+
with pytest.raises(gbq.TableCreationError):
10661067
gbq.to_gbq(df, self.destination_table + test_id, _get_project_id(),
10671068
private_key=_get_private_key_path())
10681069

10691070
# Test the if_exists parameter with value 'fail'
1070-
with tm.assertRaises(gbq.TableCreationError):
1071+
with pytest.raises(gbq.TableCreationError):
10711072
gbq.to_gbq(df, self.destination_table + test_id, _get_project_id(),
10721073
if_exists='fail', private_key=_get_private_key_path())
10731074

@@ -1094,7 +1095,7 @@ def test_upload_data_if_table_exists_append(self):
10941095
assert result['num_rows'][0] == test_size * 2
10951096

10961097
# Try inserting with a different schema, confirm failure
1097-
with tm.assertRaises(gbq.InvalidSchema):
1098+
with pytest.raises(gbq.InvalidSchema):
10981099
gbq.to_gbq(df_different_schema, self.destination_table + test_id,
10991100
_get_project_id(), if_exists='append',
11001101
private_key=_get_private_key_path())
@@ -1128,7 +1129,7 @@ def test_upload_data_if_table_exists_raises_value_error(self):
11281129
df = make_mixed_dataframe_v2(test_size)
11291130

11301131
# Test invalid value for if_exists parameter raises value error
1131-
with tm.assertRaises(ValueError):
1132+
with pytest.raises(ValueError):
11321133
gbq.to_gbq(df, self.destination_table + test_id, _get_project_id(),
11331134
if_exists='xxxxx', private_key=_get_private_key_path())
11341135

@@ -1142,7 +1143,7 @@ def test_google_upload_errors_should_raise_exception(self):
11421143
'times': [test_timestamp, test_timestamp]},
11431144
index=range(2))
11441145

1145-
with tm.assertRaises(gbq.StreamingInsertError):
1146+
with pytest.raises(gbq.StreamingInsertError):
11461147
gbq.to_gbq(bad_df, self.destination_table + test_id,
11471148
_get_project_id(), private_key=_get_private_key_path())
11481149

0 commit comments

Comments
 (0)