GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — document-api-python/test/test_datasource.py at master · bodschut/document-api-python

Expand file tree

/

test_datasource.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
166 lines (127 loc) · 5.8 KB
/

test_datasource.py

Copy path

File metadata and controls

166 lines (127 loc) · 5.8 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import os
import os.path
import shutil
import tempfile
import unittest
from tableaudocumentapi import Datasource, Workbook
TEST_ASSET_DIR = os.path.join(
os.path.dirname(__file__),
'assets'
)
TEST_TDS_FILE = os.path.join(
TEST_ASSET_DIR,
'datasource_test.tds'
)
TEST_TWB_FILE = os.path.join(
TEST_ASSET_DIR,
'datasource_test.twb'
)
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):
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)
self.assertIsNotNone(self.ds.fields.get('[Number of Records]', None))
def test_datasource_returns_calculation_from_fields(self):
self.assertEqual('1', self.ds.fields['[Number of Records]'].calculation)
def test_datasource_uses_metadata_record(self):
self.assertEqual('Sum', self.ds.fields['[x]'].default_aggregation)
def test_datasource_column_name_contains_apostrophy(self):
self.assertIsNotNone(self.ds.fields.get("[Today's Date]", None))
def test_datasource_field_can_get_caption(self):
self.assertEqual(self.ds.fields['[a]'].caption, 'A')
self.assertEqual(getattr(self.ds.fields['[a]'], 'caption', None), 'A')
def test_datasource_field_caption_can_be_used_to_query(self):
self.assertIsNotNone(self.ds.fields.get('A', None))
def test_datasource_field_is_nominal(self):
self.assertTrue(self.ds.fields['[a]'].is_nominal)
def test_datasource_field_is_quantitative(self):
self.assertTrue(self.ds.fields['[y]'].is_quantitative)
def test_datasource_field_is_ordinal(self):
self.assertTrue(self.ds.fields['[x]'].is_ordinal)
def test_datasource_field_datatype(self):
self.assertEqual(self.ds.fields['[x]'].datatype, 'integer')
def test_datasource_field_role(self):
self.assertEqual(self.ds.fields['[x]'].role, 'measure')
def test_datasource_field_description(self):
actual = self.ds.fields['[a]'].description
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')
self.assertIsNotNone(self.ds._datasourceXML.find('.//repository-location'))
self.ds.clear_repository_location()
try:
self.ds.save_as(filename)
with open(filename, 'r') as newfile:
self.assertFalse('repository-location' in newfile.read())
finally:
if os.path.exists(filename):
os.unlink(filename)
class DataSourceFieldsTWB(unittest.TestCase):
def setUp(self):
self.wb = Workbook(TEST_TWB_FILE)
# Assume the first datasource in the file
self.ds = self.wb.datasources[0]
def test_datasource_fields_loaded_in_workbook(self):
self.assertIsNotNone(self.ds.fields)
self.assertIsNotNone(self.ds.fields.get('[Number of Records]', None))
class DataSourceFieldsFoundIn(unittest.TestCase):
def setUp(self):
self.wb = Workbook(TEST_TWB_FILE)
# Assume the first datasource in the file
self.ds = self.wb.datasources[0]
def test_datasource_fields_found_in_returns_fields(self):
actual_values = self.ds.fields.used_by_sheet('Sheet 1')
self.assertIsNotNone(actual_values)
self.assertEqual(1, len(actual_values))
self.assertIn('A', (x.name for x in actual_values))
def test_datasource_fields_found_in_does_not_return_fields_not_used_in_worksheet(self):
actual_values = self.ds.fields.used_by_sheet('Sheet 1')
self.assertIsNotNone(actual_values)
self.assertEqual(1, len(actual_values))
self.assertNotIn('X', (x.name for x in actual_values))
def test_datasource_fields_found_in_returns_multiple_fields(self):
actual_values = self.ds.fields.used_by_sheet('Sheet 2')
self.assertIsNotNone(actual_values)
self.assertEqual(2, len(actual_values))
self.assertIn('A', (x.name for x in actual_values))
self.assertIn('X', (x.name for x in actual_values))
self.assertNotIn('Y', (x.name for x in actual_values))
def test_datasource_fields_found_in_accepts_lists(self):
actual_values = self.ds.fields.used_by_sheet(['Sheet 1', 'Sheet 2'])
self.assertIsNotNone(actual_values)
self.assertEqual(2, len(actual_values))
self.assertIn('A', (x.name for x in actual_values))
self.assertIn('X', (x.name for x in actual_values))
self.assertNotIn('Y', (x.name for x in actual_values))
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.