From c7af92323f7a2fe9656e66e605f40c5b1e3ef244 Mon Sep 17 00:00:00 2001 From: fawce Date: Tue, 6 Mar 2012 14:47:04 -0500 Subject: [PATCH] fixed unit tests by changing expected data types for prices. added dataload step to jenkins.sh --- etc/jenkins.sh | 4 ++++ zipline/messaging.py | 2 +- zipline/protocol.py | 19 ++++++++++--------- zipline/test/test_finance.py | 12 ++++++------ 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/etc/jenkins.sh b/etc/jenkins.sh index 8d30bea6..fc6e218d 100755 --- a/etc/jenkins.sh +++ b/etc/jenkins.sh @@ -31,6 +31,10 @@ cp /mnt/jenkins/zipline_host_settings.py ./host_settings.py #documentation output paver apidocs html +#load treasury data +python dataloader.py tr +#load benchmark data +python dataloader.py bm #run all the tests in test. see setup.cfg for flags. nosetests diff --git a/zipline/messaging.py b/zipline/messaging.py index fbeadd90..89664aba 100644 --- a/zipline/messaging.py +++ b/zipline/messaging.py @@ -222,7 +222,7 @@ class ParallelBuffer(Component): try: event = self.unframe(message) # deserialization error - except zp.INVALID_DATASOURE_FRAME as exc: + except zp.INVALID_DATASOURCE_FRAME as exc: return self.signal_exception(exc) try: diff --git a/zipline/protocol.py b/zipline/protocol.py index f7397132..89726fe6 100644 --- a/zipline/protocol.py +++ b/zipline/protocol.py @@ -464,8 +464,8 @@ def TRADE_FRAME(event): assert isinstance(event.source_id, basestring) assert event.type == DATASOURCE_TYPE.TRADE assert isinstance(event.sid, int) - assert isinstance(event.price, float) - assert isinstance(event.volume, int) + assert isinstance(event.price, numbers.Real) + assert isinstance(event.volume, numbers.Integral) PACK_DATE(event) return msgpack.dumps(tuple([ event.sid, @@ -483,8 +483,8 @@ def TRADE_UNFRAME(msg): sid, price, volume, epoch, micros, source_type, source_id = packed assert isinstance(sid, int) - assert isinstance(price, float) - assert isinstance(volume, int) + assert isinstance(price, numbers.Real) + assert isinstance(volume, numbers.Integral) rval = namedict({ 'sid' : sid, 'price' : price, @@ -531,8 +531,8 @@ def ORDER_UNFRAME(msg): def TRANSACTION_FRAME(event): assert isinstance(event, namedict) assert isinstance(event.sid, int) - assert isinstance(event.price, float) - assert isinstance(event.commission, float) + assert isinstance(event.price, numbers.Real) + assert isinstance(event.commission, numbers.Real) assert isinstance(event.amount, int) PACK_DATE(event) return msgpack.dumps(tuple([ @@ -549,8 +549,8 @@ def TRANSACTION_UNFRAME(msg): sid, price, amount, commission, epoch, micros = msgpack.loads(msg) assert isinstance(sid, int) - assert isinstance(price, float) - assert isinstance(commission, float) + assert isinstance(price, numbers.Real) + assert isinstance(commission, numbers.Real) assert isinstance(amount, int) rval = namedict({ 'sid' : sid, @@ -640,7 +640,8 @@ def UNPACK_DATE(event): """ Unpacks the datetime property of event from msgpack'able longs. This function should be called purely for its side effects. - The event's 'dt' property is created by reading two longs: epoch and micros. + The event's 'dt' property is created by reading and then combining two longs: epoch and micros. + The epoch and micros properties are removed after dt is added. UNPACK_DATE and PACK_DATE are inverse operations. diff --git a/zipline/test/test_finance.py b/zipline/test/test_finance.py index f239826b..0544f5c6 100644 --- a/zipline/test/test_finance.py +++ b/zipline/test/test_finance.py @@ -26,14 +26,14 @@ class FinanceTestCase(TestCase): def test_trade_feed_protocol(self): # TODO: Perhaps something more self-documenting for variables names? - a = 133 - b = [10] * 4 - c = [100] * 4 + sid = 133 + price = [10.0] * 4 + volume = [100] * 4 - ts = datetime.strptime("02/15/2012","%m/%d/%Y") - dt = timedelta(days=1) + start_date = datetime.strptime("02/15/2012","%m/%d/%Y") + one_day_td = timedelta(days=1) - trades = factory.create_trade_history( a, b, c, ts, dt ) + trades = factory.create_trade_history( sid, price, volume, start_date, one_day_td ) for trade in trades: #simulate data source sending frame