mirror of
https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess.git
synced 2024-11-22 07:10:18 +09:00
fix: master log parse (invalid station detection in status parse)
- missed switch for `Station1` - added integrated test to check lines count of output csv
This commit is contained in:
parent
e20c029684
commit
fb5160d2d9
2 changed files with 30 additions and 21 deletions
|
@ -2,7 +2,7 @@ use std::{collections::BTreeMap, io::BufRead, str::FromStr};
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use log::{debug, info, trace};
|
use log::{debug, error, info, trace};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
|
|
||||||
|
@ -123,7 +123,9 @@ impl MasterLogResult {
|
||||||
debug!("End of assignments");
|
debug!("End of assignments");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
debug!("line: {}", line);
|
||||||
let (pos, id) = extract_position_id(&line)?;
|
let (pos, id) = extract_position_id(&line)?;
|
||||||
|
trace!("pos: {}", pos);
|
||||||
match assignments.insert(pos.clone(), id) {
|
match assignments.insert(pos.clone(), id) {
|
||||||
None => (),
|
None => (),
|
||||||
Some(old_id) => {
|
Some(old_id) => {
|
||||||
|
@ -163,9 +165,17 @@ impl MasterLogResult {
|
||||||
let mut board_results = BTreeMap::new();
|
let mut board_results = BTreeMap::new();
|
||||||
for station_minor in [0, 1] {
|
for station_minor in [0, 1] {
|
||||||
info!("Result for {:?}", station_minor);
|
info!("Result for {:?}", station_minor);
|
||||||
for _ in 1..10 {
|
|
||||||
|
// Loop for sufficiently large number to reach `Station1`
|
||||||
|
for _ in 1..20 {
|
||||||
let line = lines.next().context("Invalid log format(result body)")??;
|
let line = lines.next().context("Invalid log format(result body)")??;
|
||||||
if line.contains("Station1") || line.contains("======") {
|
trace!("line: {}", line);
|
||||||
|
if line.contains("======") {
|
||||||
|
// end of status
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if line.contains(&format!("Station{}", station_minor + 1)) {
|
||||||
|
debug!("Next station: line: {}", line);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let parts: Vec<&str> = line.split('|').collect();
|
let parts: Vec<&str> = line.split('|').collect();
|
||||||
|
@ -182,7 +192,7 @@ impl MasterLogResult {
|
||||||
.parse::<u8>()
|
.parse::<u8>()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
.context("Invalid station format")??;
|
.context(format!("Invalid station format: {}", line))??;
|
||||||
let station_id = match station_minor {
|
let station_id = match station_minor {
|
||||||
0 => raw_station_id,
|
0 => raw_station_id,
|
||||||
1 => raw_station_id - 10,
|
1 => raw_station_id - 10,
|
||||||
|
@ -283,14 +293,8 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_runid_line() {
|
fn parse_runid_line() {
|
||||||
assert_eq!(
|
assert_eq!(extract_runid_line("QAQC runid: 7").unwrap(), 7);
|
||||||
extract_runid_line("QAQC runid: 7").unwrap(),
|
assert_eq!(extract_runid_line("QAQC runid: 12345").unwrap(), 12345);
|
||||||
7
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
extract_runid_line("QAQC runid: 12345").unwrap(),
|
|
||||||
12345
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
19
tests/cli.rs
19
tests/cli.rs
|
@ -7,6 +7,7 @@ mod integrated_test {
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use assert_cmd::Command;
|
use assert_cmd::Command;
|
||||||
|
use itertools::Itertools;
|
||||||
use predicates::prelude::*;
|
use predicates::prelude::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -26,18 +27,22 @@ mod integrated_test {
|
||||||
|
|
||||||
// check output
|
// check output
|
||||||
{
|
{
|
||||||
|
// check output content
|
||||||
let f = File::open(test_out.clone())?;
|
let f = File::open(test_out.clone())?;
|
||||||
let r = BufReader::new(f);
|
let r = BufReader::new(f);
|
||||||
assert!(r
|
assert!(r.lines().any(|line| {
|
||||||
.lines()
|
line.unwrap().contains(
|
||||||
.any(|line| {
|
"8866,,B-0-1,0,1,1,0,1,8,1,,7,2024-07-20T17:15:46Z,7.log,0.1.0,alice,,,,",
|
||||||
line
|
|
||||||
.unwrap()
|
|
||||||
.contains(
|
|
||||||
"8866,,B-0-1,0,1,1,0,1,8,1,,7,2024-07-20T17:15:46Z,7.log,0.1.0,alice,,,,"
|
|
||||||
)
|
)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
// Check output lines count
|
||||||
|
let f = File::open(test_out.clone())?;
|
||||||
|
let r = BufReader::new(f);
|
||||||
|
let lc = r.lines().collect_vec().len();
|
||||||
|
assert_eq!(lc, 19);
|
||||||
|
}
|
||||||
|
|
||||||
// 2nd file
|
// 2nd file
|
||||||
let mut cmd = Command::cargo_bin("psb-qaqc")?;
|
let mut cmd = Command::cargo_bin("psb-qaqc")?;
|
||||||
|
|
Loading…
Reference in a new issue