8000 Updating tests to work on Windows and Mac, Py2 and Py3. I'm manually … · Lakkichand/document-api-python@cc94371 · GitHub
[go: up one dir, main page]

Skip to content

Commit cc94371

Browse files
committed
Updating tests to work on Windows and Mac, Py2 and Py3. I'm manually managing temp files right now, but we may want to modify our Workbook and Datasource classes to accept all File-Like objects in the future so I don't have to do this filename sillyness. Still, this works for now and is cross platform
1 parent 564c172 commit cc94371

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Document API/test.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
2-
import tempfile
3-
2+
import io
3+
import os
44
import xml.etree.ElementTree as ET
55

66
from tableaudocumentapi import Workbook, Datasource, Connection
@@ -61,10 +61,14 @@ def test_can_write_attributes_to_connection(self):
6161
class DatasourceModelTests(unittest.TestCase):
6262

6363
def setUp(self):
64-
self.tds_file = tempfile.NamedTemporaryFile(suffix='.tds')
64+
self.tds_file = io.FileIO('test.tds', 'w')
6565
self.tds_file.write(TABLEAU_93_TDS.encode('utf8'))
6666
self.tds_file.seek(0)
6767

68+
def tearDown(self):
69+
self.tds_file.close()
70+
os.unlink(self.tds_file.name)
71+
6872
def test_can_extract_datasource_from_file(self):
6973
ds = Datasource.from_file(self.tds_file.name)
7074
self.assertEqual(ds.name, 'sqlserver.17u3bqc16tjtxn14e2hxh19tyvpo')
@@ -78,10 +82,14 @@ def test_can_extract_connection(self):
7882
class WorkbookModelTests(unittest.TestCase):
7983

8084
def setUp(self):
81-
self.workbook_file = tempfile.NamedTemporaryFile(suffix='.twb')
85+
self.workbook_file = io.FileIO('test.twb', 'w')
8286
self.workbook_file.write(TABLEAU_93_WORKBOOK.encode('utf8'))
8387
self.workbook_file.seek(0)
8488

89+
def tearDown(self):
90+
self.workbook_file.close()
91+
os.unlink(self.workbook_file.name)
92+
8593
def test_can_extract_datasource(self):
8694
wb = Workbook(self.workbook_file.name)
8795
self.assertEqual(len(wb.datasources), 1)

0 commit comments

Comments
 (0)
0