Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tech] Update some crates to test new CI/CD + fix clippy errors #872

Merged
merged 4 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Hove <[email protected]>", "Guillaume Pinot <[email protected]>"]
name = "transit_model"
version = "0.52.0"
version = "0.53.0"
license = "AGPL-3.0-only"
description = "Transit data management"
repository = "https://github.com/hove-io/transit_model"
Expand Down Expand Up @@ -43,7 +43,7 @@ chrono = { version = "0.4", default-features = false, features = ["std", "clock"
chrono-tz = { version = "0.7", features = ["serde"] }
csv = "1"
derivative = "2"
geo = "0.19"
geo = "0.23"
iso4217 = "0.3"
lazy_static = "1"
md5 = "0.7"
Expand All @@ -66,7 +66,7 @@ tracing = { version = "0.1", features = ["log"] }
typed_index_collection = "2"
walkdir = "2"
wkt = "0.10"
zip = { version = "0.5", default-features = false, features = ["deflate"] }
zip = { version = "0.6", default-features = false, features = ["deflate"] }
git-version = "0.3"

[[test]]
Expand Down
4 changes: 2 additions & 2 deletions model-builder/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl ModelBuilder {
let default_calendar = self.collections.calendars.get_mut(DEFAULT_CALENDAR_ID);
if let Some(mut cal) = default_calendar {
if cal.dates.is_empty() {
cal.dates.insert(Date::from_ymd(2020, 1, 1));
cal.dates.insert(Date::from_ymd_opt(2020, 1, 1).unwrap());
}
}
}
Expand Down Expand Up @@ -472,7 +472,7 @@ mod test {
.collect()
);
let default_calendar = model.calendars.get("default_service").unwrap();
let dates = [transit_model::objects::Date::from_ymd(2020, 1, 1)]
let dates = [transit_model::objects::Date::from_ymd_opt(2020, 1, 1).unwrap()]
.iter()
.copied()
.collect::<std::collections::BTreeSet<_>>();
Expand Down
12 changes: 6 additions & 6 deletions ntfs2gtfs/tests/ntfs2gtfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn test_stop_zones_not_exported_and_cleaned() {
collections.remove_route_points();
let model = Model::new(collections).unwrap();
transit_model::gtfs::write(model, path, false).unwrap();
compare_output_dir_with_expected(&path, None, "./tests/fixtures/output");
compare_output_dir_with_expected(path, None, "./tests/fixtures/output");
});
}

