Skip to content

TST: Fix pytest.raises usage for latest pytest. Fix warnings in tests. #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions tests/system/test_gbq.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,26 +868,27 @@ def test_array_agg(self, project_id):
),
)

def test_array_of_floats(self, private_key_path, project_id):
def test_array_of_floats(self, project_id):
query = """select [1.1, 2.2, 3.3] as a, 4 as b"""
df = gbq.read_gbq(
query,
project_id=project_id,
private_key=private_key_path,
credentials=self.credentials,
dialect="standard",
)
tm.assert_frame_equal(
df, DataFrame([[[1.1, 2.2, 3.3], 4]], columns=["a", "b"])
)

def test_tokyo(self, tokyo_dataset, tokyo_table, private_key_path):
def test_tokyo(self, tokyo_dataset, tokyo_table, project_id):
df = gbq.read_gbq(
"SELECT MAX(year) AS max_year FROM {}.{}".format(
tokyo_dataset, tokyo_table
),
dialect="standard",
location="asia-northeast1",
private_key=private_key_path,
project_id=project_id,
credentials=self.credentials,
)
assert df["max_year"][0] >= 2000

Expand Down Expand Up @@ -1401,7 +1402,17 @@ def test_upload_data_with_timestamp(self, project_id):
index=range(test_size),
columns=list("ABCD"),
)
df["times"] = np.datetime64("2018-03-13T05:40:45.348318Z")
df["times"] = pandas.Series(
[
"2018-03-13T05:40:45.348318",
"2018-04-13T05:40:45.348318",
"2018-05-13T05:40:45.348318",
"2018-06-13T05:40:45.348318",
"2018-07-13T05:40:45.348318",
"2018-08-13T05:40:45.348318",
],
dtype="datetime64[ns]",
).dt.tz_localize("UTC")

gbq.to_gbq(
df,
Expand All @@ -1421,7 +1432,7 @@ def test_upload_data_with_timestamp(self, project_id):

expected = df["times"].sort_values()
result = result_df["times"].sort_values()
tm.assert_numpy_array_equal(expected.values, result.values)
tm.assert_series_equal(expected, result)

def test_upload_data_with_different_df_and_user_schema(self, project_id):
df = tm.makeMixedDataFrame()
Expand Down
12 changes: 4 additions & 8 deletions tests/unit/test_gbq.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ def test_to_gbq_with_no_project_id_given_should_fail(monkeypatch):
pydata_google_auth, "default", mock_get_credentials_no_project
)

with pytest.raises(ValueError) as exception:
with pytest.raises(ValueError, match="Could not determine project ID"):
gbq.to_gbq(DataFrame([[1]]), "dataset.tablename")
assert "Could not determine project ID" in str(exception)


def test_to_gbq_with_verbose_new_pandas_warns_deprecation(min_bq_version):
Expand Down Expand Up @@ -280,9 +279,8 @@ def test_read_gbq_with_no_project_id_given_should_fail(monkeypatch):
pydata_google_auth, "default", mock_get_credentials_no_project
)

with pytest.raises(ValueError) as exception:
with pytest.raises(ValueError, match="Could not determine project ID"):
gbq.read_gbq("SELECT 1", dialect="standard")
assert "Could not determine project ID" in str(exception)


def test_read_gbq_with_inferred_project_id(monkeypatch):
Expand Down Expand Up @@ -311,13 +309,12 @@ def test_read_gbq_with_inferred_project_id_from_service_account_credentials(
def test_read_gbq_without_inferred_project_id_from_compute_engine_credentials(
mock_compute_engine_credentials
):
with pytest.raises(ValueError) as exception:
with pytest.raises(ValueError, match="Could not determine project ID"):
gbq.read_gbq(
"SELECT 1",
dialect="standard",
credentials=mock_compute_engine_credentials,
)
assert "Could not determine project ID" in str(exception)


def test_read_gbq_with_invalid_private_key_json_should_fail():
Expand Down Expand Up @@ -469,9 +466,8 @@ def test_read_gbq_with_private_key_old_pandas_no_warnings(


def test_read_gbq_with_invalid_dialect():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError, match="is not valid for dialect"):
gbq.read_gbq("SELECT 1", dialect="invalid")
assert "is not valid for dialect" in str(excinfo.value)


def test_generate_bq_schema_deprecated():
Expand Down