mirror of
https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess.git
synced 2024-11-22 15:21:00 +09:00
added: use out_runid.csv as default output path
This commit is contained in:
parent
1ec3f8107c
commit
772f7a155f
4 changed files with 34 additions and 10 deletions
|
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Use `out_<runid>.csv` as default output path
|
||||||
|
|
||||||
## [1.0.1]
|
## [1.0.1]
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -11,7 +11,7 @@ use anyhow::{anyhow, Context, Result};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
use masterlog::MasterLogResult;
|
use masterlog::{get_output_filename, MasterLogResult};
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::{serde_as, DisplayFromStr};
|
use serde_with::{serde_as, DisplayFromStr};
|
||||||
|
@ -36,8 +36,9 @@ pub enum Commands {
|
||||||
/// Master log file.
|
/// Master log file.
|
||||||
master_log: path::PathBuf,
|
master_log: path::PathBuf,
|
||||||
/// Output CSV file.
|
/// Output CSV file.
|
||||||
|
/// Default is `out_<runid>.csv`
|
||||||
// #[arg(default_value = get_default_log_path().into_os_string())]
|
// #[arg(default_value = get_default_log_path().into_os_string())]
|
||||||
outfile: PathBuf,
|
outfile: Option<PathBuf>,
|
||||||
},
|
},
|
||||||
/// Check CSV format
|
/// Check CSV format
|
||||||
CheckDB {
|
CheckDB {
|
||||||
|
@ -377,6 +378,8 @@ fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let outfile = outfile.unwrap_or(get_output_filename(&result));
|
||||||
|
|
||||||
let expanded_results = PsbQaqcResult::from_masterlogresult(result);
|
let expanded_results = PsbQaqcResult::from_masterlogresult(result);
|
||||||
|
|
||||||
let mut wtr = match outfile.exists() {
|
let mut wtr = match outfile.exists() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{collections::BTreeMap, io::BufRead, str::FromStr};
|
use std::{collections::BTreeMap, io::BufRead, path::PathBuf, str::FromStr};
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
@ -6,7 +6,7 @@ use log::{debug, info, trace};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
|
|
||||||
use crate::{Position, PositionLayer, PsbId};
|
use crate::{Position, PositionLayer, PsbId, PsbQaqcResult};
|
||||||
|
|
||||||
/// QAQC results for each boards extracted from master log.
|
/// QAQC results for each boards extracted from master log.
|
||||||
///
|
///
|
||||||
|
@ -303,6 +303,10 @@ impl MasterLogResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_output_filename(result: &MasterLogResult) -> PathBuf {
|
||||||
|
PathBuf::from(format!("out_{}.csv", result.runid))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
|
|
25
tests/cli.rs
25
tests/cli.rs
|
@ -1,11 +1,13 @@
|
||||||
mod integrated_test {
|
mod integrated_test {
|
||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
env::current_dir,
|
||||||
|
ffi::OsString,
|
||||||
|
fs::{self, read_dir, File},
|
||||||
io::{BufRead, BufReader},
|
io::{BufRead, BufReader},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::{Context, Result};
|
||||||
use assert_cmd::Command;
|
use assert_cmd::Command;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use predicates::prelude::*;
|
use predicates::prelude::*;
|
||||||
|
@ -67,17 +69,28 @@ mod integrated_test {
|
||||||
#[test]
|
#[test]
|
||||||
fn partial_log() -> Result<()> {
|
fn partial_log() -> Result<()> {
|
||||||
let test_out_dir = assert_fs::TempDir::new()?;
|
let test_out_dir = assert_fs::TempDir::new()?;
|
||||||
let test_out = PathBuf::new().join(&test_out_dir).join("out.csv");
|
fs::copy(
|
||||||
|
"./tests/example_logs/valid/84.log",
|
||||||
|
test_out_dir.join("84.log"),
|
||||||
|
)
|
||||||
|
.context("Error preparing source file")?;
|
||||||
|
|
||||||
let mut cmd = Command::cargo_bin("psb-qaqc")?;
|
let mut cmd = Command::cargo_bin("psb-qaqc")?;
|
||||||
cmd.current_dir("tests")
|
cmd.current_dir(&test_out_dir)
|
||||||
.arg("add-master-log")
|
.arg("add-master-log")
|
||||||
.arg("./example_logs/valid/84.log")
|
.arg("84.log")
|
||||||
.arg(test_out.as_path())
|
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
.stdout(predicate::str::contains("Creating new file"));
|
.stdout(predicate::str::contains("Creating new file"));
|
||||||
|
|
||||||
|
assert!(read_dir(&test_out_dir)
|
||||||
|
.context("Failed to read dir")?
|
||||||
|
.any(|entry| {
|
||||||
|
entry
|
||||||
|
.map_or(OsString::from(""), |entry| entry.file_name())
|
||||||
|
.eq("out_84.csv")
|
||||||
|
}));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue