From 60dacec576fc406ec92dd384485aa663c0c1deb1 Mon Sep 17 00:00:00 2001 From: Freddie Vargus Date: Fri, 21 Apr 2017 11:58:28 -0400 Subject: [PATCH] TST: Add test for repr Remove unused code --- tests/finance/test_transaction.py | 30 ++++++++++++++++++++++++++++++ zipline/finance/transaction.py | 3 +-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 tests/finance/test_transaction.py diff --git a/tests/finance/test_transaction.py b/tests/finance/test_transaction.py new file mode 100644 index 0000000000..97ff69107c --- /dev/null +++ b/tests/finance/test_transaction.py @@ -0,0 +1,30 @@ +# +# Copyright 2017 Quantopian, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import pandas as pd +from unittest import TestCase + +from zipline.assets import Asset +from zipline.finance.transaction import Transaction + +class TransactionTestCase(TestCase): + + def test_transaction_repr(self): + dt = pd.Timestamp('2017-01-01') + + asset = Asset(1, exchange='test') + txn = Transaction(asset, amount=100, dt=dt, price=10, order_id=0) + + expected = "Transaction(sid=Asset(1), dt=2017-01-01 00:00:00, amount=100, price=10)" + self.assertEqual(repr(txn), expected) diff --git a/zipline/finance/transaction.py b/zipline/finance/transaction.py index 615c568984..fb6f02821e 100644 --- a/zipline/finance/transaction.py +++ b/zipline/finance/transaction.py @@ -37,10 +37,9 @@ def __getitem__(self, name): return self.__dict__[name] def __repr__(self): - return """{typename}(order_id={order_id}, sid={sid}, \ + return """{typename}(sid={sid}, \ dt={dt}, amount={amount}, price={price})""".format( typename=type(self).__name__, - order_id=self.order_id, sid=self.sid, dt=self.dt, amount=self.amount,