-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #330 from conveyal/dev
Fix Release Sept 29, 2021
- Loading branch information
Showing
43 changed files
with
904 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.conveyal.gtfs.loader; | ||
|
||
import com.conveyal.gtfs.TestUtils; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import javax.sql.DataSource; | ||
import java.io.IOException; | ||
import java.util.stream.Stream; | ||
|
||
import static com.conveyal.gtfs.GTFS.load; | ||
import static com.conveyal.gtfs.GTFS.validate; | ||
import static com.conveyal.gtfs.TestUtils.assertThatSqlCountQueryYieldsExpectedCount; | ||
|
||
/** | ||
* Load in a GTFS feed with GTFS flex features, and ensure all needed fields are imported correctly. | ||
* TODO: update feed to use more features, and test for these. | ||
*/ | ||
public class GtfsFlexTest { | ||
private static String testDBName; | ||
private static DataSource testDataSource; | ||
private static String testNamespace; | ||
|
||
@BeforeAll | ||
public static void setUpClass() throws IOException { | ||
// Create a new database | ||
testDBName = TestUtils.generateNewDB(); | ||
String dbConnectionUrl = String.format("jdbc:postgresql://localhost/%s", testDBName); | ||
testDataSource = TestUtils.createTestDataSource(dbConnectionUrl); | ||
// load feed into db | ||
String zipFileName = TestUtils.zipFolderFiles( | ||
"real-world-gtfs-feeds/washington-park-shuttle-with-flex-additions", | ||
true); | ||
FeedLoadResult feedLoadResult = load(zipFileName, testDataSource); | ||
testNamespace = feedLoadResult.uniqueIdentifier; | ||
validate(testNamespace, testDataSource); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("createContinuousPickupAndDropOffChecks") | ||
void continuousPickupAndDropOffTests(String namespace, String field, int value, int expectedCount) { | ||
String query = String.format("select count(*) from %s.stop_times where %s = '%s'", | ||
namespace, | ||
field, | ||
value); | ||
assertThatSqlCountQueryYieldsExpectedCount(testDataSource, query, expectedCount); | ||
} | ||
|
||
private static Stream<Arguments> createContinuousPickupAndDropOffChecks() { | ||
return Stream.of( | ||
Arguments.of(testNamespace, "continuous_pickup", 0, 3), | ||
Arguments.of(testNamespace, "continuous_pickup", 1, 5), | ||
Arguments.of(testNamespace, "continuous_pickup", 2, 1), | ||
Arguments.of(testNamespace, "continuous_drop_off", 0, 2), | ||
Arguments.of(testNamespace, "continuous_drop_off", 1, 5), | ||
Arguments.of(testNamespace, "continuous_drop_off", 2, 2) | ||
); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/test/java/com/conveyal/gtfs/loader/LineContextTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.conveyal.gtfs.loader; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static com.conveyal.gtfs.loader.JdbcGtfsLoader.POSTGRES_NULL_TEXT; | ||
import static com.conveyal.gtfs.loader.Requirement.OPTIONAL; | ||
import static com.conveyal.gtfs.loader.Requirement.REQUIRED; | ||
import static com.conveyal.gtfs.loader.Table.FARE_ATTRIBUTES; | ||
import static com.conveyal.gtfs.loader.Table.ROUTES; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class LineContextTest { | ||
/** | ||
* Emulates querying a field in a GTFS record for which the column is absent in the source GTFS. | ||
* Here we query the optional "contains_id" field that is missing in the "fare_rules" table. | ||
*/ | ||
@Test | ||
void shouldReturnPostgresNullTextForMissingField() { | ||
// Line number, fare_id, route_id | ||
// (Optional field "contains_id" is missing.) | ||
String[] rowDataWithLineNumber = new String[] {"2", "1", "300"}; | ||
Table table = Table.FARE_RULES; | ||
|
||
// Here, only list fields that are loaded from the GTFS feed, as happens during execution. | ||
Field[] fields = new Field[] { | ||
new StringField("fare_id", REQUIRED).isReferenceTo(FARE_ATTRIBUTES), | ||
new StringField("route_id", OPTIONAL).isReferenceTo(ROUTES), | ||
}; | ||
LineContext lineContext = new LineContext(table, fields, rowDataWithLineNumber, 2); | ||
|
||
assertEquals(POSTGRES_NULL_TEXT, lineContext.getValueForRow("contains_id")); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
src/test/resources/fake-agency-mtc-long-fields/fare_attributes.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
fare_id,price,currency_type,payment_method,transfers,transfer_duration | ||
route_based_fare,1.23,USD,0,0,0 | ||
fare_id,agency_id,price,currency_type,payment_method,transfers,transfer_duration | ||
route_based_fare,1,1.23,USD,0,0,0 |
2 changes: 2 additions & 0 deletions
2
src/test/resources/real-world-gtfs-feeds/tri-delta-fare-rules/agency.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
agency_id,agency_name,agency_url,agency_phone,agency_timezone,agency_lang | ||
1,"Tri Delta Transit","http://trideltatransit.com","(925) 754-4040","America/Los_Angeles","en" |
2 changes: 2 additions & 0 deletions
2
src/test/resources/real-world-gtfs-feeds/tri-delta-fare-rules/calendar.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date | ||
1,1,1,1,1,1,1,1,20210828,20221231 |
2 changes: 2 additions & 0 deletions
2
src/test/resources/real-world-gtfs-feeds/tri-delta-fare-rules/fare_attributes.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
fare_id,price,currency_type,payment_method,transfers,transfer_duration,agency_id | ||
"1",2.00,USD,0,0,,1 |
2 changes: 2 additions & 0 deletions
2
src/test/resources/real-world-gtfs-feeds/tri-delta-fare-rules/fare_rules.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
fare_id,route_id | ||
"1","300" |
2 changes: 2 additions & 0 deletions
2
src/test/resources/real-world-gtfs-feeds/tri-delta-fare-rules/routes.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
route_id,agency_id,route_short_name,route_long_name,route_type,route_color,route_text_color,route_url | ||
"300",1,"300","Brentwood Park & Ride / Antioch BART",3,800080,FFFFFF,"http://12.155.17.20/RTT/Public/Schedule.aspx?RouteNo=300" |
3 changes: 3 additions & 0 deletions
3
src/test/resources/real-world-gtfs-feeds/tri-delta-fare-rules/shapes.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
shape_id,shape_pt_lon,shape_pt_lat,shape_pt_sequence | ||
27,-121.780946,37.996068,1 | ||
27,-121.698770,37.933812,2 |
6 changes: 6 additions & 0 deletions
6
src/test/resources/real-world-gtfs-feeds/tri-delta-fare-rules/stop_times.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
trip_id,arrival_time,departure_time,stop_id,stop_sequence,stop_headsign,timepoint | ||
1720,17:46:00,17:46:00,722,1,,1 | ||
1720,17:59:00,17:59:00,33,2,,1 | ||
1720,18:02:01,18:02:01,443,3,,0 | ||
1720,18:20:06,18:20:06,421,4,,0 | ||
1720,18:24:00,18:24:00,610,5,,1 |
6 changes: 6 additions & 0 deletions
6
src/test/resources/real-world-gtfs-feeds/tri-delta-fare-rules/stops.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
stop_id,stop_code,stop_name,stop_lat,stop_lon,stop_url,zone_id | ||
33,813644,"Main St & Empire Ave",37.997839,-121.730492,"http://12.155.17.20/RTT/Public/RoutePositionET.aspx?PlatformTag=33", | ||
421,810930,"Brentwood Blvd & Village Dr",37.941524,-121.696341,"http://12.155.17.20/RTT/Public/RoutePositionET.aspx?PlatformTag=421", | ||
443,811043,"Main St & Norcross Ln",37.997716,-121.716376,"http://12.155.17.20/RTT/Public/RoutePositionET.aspx?PlatformTag=443", | ||
610,811425,"Brentwood Park n Ride",37.933838,-121.698755,"http://12.155.17.20/RTT/Public/RoutePositionET.aspx?PlatformTag=610", | ||
722,817754,"Antioch BART",37.995572,-121.778137,"http://12.155.17.20/RTT/Public/RoutePositionET.aspx?PlatformTag=722", |
2 changes: 2 additions & 0 deletions
2
src/test/resources/real-world-gtfs-feeds/tri-delta-fare-rules/trips.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
route_id,service_id,trip_id,trip_headsign,direction_id,block_id,shape_id | ||
"300",1,1720,"Eastbound Brentwood Park & Ride",0,167,27 |
2 changes: 2 additions & 0 deletions
2
...st/resources/real-world-gtfs-feeds/washington-park-shuttle-with-flex-additions/agency.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
agency_id,agency_url,agency_lang,agency_name,agency_phone,agency_timezone,agency_fare_url | ||
501,http://ewpshuttle.org/,en,Washington Park Shuttle,503-319-0999,America/Los_Angeles,http://explorewashingtonpark.org/getting-here/#shuttle |
Oops, something went wrong.