コード例 #1
0
def test_create_rides_simple():
    """Test reading in a rides file from provided sample sample_rides.csv.

    NOTE: This test relies on test_create_stations working correctly.
    """
    stations = create_stations('stations.json')
    rides = create_rides('sample_rides.csv', stations)

    # Check the first ride
    ride = rides[0]
    assert isinstance(ride, Ride)
    assert ride.start is stations['6134']
    assert ride.end is stations['6721']
    assert ride.start_time == datetime(2017, 6, 1, 7, 31, 0)
    assert ride.end_time == datetime(2017, 6, 1, 7, 54, 0)
コード例 #2
0
def test_get_position_ride():
    """Test get_position for a simple ride.
    """
    stations = create_stations('stations.json')
    rides = create_rides('sample_rides.csv', stations)

    ride = rides[0]

    # Check ride endpoints. We use pytest's approx function to
    # avoid floating point issues.
    assert ride.get_position(ride.start_time) == approx(ride.start.location)
    assert ride.get_position(ride.end_time) == approx(ride.end.location)

    # Manually check a time during the ride.
    # Note that this ride lasts *23 minutes*, and
    # goes from (-73.562643, 45.537964) to
    # (-73.54628920555115, 45.57713595014113).
    # We're checking the position after 10 minutes have passed.
    assert (ride.get_position(datetime(2017, 6, 1, 7, 41, 0)) == approx(
        (-73.5555326546, 45.5549952827), abs=1e-5))