Skip to content
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

test: improve to_gbq logic unit test coverage #449

Merged
merged 42 commits into from
Dec 28, 2021
Merged

Conversation

tswast
Copy link
Collaborator

@tswast tswast commented Dec 20, 2021

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Towards #392 🦕

Based on #443

@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery-pandas API. label Dec 20, 2021
@tswast tswast changed the title test: improve unit test coverage test: improve to_gbq logic unit test coverage Dec 23, 2021
@tswast tswast marked this pull request as ready for review December 23, 2021 23:11
@tswast tswast requested a review from a team December 23, 2021 23:11
@tswast tswast requested a review from a team as a code owner December 23, 2021 23:11
@tswast tswast requested review from shollyman and plamut December 23, 2021 23:11
@@ -1057,7 +1063,7 @@ def to_gbq(
DeprecationWarning,
stacklevel=2,
)
elif api_method == "load_csv":
else:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already a check above for known api_methods, so this was an impossible branch.

@@ -1122,12 +1128,14 @@ def to_gbq(
)
elif if_exists == "replace":
connector.delete_and_recreate_table(dataset_id, table_id, table_schema)
elif if_exists == "append":
else:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already a check above for known if_exists, so this was an impossible branch.

if not pandas_gbq.schema.schema_is_subset(original_schema, table_schema):
raise InvalidSchema(
"Please verify that the structure and "
"data types in the DataFrame match the "
"schema of the destination table."
"schema of the destination table.",
table_schema,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Towards #349

.coveragerc Outdated
@@ -22,7 +22,7 @@ omit =
google/cloud/__init__.py

[report]
fail_under = 89
fail_under = 95
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not 100, but it's solid progress. I don't want this PR to get too long. Mostly I started working on unit tests because they're just mindless enough that I can handle it while I'm sick this week.

Copy link

@plamut plamut Dec 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to merge a meaningful piece of work into main, it doesn't have to be all-or-nothing. This PR by itself is already a significant improvement.

(I will review this tomorrow, did not manage to go through everything today)

def get_table(table_ref_or_id, **kwargs):
return google.cloud.bigquery.Table(table_ref_or_id)

mock_client.get_table.side_effect = get_table
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was messing with the to_gbq tests, so moved to test_gbq.py (and potentially to a test_read_gbq.py in future.

Copy link

@plamut plamut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, not much to add really, one or two remarks aside.

One of the system tests might need an adjustment, though, it does not look like flakiness.

pandas_gbq/gbq.py Show resolved Hide resolved
tests/unit/test_load.py Show resolved Hide resolved
@tswast tswast requested a review from plamut December 28, 2021 16:43
@tswast
Copy link
Collaborator Author

tswast commented Dec 28, 2021

I've removed the failing system test. The behavior of _Table.delete() did in fact change, but it's not a part of the public interface and the new behavior is verified by unit tests.

@tswast tswast merged commit 3ae5d4c into main Dec 28, 2021
@tswast tswast deleted the issue392-unit-test-100 branch December 28, 2021 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery-pandas API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants