def test_update(self):
        # Arrange
        bar_spec = TestStubs.bar_spec_1min_mid()
        builder = BarBuilder(bar_spec, use_previous_close=True)

        tick1 = QuoteTick(symbol=AUDUSD_FXCM,
                          bid=Price("1.00001"),
                          ask=Price("1.00004"),
                          bid_size=Quantity(1),
                          ask_size=Quantity(1),
                          timestamp=UNIX_EPOCH)

        tick2 = QuoteTick(symbol=AUDUSD_FXCM,
                          bid=Price("1.00002"),
                          ask=Price("1.00005"),
                          bid_size=Quantity(1),
                          ask_size=Quantity(1),
                          timestamp=UNIX_EPOCH)

        tick3 = QuoteTick(symbol=AUDUSD_FXCM,
                          bid=Price("1.00000"),
                          ask=Price("1.00003"),
                          bid_size=Quantity(1),
                          ask_size=Quantity(1),
                          timestamp=UNIX_EPOCH)

        # Act
        builder.handle_quote_tick(tick1)
        builder.handle_quote_tick(tick2)
        builder.handle_quote_tick(tick3)

        # Assert
        self.assertEqual(bar_spec, builder.bar_spec)
        self.assertEqual(3, builder.count)
        self.assertEqual(UNIX_EPOCH, builder.last_update)
    def test_build_with_previous_close(self):
        # Arrange
        bar_spec = TestStubs.bar_spec_1min_mid()
        builder = BarBuilder(bar_spec, use_previous_close=True)

        tick1 = QuoteTick(symbol=AUDUSD_FXCM,
                          bid=Price("1.00001"),
                          ask=Price("1.00004"),
                          bid_size=Quantity(1),
                          ask_size=Quantity(1),
                          timestamp=UNIX_EPOCH)

        tick2 = QuoteTick(symbol=AUDUSD_FXCM,
                          bid=Price("1.00002"),
                          ask=Price("1.00005"),
                          bid_size=Quantity(1),
                          ask_size=Quantity(1),
                          timestamp=UNIX_EPOCH)

        tick3 = QuoteTick(symbol=AUDUSD_FXCM,
                          bid=Price("1.00000"),
                          ask=Price("1.00003"),
                          bid_size=Quantity(1),
                          ask_size=Quantity(1),
                          timestamp=UNIX_EPOCH)

        builder.handle_quote_tick(tick1)
        builder.handle_quote_tick(tick2)
        builder.handle_quote_tick(tick3)
        builder.build()

        # Act
        bar = builder.build()  # Also resets builder

        # Assert
        self.assertEqual(Price("1.000015"), bar.open)
        self.assertEqual(Price("1.000015"), bar.high)
        self.assertEqual(Price("1.000015"), bar.low)
        self.assertEqual(Price("1.000015"), bar.close)
        self.assertEqual(Quantity(), bar.volume)
        self.assertEqual(UNIX_EPOCH, bar.timestamp)
        self.assertEqual(UNIX_EPOCH, builder.last_update)
        self.assertEqual(0, builder.count)