diff --git a/tableaudocumentapi/datasource.py b/tableaudocumentapi/datasource.py index 09860b4..b762f62 100644 --- a/tableaudocumentapi/datasource.py +++ b/tableaudocumentapi/datasource.py @@ -19,7 +19,7 @@ # dropped, remove this and change the basestring references below to str try: basestring -except NameError: +except NameError: # pragma: no cover basestring = str ######## diff --git a/tableaudocumentapi/field.py b/tableaudocumentapi/field.py index 4af648f..711e772 100644 --- a/tableaudocumentapi/field.py +++ b/tableaudocumentapi/field.py @@ -42,8 +42,10 @@ def __init__(self, column_xml=None, metadata_xml=None): if column_xml is not None: self._initialize_from_column_xml(column_xml) - if metadata_xml is not None: - self.apply_metadata(metadata_xml) + # This isn't currently never called because of the way we get the data from the xml, + # but during the refactor, we might need it. This is commented out as a reminder + # if metadata_xml is not None: + # self.apply_metadata(metadata_xml) elif metadata_xml is not None: self._initialize_from_metadata_xml(metadata_xml) diff --git a/tableaudocumentapi/multilookup_dict.py b/tableaudocumentapi/multilookup_dict.py index 6677b07..732b7da 100644 --- a/tableaudocumentapi/multilookup_dict.py +++ b/tableaudocumentapi/multilookup_dict.py @@ -13,6 +13,7 @@ def _resolve_value(key, value): if retval is None: retval = getattr(value, key, None) except AttributeError: + # We should never hit this. retval = None return retval @@ -50,13 +51,6 @@ def _get_real_key(self, key): def __setitem__(self, key, value): real_key = self._get_real_key(key) - alias = _resolve_value('alias', value) - caption = _resolve_value('caption', value) - if alias is not None: - self._indexes['alias'][alias] = real_key - if caption is not None: - self._indexes['caption'][caption] = real_key - dict.__setitem__(self, real_key, value) def get(self, key, default_value=_no_default_value): diff --git a/test/assets/BadZip.zip b/test/assets/BadZip.zip new file mode 100644 index 0000000..9eca08f Binary files /dev/null and b/test/assets/BadZip.zip differ diff --git a/test/bvt.py b/test/bvt.py index ce96afe..e8870d0 100644 --- a/test/bvt.py +++ b/test/bvt.py @@ -201,6 +201,14 @@ def test_can_extract_datasource(self): self.assertEqual(wb.datasources[0].name, 'sqlserver.17u3bqc16tjtxn14e2hxh19tyvpo') + def test_can_get_worksheets(self): + wb = Workbook(self.workbook_file.name) + self.assertIsNotNone(wb.worksheets) + + def test_has_filename(self): + wb = Workbook(self.workbook_file.name) + self.assertEqual(wb.filename, self.workbook_file.name) + def test_can_update_datasource_connection_and_save(self): original_wb = Workbook(self.workbook_file.name) original_wb.datasources[0].connections[0].dbname = 'newdb.test.tsi.lan' diff --git a/test/test_field.py b/test/test_field.py new file mode 100644 index 0000000..7cbe885 --- /dev/null +++ b/test/test_field.py @@ -0,0 +1,29 @@ +import unittest +import os.path + +from tableaudocumentapi import Datasource, Field +from tableaudocumentapi.field import _find_metadata_record + +TEST_ASSET_DIR = os.path.join( + os.path.dirname(__file__), + 'assets' +) +TEST_TDS_FILE = os.path.join( + TEST_ASSET_DIR, + 'datasource_test.tds' +) + + +class FieldsUnitTest(unittest.TestCase): + def test_field_throws_if_no_data_passed_in(self): + with self.assertRaises(AttributeError): + Field() + + +class FindMetaDataRecordEdgeTest(unittest.TestCase): + class MockXmlWithNoFind(object): + def find(self, *args, **kwargs): + return None + + def test_find_metadata_record_returns_none(self): + self.assertIsNone(_find_metadata_record(self.MockXmlWithNoFind(), 'foo')) diff --git a/test/test_multidict.py b/test/test_multidict.py index 4544c49..21ecdc6 100644 --- a/test/test_multidict.py +++ b/test/test_multidict.py @@ -22,6 +22,10 @@ def setUp(self): } }) + def test_multilookupdict_can_be_empty(self): + mld = MultiLookupDict() + self.assertIsNotNone(mld) + def test_multilookupdict_name_only(self): actual = self.mld['[baz]'] self.assertEqual(3, actual['value']) @@ -70,3 +74,7 @@ def test_multilookupdict_can_set_item(self): def test_multilookupdict_can_set_new_item(self): self.mld['wakka'] = 1 self.assertEqual(1, self.mld['wakka']) + + def test_multilookupdict_can_set_with_alias(self): + self.mld['bar'] = 2 + self.assertEqual(2, self.mld['[foo]']) diff --git a/test/test_xfile.py b/test/test_xfile.py new file mode 100644 index 0000000..6cbe67f --- /dev/null +++ b/test/test_xfile.py @@ -0,0 +1,19 @@ +import os.path +import unittest +import zipfile +from tableaudocumentapi.xfile import find_file_in_zip + +TEST_ASSET_DIR = os.path.join( + os.path.dirname(__file__), + 'assets' +) +BAD_ZIP_FILE = os.path.join( + TEST_ASSET_DIR, + 'BadZip.zip' +) + + +class XFileEdgeTests(unittest.TestCase): + def test_find_file_in_zip_no_xml_file(self): + badzip = zipfile.ZipFile(BAD_ZIP_FILE) + self.assertIsNone(find_file_in_zip(badzip)) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy