'Test for operational uk_transport sensor with proper attributes.'

@requests_mock.Mocker()
def test_bus(self, mock_req):

    with requests_mock.Mocker() as mock_req:
        uri = re.compile((UkTransportSensor.TRANSPORT_API_URL_BASE + '*'))
        mock_req.get(uri, text=load_fixture('uk_transport_bus.json'))
        self.assertTrue(setup_component(self.hass, 'sensor', {'sensor': self.config}))
    bus_state = self.hass.states.get('sensor.next_bus_to_wantage')
    assert (type(bus_state.state) == str)
    assert (bus_state.name == 'Next    bus    to    {}'.format(BUS_DIRECTION))
    assert (bus_state.attributes.get(ATTR_ATCOCODE) == BUS_ATCOCODE)
    assert (bus_state.attributes.get(ATTR_LOCALITY) == 'Harwell    Campus')
    assert (bus_state.attributes.get(ATTR_STOP_NAME) == 'Bus    Station')
    assert (len(bus_state.attributes.get(ATTR_NEXT_BUSES)) == 2)
    direction_re = re.compile(BUS_DIRECTION)
    for bus in bus_state.attributes.get(ATTR_NEXT_BUSES):
        print (bus['direction'], direction_re.match(bus['direction']))
        assert (direction_re.search(bus['direction']) is not None)
