Skip to content

Commit

Permalink
TST: Add test for repr
Browse files Browse the repository at this point in the history
Remove unused code
  • Loading branch information
buinvest committed Apr 21, 2017
1 parent 910bed0 commit 60dacec
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
30 changes: 30 additions & 0 deletions 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)
3 changes: 1 addition & 2 deletions zipline/finance/transaction.py
Expand Up @@ -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,
Expand Down

0 comments on commit 60dacec

Please sign in to comment.