def testBarsExceptions(self): b1 = Bar(datetime.datetime(2013, 1, 23), 10.0, 40.0, 5.0, 25.0) b2 = Bar(datetime.datetime(2013, 1, 24), 20.0, 30.0, 15.0, 15.0) bars = Bars() bars.add_bar('AA', b1) with self.assertRaisesRegexp(Exception, 'attempt to add duplicate bar'): bars.add_bar('AA', b1) with self.assertRaisesRegexp(Exception, '!= current datetime'): bars.add_bar('AB', b2)
def testBarsBasic(self): b1 = Bar(datetime.datetime(2013, 1, 23), 10.0, 40.0, 5.0, 25.0) b2 = Bar(datetime.datetime(2013, 1, 23), 20.0, 30.0, 15.0, 15.0) bars = Bars() bars.add_bar('AA', b1) bars.add_bar('AB', b2) self.assertEqual(bars.datetime(), datetime.datetime(2013, 1, 23)) self.assertEqual(bars.symbols(), ['AA', 'AB']) self.assertEqual(bars.get_bar('AA').open(), 10.0) self.assertEqual(bars.get_bar('AB').close(), 15.0)
def testBarsExceptions(self): b1 = Bar(datetime.datetime(2013,1,23),10.0, 40.0, 5.0, 25.0) b2 = Bar(datetime.datetime(2013,1,24),20.0, 30.0, 15.0, 15.0) bars = Bars() bars.add_bar('AA', b1) with self.assertRaisesRegexp(Exception, 'attempt to add duplicate bar'): bars.add_bar('AA', b1) with self.assertRaisesRegexp(Exception, '!= current datetime'): bars.add_bar('AB', b2)
def testBarsBasic(self): b1 = Bar(datetime.datetime(2013,1,23),10.0, 40.0, 5.0, 25.0) b2 = Bar(datetime.datetime(2013,1,23),20.0, 30.0, 15.0, 15.0) bars = Bars() bars.add_bar('AA', b1) bars.add_bar('AB', b2) self.assertEqual(bars.datetime(), datetime.datetime(2013,1,23)) self.assertEqual(bars.symbols(), ['AA', 'AB']) self.assertEqual(bars.get_bar('AA').open(), 10.0) self.assertEqual(bars.get_bar('AB').close(), 15.0)