| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| import unittest | ||
| import os | ||
| import os.path | ||
| import shutil | ||
| import tempfile | ||
| import unittest | ||
|
|
||
|
|
||
| from tableaudocumentapi import Datasource, Workbook | ||
|
|
||
| Expand All | @@ -22,6 +26,19 @@ class DataSourceFieldsTDS(unittest.TestCase): | |
|
|
||
| def setUp(self): | ||
| self.ds = Datasource.from_file(TEST_TDS_FILE) | ||
| self.to_delete = set() | ||
|
|
||
| def cleanUp(self): | ||
| for path in self.to_delete: | ||
| if os.path.isdir(path): | ||
| shutil.rmtree(path, ignore_errors=True) | ||
| elif os.path.isfile(path): | ||
| os.unlink(path) | ||
|
|
||
| def get_temp_file(self, filename): | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWe have 3 ways of doing temp file management now. xfile.temporary_directory has a context manager that creates and deletes a temp dir This can be another PR, maybe we want to unify them, at least across the tests?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityAgreed, I'll do a pass to create a "temp file wrapper that both library code and tests can use" along with the auto clean up base test class.
Sorry, something went wrong.
All reactions
|
||
| tempdir = tempfile.mkdtemp('tda-datasource') | ||
| self.to_delete.add(tempdir) | ||
| return os.path.join(tempdir, filename) | ||
|
|
||
| def test_datasource_returns_correct_fields(self): | ||
| self.assertIsNotNone(self.ds.fields) | ||
| Expand Down Expand Up | @@ -63,6 +80,30 @@ def test_datasource_field_description(self): | |
| self.assertIsNotNone(actual) | ||
| self.assertTrue(u'muted gray' in actual) | ||
|
|
||
| def test_datasource_caption(self): | ||
| actual = self.ds.caption | ||
| self.assertIsNotNone(actual) | ||
| self.assertEqual(actual, 'foo') | ||
|
|
||
| def test_datasource_can_set_caption(self): | ||
| filename = self.get_temp_file('test_datasource_can_set_caption') | ||
| self.ds.caption = 'bar' | ||
| self.ds.save_as(filename) | ||
|
|
||
| actual = Datasource.from_file(filename) | ||
| self.assertIsNotNone(actual) | ||
| self.assertIsNotNone(actual.caption) | ||
| self.assertEqual(actual.caption, 'bar') | ||
|
|
||
| def test_datasource_can_remove_caption(self): | ||
| filename = self.get_temp_file('test_datasource_can_remove_caption') | ||
| del self.ds.caption | ||
| self.ds.save_as(filename) | ||
|
|
||
| actual = Datasource.from_file(filename) | ||
| self.assertIsNotNone(actual) | ||
| self.assertEqual(actual.caption, '') | ||
|
|
||
| def test_datasource_clear_repository_location(self): | ||
| filename = os.path.join(TEST_ASSET_DIR, 'clear-repository-test.tds') | ||
|
|
||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityAre all datasources guaranteed to have a caption or would you ever want to remove it?
We could apply the None strategy like we do for port
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI think it's more idiomatic to do del ds.caption
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.