Skip to content

Commit

Permalink
Merge pull request #788 from CanalTP/output-zip
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean SIMARD authored Jun 29, 2021
2 parents e4ea2da + 2ec42ff commit 7dbad03
Show file tree
Hide file tree
Showing 19 changed files with 530 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Kisio Digital <[email protected]>", "Guillaume Pinot <[email protected]>"]
name = "transit_model"
version = "0.37.0"
version = "0.38.0"
license = "AGPL-3.0-only"
description = "Transit data management"
repository = "https://github.com/CanalTP/transit_model"
Expand Down
4 changes: 4 additions & 0 deletions gtfs2netexfr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ slog-term = "2.4"
structopt = "0.3"
transit_model = { path = "../", features = ["proj"] }
lazy_static = "1"

[dev-dependencies]
assert_cmd = "1"
tempfile = "3"
21 changes: 14 additions & 7 deletions gtfs2netexfr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,20 @@ fn run(opt: Opt) -> Result<()> {

let model = transit_model::gtfs::Reader::new(configuration).parse(opt.input)?;

let netex_exporter = transit_model::netex_france::Exporter::new(
&model,
opt.participant,
opt.stop_provider,
opt.current_datetime,
);
netex_exporter.write(opt.output)?;
let mut config = transit_model::netex_france::WriteConfiguration::new(opt.participant)
.current_datetime(opt.current_datetime);
if let Some(stop_provider) = opt.stop_provider {
config = config.stop_provider(stop_provider);
}
match opt.output.extension() {
Some(ext) if ext == "zip" => {
transit_model::netex_france::write_to_zip(&model, opt.output, config)?;
}
_ => {
transit_model::netex_france::write(&model, opt.output, config)?;
}
};

Ok(())
}

Expand Down
79 changes: 79 additions & 0 deletions gtfs2netexfr/tests/gtfs2netexfr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use assert_cmd::prelude::*;
use std::process::Command;
use tempfile::TempDir;

#[test]
fn test_gtfs2netexfr() {
let output_dir = TempDir::new().expect("create temp dir failed");
Command::cargo_bin("gtfs2netexfr")
.expect("Failed to find binary 'gtfs2netexfr'")
.arg("--input")
.arg("../tests/fixtures/netex_france/input_gtfs")
.arg("--output")
.arg(output_dir.path().to_str().unwrap())
.arg("--participant")
.arg("Participant")
.arg("--current-datetime")
.arg("2019-04-03T17:19:00Z")
.assert()
.success();
assert!(output_dir.path().join("arrets.xml").is_file());
}

#[test]
fn test_gtfs2netexfr_without_dir() {
let output_dir = TempDir::new().expect("create temp dir failed");
let unexisting_dir = output_dir.path().join("unexisting-dir");
Command::cargo_bin("gtfs2netexfr")
.expect("Failed to find binary 'gtfs2netexfr'")
.arg("--input")
.arg("../tests/fixtures/netex_france/input_gtfs")
.arg("--output")
.arg(unexisting_dir.to_str().unwrap())
.arg("--participant")
.arg("Participant")
.arg("--current-datetime")
.arg("2019-04-03T17:19:00Z")
.assert()
.success();
assert!(unexisting_dir.join("arrets.xml").is_file());
}

#[test]
fn test_gtfs2netexfr_create_zip() {
let output_dir = TempDir::new().expect("create temp dir failed");
let netexfr_zip = output_dir.path().join("netexfr.zip");
assert!(!netexfr_zip.exists());
Command::cargo_bin("gtfs2netexfr")
.expect("Failed to find binary 'gtfs2netexfr'")
.arg("--input")
.arg("../tests/fixtures/netex_france/input_gtfs")
.arg("--output")
.arg(netexfr_zip.to_str().unwrap())
.arg("--participant")
.arg("Participant")
.arg("--current-datetime")
.arg("2019-04-03T17:19:00Z")
.assert()
.success();
assert!(netexfr_zip.is_file());
}

