def test_get_random_connection_excludes_exclusions_if_possible(mocker): mocker.patch('herdcats.tube.STATIONS', utils.get_stations()) mocker.patch('herdcats.tube.CONNECTIONS', utils.get_connections()) mocker.patch('random.choice').side_effect = lambda stations: stations connection = tube.get_random_connection(1, exclude_if_possible=[2, 4]) assert connection == [3]
def test_get_random_connection_returns_valid_connection(mocker): mocker.patch('herdcats.tube.STATIONS', utils.get_stations()) mocker.patch('herdcats.tube.CONNECTIONS', utils.get_connections()) mocker.patch('random.choice').side_effect = lambda stations: stations connection = tube.get_random_connection(1) assert set(connection) == set([2, 3, 4])
def test_get_random_connection_ignores_exclusions_if_theyd_prevent_travel( mocker): mocker.patch('herdcats.tube.STATIONS', utils.get_stations()) mocker.patch('herdcats.tube.CONNECTIONS', utils.get_connections()) mocker.patch('random.choice').side_effect = lambda stations: stations connection = tube.get_random_connection(1, exclude_if_possible=[2, 3, 4]) assert set(connection) == set([2, 3, 4])
def test_get_random_connection_returns_None_if_station_closed(mocker): mocker.patch('herdcats.tube.STATIONS', utils.get_stations()) mocker.patch('herdcats.tube.CONNECTIONS', utils.get_connections()) mocker.patch('random.choice').side_effect = lambda stations: stations tube.STATIONS[1]['is_closed'] = True connection = tube.get_random_connection(1) assert connection is None
def test_get_random_connection_excludes_closed_stations(mocker): mocker.patch('herdcats.tube.STATIONS', utils.get_stations()) mocker.patch('herdcats.tube.CONNECTIONS', utils.get_connections()) mocker.patch('random.choice').side_effect = lambda stations: stations tube.STATIONS[3]['is_closed'] = True tube.STATIONS[4]['is_closed'] = True connection = tube.get_random_connection(1) assert connection == [2]