From f7882b5864863101a5e2368e18ed8e42114349a2 Mon Sep 17 00:00:00 2001 From: scriada Date: Thu, 6 Sep 2018 12:21:21 +0100 Subject: [PATCH] Make host optional in VersionedItem (#619) (#620) This makes `VersionedItem` backwards compatible, so any third-party libraries creating their own `VersionedItem`s won't be affected. --- arctic/store/versioned_item.py | 4 ++++ tests/unit/store/test_version_item.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/arctic/store/versioned_item.py b/arctic/store/versioned_item.py index edfdad2af3964..a213cbf4102c5 100644 --- a/arctic/store/versioned_item.py +++ b/arctic/store/versioned_item.py @@ -5,6 +5,10 @@ class VersionedItem(namedtuple('VersionedItem', ['symbol', 'library', 'data', 'v """ Class representing a Versioned object in VersionStore. """ + + def __new__(cls, symbol, library, data, version, metadata, host=None): + return super(VersionedItem, cls).__new__(cls, symbol, library, data, version, metadata, host) + def metadata_dict(self): return {'symbol': self.symbol, 'library': self.library, 'version': self.version} diff --git a/tests/unit/store/test_version_item.py b/tests/unit/store/test_version_item.py index 05b375a60ab63..5238847458c64 100644 --- a/tests/unit/store/test_version_item.py +++ b/tests/unit/store/test_version_item.py @@ -17,6 +17,23 @@ def test_versioned_item_str(): assert repr(item) == expected +def test_versioned_item_default_host(): + item = VersionedItem(symbol="sym", + library="ONEMINUTE", + data=[1, 2, 3], + version=1.0, + metadata={'metadata': 'foo'}) + + expected_item = VersionedItem(symbol="sym", + library="ONEMINUTE", + data=[1, 2, 3], + version=1.0, + host=None, + metadata={'metadata': 'foo'}) + + assert item == expected_item + + def test_versioned_item_str_handles_none(): item = VersionedItem(symbol=None, library=None,