#[test]
fn test_gtfs2netexfr_create_not_zip_extension() {
let output_dir = TempDir::new().expect("create temp dir failed");
let netexfr_foobar = output_dir.path().join("netexfr.foobar");
Command::cargo_bin("gtfs2netexfr")
.expect("Failed to find binary 'gtfs2netexfr'")
.arg("--input")
.arg("../tests/fixtures/netex_france/input_gtfs")
.arg("--output")
.arg(netexfr_foobar.to_str().unwrap())
.arg("--participant")
.arg("Participant")
.arg("--current-datetime")
.arg("2019-04-03T17:19:00Z")
.assert()
.success();
assert!(netexfr_foobar.join("arrets.xml").is_file());
}
4 changes: 4 additions & 0 deletions gtfs2ntfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ slog-term = "2.4"
structopt = "0.3"
transit_model = { path = "../" }
lazy_static = "1"

[dev-dependencies]
assert_cmd = "1"
tempfile = "3"
9 changes: 8 additions & 1 deletion gtfs2ntfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,14 @@ fn run(opt: Opt) -> Result<()> {
None,
)?;

transit_model::ntfs::write(&model, opt.output, opt.current_datetime)?;
match opt.output.extension() {
Some(ext) if ext == "zip" => {
transit_model::ntfs::write_to_zip(&model, opt.output, opt.current_datetime)?;
}
_ => {
transit_model::ntfs::write(&model, opt.output, opt.current_datetime)?;
}
};
Ok(())
}

Expand Down
72 changes: 72 additions & 0 deletions gtfs2ntfs/tests/gtfs2ntfs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use assert_cmd::prelude::*;
use std::process::Command;
use tempfile::TempDir;

#[test]
fn test_gtfs2ntfs() {
let output_dir = TempDir::new().expect("create temp dir failed");
Command::cargo_bin("gtfs2ntfs")
.expect("Failed to find binary 'gtfs2ntfs'")
.arg("--input")
.arg("../tests/fixtures/gtfs2ntfs/minimal/input")
.arg("--output")
.arg(output_dir.path().to_str().unwrap())
.arg("--current-datetime")
.arg("2019-04-03T17:19:00Z")
.assert()
.success();
assert!(output_dir.path().join("feed_infos.txt").is_file());
}

#[test]
fn test_gtfs2ntfs_create_output_directory() {
let output_dir = TempDir::new().expect("create temp dir failed");
let unexisting_dir = output_dir.path().join("unexisting-folder");
Command::cargo_bin("gtfs2ntfs")
.expect("Failed to find binary 'gtfs2ntfs'")
.arg("--input")
.arg("../tests/fixtures/gtfs2ntfs/minimal/input")
.arg("--output")
.arg(unexisting_dir.to_str().unwrap())
.arg("--current-datetime")
.arg("2019-04-03T17:19:00Z")
.assert()
.success();
assert!(unexisting_dir.join("feed_infos.txt").is_file());
}

#[test]
fn test_gtfs2ntfs_create_zip() {
let output_dir = TempDir::new().expect("create temp dir failed");
let ntfs_zip = output_dir.path().join("ntfs.zip");
assert!(!ntfs_zip.exists());
Command::cargo_bin("gtfs2ntfs")
.expect("Failed to find binary 'gtfs2ntfs'")
.arg("--input")
.arg("../tests/fixtures/gtfs2ntfs/minimal/input")
.arg("--output")
.arg(ntfs_zip.to_str().unwrap())
.arg("--current-datetime")
.arg("2019-04-03T17:19:00Z")
.assert()
.success();
assert!(ntfs_zip.is_file());
}

#[test]
fn test_gtfs2ntfs_create_not_zip_extension() {
let output_dir = TempDir::new().expect("create temp dir failed");
let ntfs_foobar = output_dir.path().join("ntfs.foobar");
assert!(!ntfs_foobar.exists());
Command::cargo_bin("gtfs2ntfs")
.expect("Failed to find binary 'gtfs2ntfs'")
.arg("--input")
.arg("../tests/fixtures/gtfs2ntfs/minimal/input")
.arg("--output")
.arg(ntfs_foobar.to_str().unwrap())
.arg("--current-datetime")
.arg("2019-04-03T17:19:00Z")
.assert()
.success();
assert!(ntfs_foobar.join("feed_infos.txt").is_file());
}
4 changes: 4 additions & 0 deletions ntfs2gtfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ slog-term = "2.4"
structopt = "0.3"
transit_model = { path = "../" }
lazy_static = "1"

