1- import unittest
1+ import os
22import os .path
3+ import shutil
4+ import tempfile
5+ import unittest
6+
37
48from tableaudocumentapi import Datasource , Workbook
59
@@ -22,6 +26,19 @@ class DataSourceFieldsTDS(unittest.TestCase):
2226
2327 def setUp (self ):
2428 self .ds = Datasource .from_file (TEST_TDS_FILE )
29+ self .to_delete = set ()
30+
31+ def cleanUp (self ):
32+ for path in self .to_delete :
33+ if os .path .isdir (path ):
34+ shutil .rmtree (path , ignore_errors = True )
35+ elif os .path .isfile (path ):
36+ os .unlink (path )
37+
38+ def get_temp_file (self , filename ):
39+ tempdir = tempfile .mkdtemp ('tda-datasource' )
40+ self .to_delete .add (tempdir )
41+ return os .path .join (tempdir , filename )
2542
2643 def test_datasource_returns_correct_fields (self ):
2744 self .assertIsNotNone (self .ds .fields )
@@ -63,6 +80,30 @@ def test_datasource_field_description(self):
6380 self .assertIsNotNone (actual )
6481 self .assertTrue (u'muted gray' in actual )
6582
83+ def test_datasource_caption (self ):
84+ actual = self .ds .caption
85+ self .assertIsNotNone (actual )
86+ self .assertEqual (actual , 'foo' )
87+
88+ def test_datasource_can_set_caption (self ):
89+ filename = self .get_temp_file ('test_datasource_can_set_caption' )
90+ self .ds .caption = 'bar'
91+ self .ds .save_as (filename )
92+
93+ actual = Datasource .from_file (filename )
94+ self .assertIsNotNone (actual )
95+ self .assertIsNotNone (actual .caption )
96+ self .assertEqual (actual .caption , 'bar' )
97+
98+ def test_datasource_can_remove_caption (self ):
99+ filename = self .get_temp_file ('test_datasource_can_remove_caption' )
100+ del self .ds .caption
101+ self .ds .save_as (filename )
102+
103+ actual = Datasource .from_file (filename )
104+ self .assertIsNotNone (actual )
105+ self .assertEqual (actual .caption , '' )
106+
66107 def test_datasource_clear_repository_location (self ):
67108 filename = os .path .join (TEST_ASSET_DIR , 'clear-repository-test.tds' )
68109
0 commit comments