Expand All @@ -39,7 +39,7 @@ fn test_mode_in_route_shortname() {
let model = add_mode_to_line_code(model).unwrap();
transit_model::gtfs::write(model, path, false).unwrap();
compare_output_dir_with_expected(
&path,
path,
Some(vec!["routes.txt"]),
"./tests/fixtures/output_route_shortname_with_mode",
);
Expand All @@ -53,7 +53,7 @@ fn test_platforms_preserving() {
let model = transit_model::ntfs::read(input).unwrap();
transit_model::gtfs::write(model, path, false).unwrap();
compare_output_dir_with_expected(
&path,
path,
Some(vec!["stops.txt"]),
"./tests/fixtures/platforms/output",
);
Expand Down Expand Up @@ -134,7 +134,7 @@ fn test_ntfs2gtfs_extended() {
.assert()
.success();
compare_output_dir_with_expected(
&output_dir,
output_dir,
Some(vec!["routes.txt"]),
"./tests/fixtures/output_extended_route",
);
Expand All @@ -152,7 +152,7 @@ fn test_ntfs2gtfs_split_route_by_mode() {
.assert()
.success();
compare_output_dir_with_expected(
&output_dir,
output_dir,
Some(vec!["routes.txt"]),
"./tests/fixtures/output_split_route_by_mode",
);
Expand All @@ -171,7 +171,7 @@ fn test_ntfs2gtfs_split_route_by_mode_extended() {
.assert()
.success();
compare_output_dir_with_expected(
&output_dir,
output_dir,
Some(vec!["routes.txt"]),
"./tests/fixtures/output_split_route_by_mode_extended",
);
Expand Down
12 changes: 6 additions & 6 deletions src/enhancers/enhance_pickup_dropoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub fn enhance_pickup_dropoff(collections: &mut Collections) {
let mut vj = collections.vehicle_journeys.index_mut(vj_idx);

if !allowed_first_drop_off_vj.contains(&vj_idx) {
if let Some(st) = vj.stop_times.iter_mut().find(|st| !is_route_point(*st)) {
if let Some(st) = vj.stop_times.iter_mut().find(|st| !is_route_point(st)) {
st.drop_off_type = 1;
}
}
Expand All @@ -151,7 +151,7 @@ pub fn enhance_pickup_dropoff(collections: &mut Collections) {
.stop_times
.iter_mut()
.rev()
.find(|st| !is_route_point(*st))
.find(|st| !is_route_point(st))
{
st.pickup_type = 1;
}
Expand Down Expand Up @@ -313,7 +313,7 @@ mod tests {
);
collections.vehicle_journeys = build_vehicle_journeys(prev_vj_config, next_vj_config);
let mut dates = BTreeSet::new();
dates.insert(Date::from_ymd(2020, 1, 1));
dates.insert(Date::from_ymd_opt(2020, 1, 1).unwrap());
collections.calendars = CollectionWithId::new(vec![Calendar {
id: "default_service".to_owned(),
dates,
Expand Down Expand Up @@ -354,7 +354,7 @@ mod tests {
);
collections.vehicle_journeys = build_vehicle_journeys(prev_vj_config, next_vj_config);
let mut dates = BTreeSet::new();
dates.insert(Date::from_ymd(2020, 1, 1));
dates.insert(Date::from_ymd_opt(2020, 1, 1).unwrap());
collections.calendars = CollectionWithId::new(vec![Calendar {
id: "default_service".to_owned(),
dates,
Expand Down Expand Up @@ -395,7 +395,7 @@ mod tests {
);
collections.vehicle_journeys = build_vehicle_journeys(prev_vj_config, next_vj_config);
let mut dates = BTreeSet::new();
dates.insert(Date::from_ymd(2020, 1, 1));
dates.insert(Date::from_ymd_opt(2020, 1, 1).unwrap());
collections.calendars = CollectionWithId::new(vec![Calendar {
id: "default_service".to_owned(),
dates,
Expand Down Expand Up @@ -459,7 +459,7 @@ mod tests {
});
drop(vj_mut);
let mut dates = BTreeSet::new();
dates.insert(Date::from_ymd(2020, 1, 1));
dates.insert(Date::from_ymd_opt(2020, 1, 1).unwrap());
collections.calendars = CollectionWithId::new(vec![Calendar {
id: "default_service".to_owned(),
dates,
Expand Down
10 changes: 5 additions & 5 deletions src/gtfs/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2831,8 +2831,8 @@ mod tests {
calendars::manage_calendars(&mut handler, &mut collections).unwrap();

let mut dates = BTreeSet::new();
dates.insert(chrono::NaiveDate::from_ymd(2018, 5, 5));
dates.insert(chrono::NaiveDate::from_ymd(2018, 5, 6));
dates.insert(chrono::NaiveDate::from_ymd_opt(2018, 5, 5).unwrap());
dates.insert(chrono::NaiveDate::from_ymd_opt(2018, 5, 6).unwrap());
assert_eq!(
vec![Calendar {
id: "1".to_string(),
Expand All @@ -2858,7 +2858,7 @@ mod tests {
calendars::manage_calendars(&mut handler, &mut collections).unwrap();

let mut dates = BTreeSet::new();
dates.insert(chrono::NaiveDate::from_ymd(2018, 2, 12));
dates.insert(chrono::NaiveDate::from_ymd_opt(2018, 2, 12).unwrap());
assert_eq!(
vec![Calendar {
id: "1".to_string(),
Expand Down Expand Up @@ -2890,8 +2890,8 @@ mod tests {
calendars::manage_calendars(&mut handler, &mut collections).unwrap();

let mut dates = BTreeSet::new();
dates.insert(chrono::NaiveDate::from_ymd(2018, 5, 6));
dates.insert(chrono::NaiveDate::from_ymd(2018, 5, 7));
dates.insert(chrono::NaiveDate::from_ymd_opt(2018, 5, 6).unwrap());
dates.insert(chrono::NaiveDate::from_ymd_opt(2018, 5, 7).unwrap());
assert_eq!(
vec![
Calendar {
Expand Down
8 changes: 4 additions & 4 deletions src/gtfs/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ fn make_gtfs_route_from_ntfs_line(line: &objects::Line, pm: &PhysicalModeWithOrd
Route {
id: get_gtfs_route_id_from_ntfs_line_id(&line.id, pm),
agency_id: Some(line.network_id.clone()),
short_name: line.code.clone().unwrap_or_else(|| "".to_string()),
short_name: line.code.clone().unwrap_or_default(),
long_name: line.name.clone(),
desc: None,
route_type: RouteType::from(pm.inner),
Expand Down Expand Up @@ -851,7 +851,7 @@ mod tests {
})
.unwrap();
let mut dates = BTreeSet::new();
dates.insert(chrono::NaiveDate::from_ymd(2018, 5, 6));
dates.insert(chrono::NaiveDate::from_ymd_opt(2018, 5, 6).unwrap());
collections
.calendars
.push(objects::Calendar {
Expand Down Expand Up @@ -1130,9 +1130,9 @@ mod tests {
fn write_calendar_file_from_calendar() {
let mut dates = BTreeSet::new();
//saturday
dates.insert(chrono::NaiveDate::from_ymd(2018, 5, 5));
dates.insert(chrono::NaiveDate::from_ymd_opt(2018, 5, 5).unwrap());
//sunday
dates.insert(chrono::NaiveDate::from_ymd(2018, 5, 6));
dates.insert(chrono::NaiveDate::from_ymd_opt(2018, 5, 6).unwrap());
let calendar = CollectionWithId::new(vec![
Calendar {
id: "1".to_string(),
Expand Down
44 changes: 33 additions & 11 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1607,23 +1607,45 @@ mod tests {
let mut collections = Collections::default();

let mut service_1 = Calendar::new(String::from("service_1"));
service_1.dates.insert(NaiveDate::from_ymd(2019, 10, 1));
service_1.dates.insert(NaiveDate::from_ymd(2019, 10, 2));
service_1.dates.insert(NaiveDate::from_ymd(2019, 10, 3));
service_1.dates.insert(NaiveDate::from_ymd(2019, 10, 10));
service_1
.dates
.insert(NaiveDate::from_ymd_opt(2019, 10, 1).unwrap());
service_1
.dates
.insert(NaiveDate::from_ymd_opt(2019, 10, 2).unwrap());
service_1
.dates
.insert(NaiveDate::from_ymd_opt(2019, 10, 3).unwrap());
service_1
.dates
.insert(NaiveDate::from_ymd_opt(2019, 10, 10).unwrap());
collections.calendars.push(service_1).unwrap();

let mut service_2 = Calendar::new(String::from("service_2"));
service_2.dates.insert(NaiveDate::from_ymd(2019, 10, 1));
service_2.dates.insert(NaiveDate::from_ymd(2019, 10, 2));
service_2.dates.insert(NaiveDate::from_ymd(2019, 10, 3));
service_2.dates.insert(NaiveDate::from_ymd(2019, 10, 10));
service_2
.dates
.insert(NaiveDate::from_ymd_opt(2019, 10, 1).unwrap());
service_2
.dates
.insert(NaiveDate::from_ymd_opt(2019, 10, 2).unwrap());
service_2
.dates
.insert(NaiveDate::from_ymd_opt(2019, 10, 3).unwrap());
service_2
.dates
.insert(NaiveDate::from_ymd_opt(2019, 10, 10).unwrap());
collections.calendars.push(service_2).unwrap();

let mut service_3 = Calendar::new(String::from("service_3"));
service_3.dates.insert(NaiveDate::from_ymd(2019, 10, 1));
service_3.dates.insert(NaiveDate::from_ymd(2019, 10, 3));
service_3.dates.insert(NaiveDate::from_ymd(2019, 10, 10));
service_3
.dates
.insert(NaiveDate::from_ymd_opt(2019, 10, 1).unwrap());
service_3
.dates
.insert(NaiveDate::from_ymd_opt(2019, 10, 3).unwrap());
service_3
.dates
.insert(NaiveDate::from_ymd_opt(2019, 10, 10).unwrap());
collections.calendars.push(service_3).unwrap();

collections
Expand Down
15 changes: 9 additions & 6 deletions src/netex_france/calendars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ impl<'a> CalendarExporter<'a> {
}

fn generate_from_date(date: Date) -> Element {
let date_string = DateTime::<Utc>::from_utc(date.and_hms(0, 0, 0), Utc).to_rfc3339();
let date_string =
DateTime::<Utc>::from_utc(date.and_hms_opt(0, 0, 0).unwrap(), Utc).to_rfc3339();
Element::builder("FromDate")
.append(Node::Text(date_string))
.build()
Expand Down Expand Up @@ -176,16 +177,18 @@ mod tests {

#[test]
fn only_one_date() {
let dates = vec![NaiveDate::from_ymd(2020, 1, 1)].into_iter().collect();
let dates = vec![NaiveDate::from_ymd_opt(2020, 1, 1).unwrap()]
.into_iter()
.collect();
let valid_day_bits_element = CalendarExporter::generate_valid_day_bits(&dates);
assert_eq!("1", get_valid_day_bits(valid_day_bits_element));
}

#[test]
fn successive_dates() {
let dates = vec![
NaiveDate::from_ymd(2020, 1, 1),
NaiveDate::from_ymd(2020, 1, 2),
NaiveDate::from_ymd_opt(2020, 1, 1).unwrap(),
NaiveDate::from_ymd_opt(2020, 1, 2).unwrap(),
]
.into_iter()
.collect();
Expand All @@ -196,8 +199,8 @@ mod tests {
#[test]
fn not_successive_dates() {
let dates = vec![
NaiveDate::from_ymd(2020, 1, 1),
NaiveDate::from_ymd(2020, 1, 3),
NaiveDate::from_ymd_opt(2020, 1, 1).unwrap(),
NaiveDate::from_ymd_opt(2020, 1, 3).unwrap(),
]
.into_iter()
.collect();
Expand Down
3 changes: 2 additions & 1 deletion src/netex_france/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ impl Exporter<'_> {

fn create_valid_between(&self) -> Result<Element> {
let format_date = |date: Date, hour, minute, second| -> String {
DateTime::<Utc>::from_utc(date.and_hms(hour, minute, second), Utc).to_rfc3339()
DateTime::<Utc>::from_utc(date.and_hms_opt(hour, minute, second).unwrap(), Utc)
.to_rfc3339()
};
let (start_date, end_date) = self.model.calculate_validity_period()?;
let from_date = Element::builder("FromDate")
Expand Down
5 changes: 2 additions & 3 deletions src/netex_france/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ mod transfers;
use transfers::TransferExporter;

use crate::{model::Model, Result};
use chrono::{DateTime, FixedOffset, TimeZone};
use chrono::{DateTime, FixedOffset};

/// Configuration options for exporting a NeTEx France.
/// 3 options can be configured:
Expand All @@ -56,8 +56,7 @@ impl WriteConfiguration {
WriteConfiguration {
participant: participant.into(),
stop_provider: None,
current_datetime: chrono::FixedOffset::east(0)
.from_utc_datetime(&chrono::Utc::now().naive_utc()),
current_datetime: chrono::Utc::now().with_timezone(&FixedOffset::east_opt(0).unwrap()),
}
}
/// Setup the Stop Provider (see [specifications](https://github.com/hove-io/ntfs-specification/blob/master/ntfs_to_netex_france_specs.md) for more details)
Expand Down
4 changes: 3 additions & 1 deletion src/netex_france/offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,9 @@ mod tests {
});
collections.calendars = CollectionWithId::from(Calendar {
id: String::from("service_id"),
dates: vec![Date::from_ymd(2020, 1, 1)].into_iter().collect(),
dates: vec![Date::from_ymd_opt(2020, 1, 1).unwrap()]
.into_iter()
.collect(),
});
collections.vehicle_journeys = CollectionWithId::from(VehicleJourney {
id: String::from("vj_id_1"),
Expand Down
Loading