-
Notifications
You must be signed in to change notification settings - Fork 182
Add caption support for datasources #99
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
||
|
@@ -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): | ||
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. We have 3 ways of doing temp file management now.
This can be another PR, maybe we want to unify them, at least across the tests? 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. Agreed, 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. |
||
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) | ||
|
@@ -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') | ||
|
||
|
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.
Are 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 portThere 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.
I think it's more idiomatic to do
del ds.caption