From f005d5361a553c539907c5622514f708a75bdc48 Mon Sep 17 00:00:00 2001 From: Russell Hay Date: Tue, 9 Aug 2016 13:20:42 -0700 Subject: [PATCH 1/5] Removing code that should have been removed in a previous checkin --- tableaudocumentapi/multilookup_dict.py | 8 +------- test/test_multidict.py | 4 ++++ 2 files changed, 5 insertions(+), 7 deletions(-) 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/test_multidict.py b/test/test_multidict.py index 4544c49..58bf7e8 100644 --- a/test/test_multidict.py +++ b/test/test_multidict.py @@ -70,3 +70,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]']) From 894bc9d356853542fb10d3439ca47eafa20fe021 Mon Sep 17 00:00:00 2001 From: Russell Hay Date: Tue, 9 Aug 2016 13:32:04 -0700 Subject: [PATCH 2/5] another small improvement --- tableaudocumentapi/field.py | 6 ++++-- test/test_field.py | 32 ++++++++++++++++++++++++++++++++ test/test_multidict.py | 4 ++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 test/test_field.py 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/test/test_field.py b/test/test_field.py new file mode 100644 index 0000000..a627ac6 --- /dev/null +++ b/test/test_field.py @@ -0,0 +1,32 @@ +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): + try: + Field() + self.fail('Field should have thrown') + except AttributeError: + pass + + +class FindMetaDataRecordEdgeTest(unittest.TestCase): + class MockXml(object): + def find(self, *args, **kwargs): + return None + + def test_find_metadata_record_returns_none(self): + self.assertIsNone(_find_metadata_record(self.MockXml(), 'foo')) diff --git a/test/test_multidict.py b/test/test_multidict.py index 58bf7e8..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']) From 5fb80bf44e268797d81eb2cdc4d9533d306732d2 Mon Sep 17 00:00:00 2001 From: Russell Hay Date: Tue, 9 Aug 2016 13:38:21 -0700 Subject: [PATCH 3/5] Adding coverage for one of the xfile edge cases --- test/assets/BadZip.zip | Bin 0 -> 201 bytes test/test_xfile.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/assets/BadZip.zip create mode 100644 test/test_xfile.py diff --git a/test/assets/BadZip.zip b/test/assets/BadZip.zip new file mode 100644 index 0000000000000000000000000000000000000000..9eca08f821d6dd60285c038233f430d94072a67f GIT binary patch literal 201 zcmWIWW@h1H00F-oPEXFcu}kHFY!K#RkYR92Oo{OI(W}VK2@T<7U=Frh6%N9s72FJr zEa59BhqENIZ)WyX&sE6FFHuO$Qvj+~NXyJg)lo>QR7lUy$*I)i3h-uRl4HhYi3G@Q i21X!W(g Date: Tue, 9 Aug 2016 13:44:09 -0700 Subject: [PATCH 4/5] Adding a few additional tests --- tableaudocumentapi/datasource.py | 2 +- test/bvt.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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/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' From 2b19a9dfb2e228e756922c58d7a38fbad059129d Mon Sep 17 00:00:00 2001 From: Russell Hay Date: Tue, 9 Aug 2016 15:14:39 -0700 Subject: [PATCH 5/5] Updating based on code review feedback. Note: assertRaises does not take a message --- test/test_field.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/test_field.py b/test/test_field.py index a627ac6..7cbe885 100644 --- a/test/test_field.py +++ b/test/test_field.py @@ -16,17 +16,14 @@ class FieldsUnitTest(unittest.TestCase): def test_field_throws_if_no_data_passed_in(self): - try: + with self.assertRaises(AttributeError): Field() - self.fail('Field should have thrown') - except AttributeError: - pass class FindMetaDataRecordEdgeTest(unittest.TestCase): - class MockXml(object): + class MockXmlWithNoFind(object): def find(self, *args, **kwargs): return None def test_find_metadata_record_returns_none(self): - self.assertIsNone(_find_metadata_record(self.MockXml(), 'foo')) + self.assertIsNone(_find_metadata_record(self.MockXmlWithNoFind(), 'foo')) 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