Skip to content

Commit

Permalink
fixed tests and unicode change
Browse files Browse the repository at this point in the history
  • Loading branch information
cgoldberg committed Dec 21, 2013
1 parent 73efa41 commit dfe6e04
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
57 changes: 30 additions & 27 deletions test_ystockquote.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# Requires: Python 2.7/3.2+
# Requires: Python 2.7/3.3+


import unittest

import pep8
from testscenarios import generate_scenarios, TestWithScenarios

import ystockquote


class Pep8ConformanceTestCase(unittest.TestCase):
"""Test that all code conforms to PEP8."""
"""Test that all code conforms to PEP8!"""

def test_pep8_conformance(self):
self.pep8style = pep8.StyleGuide(show_source=True)
Expand All @@ -29,36 +30,38 @@ def test_pep8_conformance(self):
self.assertEqual(self.pep8style.options.report.total_errors, 0)


class YStockQuoteTestCase(unittest.TestCase):

def setUp(self):
self.symbol = 'GOOG'
class YStockQuoteTestCase(TestWithScenarios):

def test_get_all(self):
all_info = ystockquote.get_all(self.symbol)
symbol = 'GOOG'
all_info = ystockquote.get_all(symbol)
self.assertIsInstance(all_info, dict)
p = all_info['dividend_yield']
self.assertIsInstance(p, str)
pc = all_info['previous_close']
self.assertNotEqual(pc, 'N/A')
self.assertGreater(float(pc), 0)

def test_get_historical_prices(self):
prices_dict = ystockquote.get_historical_prices(
self.symbol, '2013-01-02', '2013-01-15')
self.assertIsInstance(prices_dict, dict)
self.assertEqual(len(prices_dict), 10)
self.assertEqual(sorted(prices_dict.keys())[0], '2013-01-02')
self.assertEqual(sorted(prices_dict.keys())[-1], '2013-01-15')
self.assertGreater(float(prices_dict['2013-01-02']['Open']), 0.0)
self.assertGreater(float(prices_dict['2013-01-02']['High']), 0.0)
self.assertGreater(float(prices_dict['2013-01-02']['Low']), 0.0)
self.assertGreater(float(prices_dict['2013-01-02']['Close']), 0.0)
self.assertGreater(float(prices_dict['2013-01-02']['Volume']), 0.0)
self.assertGreater(float(prices_dict['2013-01-02']['Adj Close']), 0.0)
self.assertGreater(float(prices_dict['2013-01-15']['Open']), 0.0)
self.assertGreater(float(prices_dict['2013-01-15']['High']), 0.0)
self.assertGreater(float(prices_dict['2013-01-15']['Low']), 0.0)
self.assertGreater(float(prices_dict['2013-01-15']['Close']), 0.0)
self.assertGreater(float(prices_dict['2013-01-15']['Volume']), 0.0)
self.assertGreater(float(prices_dict['2013-01-15']['Adj Close']), 0.0)
symbol = 'GOOG'
start_date = '2013-01-02'
end_date = '2013-01-15'
prices = ystockquote.get_historical_prices(
symbol, start_date, end_date)
self.assertIsInstance(prices, dict)
self.assertEqual(len(prices), 10)
self.assertEqual(sorted(prices.keys())[0], '2013-01-02')
self.assertEqual(sorted(prices.keys())[-1], end_date)
self.assertGreater(float(prices[start_date]['Open']), 0.0)
self.assertGreater(float(prices[start_date]['High']), 0.0)
self.assertGreater(float(prices[start_date]['Low']), 0.0)
self.assertGreater(float(prices[start_date]['Close']), 0.0)
self.assertGreater(float(prices[start_date]['Volume']), 0.0)
self.assertGreater(float(prices[start_date]['Adj Close']), 0.0)
self.assertGreater(float(prices[end_date]['Open']), 0.0)
self.assertGreater(float(prices[end_date]['High']), 0.0)
self.assertGreater(float(prices[end_date]['Low']), 0.0)
self.assertGreater(float(prices[end_date]['Close']), 0.0)
self.assertGreater(float(prices[end_date]['Volume']), 0.0)
self.assertGreater(float(prices[end_date]['Adj Close']), 0.0)


if __name__ == '__main__':
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ envlist = py27, py33, pypy
[testenv]
deps =
pep8
testscenarios
commands =
{envpython} setup.py install
{envpython} -m unittest discover
5 changes: 3 additions & 2 deletions ystockquote.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# Requires: Python 2.7/3.2+
# Requires: Python 2.7/3.3+


__version__ = '0.2.5dev'
Expand All @@ -29,7 +29,8 @@ def _request(symbol, stat):
url = 'http://finance.yahoo.com/d/quotes.csv?s=%s&f=%s' % (symbol, stat)
req = Request(url)
resp = urlopen(req)
return str(resp.read().decode('utf-8').strip())
content = resp.read().decode().strip()
return content


def get_all(symbol):
Expand Down

0 comments on commit dfe6e04

Please sign in to comment.