Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
Add a system test for 'Table.upload_from_file'.#2313
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -288,6 +288,59 @@ def _has_rows(result): | ||
| self.assertEqual(sorted(rows, key=by_age), | ||
| sorted(ROWS, key=by_age)) | ||
| def test_load_table_from_local_file_then_dump_table(self): | ||
| import csv | ||
| import tempfile | ||
| ROWS = [ | ||
| ('Phred Phlyntstone', 32), | ||
| ('Bharney Rhubble', 33), | ||
| ('Wylma Phlyntstone', 29), | ||
| ('Bhettye Rhubble', 27), | ||
| ] | ||
| TABLE_NAME = 'test_table' | ||
| dataset = Config.CLIENT.dataset(DATASET_NAME) | ||
| retry_403(dataset.create)() | ||
| self.to_delete.append(dataset) | ||
| full_name = bigquery.SchemaField('full_name', 'STRING', | ||
| mode='REQUIRED') | ||
| age = bigquery.SchemaField('age', 'INTEGER', mode='REQUIRED') | ||
| table = dataset.table(TABLE_NAME, schema=[full_name, age]) | ||
| table.create() | ||
| self.to_delete.insert(0, table) | ||
| with tempfile.NamedTemporaryFile(mode='w+') as csv_file: | ||
| writer = csv.writer(csv_file) | ||
| writer.writerow(('Full Name', 'Age')) | ||
| writer.writerows(ROWS) | ||
| csv_file.flush() | ||
| with open(csv_file.name, 'rb') as csv_read: | ||
| job = table.upload_from_file( | ||
| csv_read, | ||
| source_format='CSV', | ||
| skip_leading_rows=1, | ||
| create_disposition='CREATE_NEVER', | ||
| write_disposition='WRITE_EMPTY', | ||
| ) | ||
| def _job_done(instance): | ||
| return instance.state.lower() == 'done' | ||
| # Retry until done. | ||
| retry = RetryInstanceState(_job_done, max_tries=8) | ||
| retry(job.reload)() | ||
| self.assertTrue(_job_done(job)) | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| self.assertEqual(job.output_rows, len(ROWS)) | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| rows, _, _ = table.fetch_data() | ||
| by_age = operator.itemgetter(1) | ||
| self.assertEqual(sorted(rows, key=by_age), | ||
| sorted(ROWS, key=by_age)) | ||
| def test_load_table_from_storage_then_dump_table(self): | ||
| import csv | ||
| import tempfile | ||
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.