示例#1
0
 def test_error_invalid_symbol(self):
     with self.assertRaises(StockException):
         with captured_output():
             raw_args = ["month-averages", "--key", self.apikey,
                         "2017-01", "2017-01", "WEYLANDYUTANI"]
             args = self.parser.parse_args(raw_args)
             main(args)
示例#2
0
 def test_error_swapped_months(self):
     with self.assertRaises(StockException):
         with captured_output():
             raw_args = ["month-averages", "--key", self.apikey,
                         "2017-02", "2017-01", "GOOGL"]
             args = self.parser.parse_args(raw_args)
             main(args)
 def test_action_required(self):
     cmdline = ["--key", "mykey"]
     with self.assertRaises(SystemExit) as ecm:
         with captured_output() as (out, err):
             self.parser.parse_args(cmdline)
             self.fail("Expected to end")
     self.assertEqual(ecm.exception.code, 2)
 def test_help(self):
     cmdline = ["-h"]
     with self.assertRaises(SystemExit) as ecm:
         with captured_output() as (out, err):
             self.parser.parse_args(cmdline)
             self.fail("Expected to end")
     self.assertEqual(ecm.exception.code, 0)
 def test_stats_basic(self):
     cmdline = ["month-averages", "--key", "mykey",
                "2017-01", "2017-02",
                "BUY", "N", "LARGE"
                ]
     with captured_output() as (out, err):
         args = self.parser.parse_args(cmdline)
         self.assertIsNotNone(args)
 def test_bad_date(self):
     cmdline = ["stats", "--key", "mykey",
                "2001-15", "2020-99",
                "BUY", "N", "LARGE"
                ]
     with self.assertRaises(SystemExit) as ecm:
         with captured_output() as (out, err):
             args = self.parser.parse_args(cmdline)
             self.fail("Expected to end with error")
     self.assertEqual(ecm.exception.code, 2)
示例#7
0
    def test_list_symbols(self):
        expected_entries = {
            "AAPL": "Apple Inc (AAPL) Prices, Dividends, Splits and Trading Volume"
        }

        with captured_output() as (out, err):
            raw_args = ["list-symbols", "--key", self.apikey]
            args = self.parser.parse_args(raw_args)
            code = main(args)
            self.assertEqual(code, 0)
        actual_entries = json.loads(out.getvalue().strip())
        self._assertDictSubset(expected_entries, actual_entries)
示例#8
0
 def test_bad_days(self):
     with captured_output() as (out, err):
         raw_args = ["biggest-loser", "--key", self.apikey,
                     "2017-01", "2017-06", "GOOGL", 'MSFT']
         args = self.parser.parse_args(raw_args)
         code = main(args)
         self.assertEqual(code, 0)
     text = out.getvalue().strip()
     data = json.loads(text)
     self.assertIn("symbols", data)
     self.assertIn("days", data)
     self.assertIn('MSFT', data['symbols'])
示例#9
0
 def test_busy_days(self):
     with captured_output() as (out, err):
         raw_args = ["busy-days", "--key", self.apikey,
                     "2017-01", "2017-06", "GOOGL", 'MSFT']
         args = self.parser.parse_args(raw_args)
         code = main(args)
         self.assertEqual(code, 0)
     text = out.getvalue().strip()
     data = json.loads(text)
     self.assertIn("GOOGL", data)
     self.assertIn("MSFT", data)
     sample_busy_day = data['GOOGL']['busy_days']['2017-01-03']
     self.assertEqual(sample_busy_day, 1959033)
示例#10
0
 def test_top_variance_days(self):
     with captured_output() as (out, err):
         raw_args = ["top-variance-days", "--key", self.apikey,
                     "2017-01", "2017-06", "GOOGL", 'MSFT']
         args = self.parser.parse_args(raw_args)
         code = main(args)
         self.assertEqual(code, 0)
     text = out.getvalue().strip()
     data = json.loads(text)
     self.assertIn("GOOGL", data)
     self.assertIn("MSFT", data)
     actual_googl_variance = data['GOOGL']['variance']
     self.assertAlmostEqual(actual_googl_variance, 52.13)
示例#11
0
 def test_month_averages(self):
     with captured_output() as (out, err):
         raw_args = ["month-averages", "--key", self.apikey,
                     "2017-01", "2017-06", "GOOGL", 'MSFT']
         args = self.parser.parse_args(raw_args)
         code = main(args)
         self.assertEqual(code, 0)
     text = out.getvalue().strip()
     data = json.loads(text)
     self.assertIn("GOOGL", data)
     self.assertIn("MSFT", data)
     actual_googl_open = data['GOOGL']['2017-01']['average_open']
     self.assertAlmostEqual(actual_googl_open, 829.854)
 def test_missing_key(self):
     with self.assertRaises(SystemExit) as ecm:
         with captured_output() as (out, err):
             self.parser.parse_args(["symbols"])
             self.fail("Expected to end with error")
     self.assertEqual(ecm.exception.code, 2)
 def test_symbols(self):
     cmdline = ["list-symbols", "--key", "mykey"]
     with captured_output() as (out, err):
         args = self.parser.parse_args(cmdline)
     self.assertIsNotNone(args)