From 6e86a08d3f9062e014521cae7bedb4a9f36f2cc2 Mon Sep 17 00:00:00 2001 From: elmotec Date: Sun, 18 Oct 2015 09:42:58 -0400 Subject: [PATCH] Fixed test_search Removed usage of sys.stderr in mock exception which caused the stream to be closed. This in turn failed the next test. Simplified test_search to avoid the zip and the loop. --- fredapi/tests/test_fred.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/fredapi/tests/test_fred.py b/fredapi/tests/test_fred.py index a88c4e8..1f616d2 100644 --- a/fredapi/tests/test_fred.py +++ b/fredapi/tests/test_fred.py @@ -79,26 +79,32 @@ def __init__(self, rel_url, response=None, side_effect=None): - - - @@ -150,7 +156,6 @@ def setUp(self): self.fake_fred_call = fake_fred_call self.__original_urlopen = fredapi.fred.urlopen - def tearDown(self): """Cleanup.""" pass @@ -230,9 +235,9 @@ def test_invalid_kwarg_in_get_series(self, urlopen): """Test invalid keyword argument in call to get_series.""" url = '{}/series?series_id=invalid&api_key={}'.format(self.root_url, fred_api_key) - side_effect = fredapi.fred.HTTPError(url, 400, '', '', sys.stderr) + side_effect = fredapi.fred.HTTPError(url, 400, '', '', io.StringIO()) self.prepare_urlopen(urlopen, side_effect=side_effect) - with self.assertRaises(ValueError) as context: + with self.assertRaises(ValueError): self.fred.get_series('SP500', observation_start='invalid-datetime-str') self.assertFalse(urlopen.called) @@ -249,12 +254,11 @@ def test_search(self, urlopen): 'seasonal_adjustment_short']]) expected = textwrap.dedent('''\ popularity observation_start seasonal_adjustment_short - series id + series id PCPI01001 0 1969-01-01 NSA PCPI01003 0 1969-01-01 NSA PCPI01005 0 1969-01-01 NSA''') - for aline, eline in zip(actual.split('\n'), expected.split('\n')): - self.assertEqual(aline.strip(), eline.strip()) + self.assertEqual(actual.split('\n'), expected.split('\n')) if __name__ == '__main__':