[dev-dependencies]
assert_cmd = "1"
tempfile = "3"
9 changes: 8 additions & 1 deletion ntfs2gtfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ fn run(opt: Opt) -> Result<()> {
model = add_mode_to_line_code(model)?;
}

transit_model::gtfs::write(model, opt.output)?;
match opt.output.extension() {
Some(ext) if ext == "zip" => {
transit_model::gtfs::write_to_zip(model, opt.output)?;
}
_ => {
transit_model::gtfs::write(model, opt.output)?;
}
};
Ok(())
}

Expand Down
64 changes: 64 additions & 0 deletions ntfs2gtfs/tests/ntfs2gtfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>

use assert_cmd::prelude::*;
use ntfs2gtfs::add_mode_to_line_code;
use std::process::Command;
use tempfile::TempDir;
use transit_model::test_utils::*;

#[test]
Expand Down Expand Up @@ -53,3 +56,64 @@ fn test_platforms_preserving() {
);
});
}

#[test]
fn test_ntfs2gtfs() {
let output_dir = TempDir::new().expect("create temp dir failed");
Command::cargo_bin("ntfs2gtfs")
.expect("Failed to find binary 'ntfs2gtfs'")
.arg("--input")
.arg("tests/fixtures/input/")
.arg("--output")
.arg(output_dir.path().to_str().unwrap())
.assert()
.success();
assert!(output_dir.path().join("agency.txt").is_file())
}

#[test]
fn test_ntfs2gtfs_create_output_directory() {
let output_dir = TempDir::new().expect("create temp dir failed");
let unexisting_dir = output_dir.path().join("unexisting-folder");
Command::cargo_bin("ntfs2gtfs")
.expect("Failed to find binary 'ntfs2gtfs'")
.arg("--input")
.arg("tests/fixtures/input/")
.arg("--output")
.arg(unexisting_dir.to_str().unwrap())
.assert()
.success();
assert!(unexisting_dir.join("agency.txt").is_file())
}

#[test]
fn test_ntfs2gtfs_create_zip() {
let output_dir = TempDir::new().expect("create temp dir failed");
let ntfs_zip = output_dir.path().join("ntfs.zip");
assert!(!ntfs_zip.is_file());
Command::cargo_bin("ntfs2gtfs")
.expect("Failed to find binary 'ntfs2gtfs'")
.arg("--input")
.arg("tests/fixtures/input/")
.arg("--output")
.arg(ntfs_zip.to_str().unwrap())
.assert()
.success();
assert!(ntfs_zip.is_file());
}

#[test]
fn test_ntfs2gtfs_create_foobar() {
let output_dir = TempDir::new().expect("create temp dir failed");
let ntfs_foobar = output_dir.path().join("ntfs.foobar");
assert!(!ntfs_foobar.is_file());
Command::cargo_bin("ntfs2gtfs")
.expect("Failed to find binary 'ntfs2gtfs'")
.arg("--input")
.arg("tests/fixtures/input/")
.arg("--output")
.arg(ntfs_foobar.to_str().unwrap())
.assert()
.success();
assert!(ntfs_foobar.join("agency.txt").is_file());
}
4 changes: 4 additions & 0 deletions ntfs2netexfr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ slog-term = "2.4"
structopt = "0.3"
transit_model = { path = "../", features = ["proj"] }
lazy_static = "1"

[dev-dependencies]
assert_cmd = "1"
tempfile = "3"
20 changes: 13 additions & 7 deletions ntfs2netexfr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,19 @@ fn run(opt: Opt) -> Result<()> {

let model = transit_model::ntfs::read(opt.input)?;

let netex_exporter = transit_model::netex_france::Exporter::new(
&model,
opt.participant,
opt.stop_provider,
opt.current_datetime,
);
netex_exporter.write(opt.output)?;
let mut config = transit_model::netex_france::WriteConfiguration::new(opt.participant)
.current_datetime(opt.current_datetime);
if let Some(stop_provider) = opt.stop_provider {
config = config.stop_provider(stop_provider);
}
match opt.output.extension() {
Some(ext) if ext == "zip" => {
transit_model::netex_france::write_to_zip(&model, opt.output, config)?;
}
_ => {
transit_model::netex_france::write(&model, opt.output, config)?;
}
};
Ok(())
}

Expand Down
Loading

0 comments on commit 7dbad03

Please sign in to comment.