1
Fork 0

Fix tests

This commit is contained in:
prescientmoon 2024-09-09 18:36:56 +02:00
parent ac4145ee40
commit ee02e2c80d
Signed by: prescientmoon
SSH key fingerprint: SHA256:WFp/cO76nbarETAoQcQXuV+0h7XJsEsOCI0UsyPIy6U
5 changed files with 24 additions and 8 deletions

View file

@ -6,8 +6,10 @@ if [ "$#" != 2 ]; then
exit 1 exit 1
fi fi
from="$1/db.sqlite" a="$1/db.sqlite"
to ="$2/db.sqlite" b="$2/db.sqlite"
sqlite3 $from ".dump songs" | sqlite3 $to sqlite3 $b "DROP TABLE songs"
sqlite3 $from ".dump charts" | sqlite3 $to sqlite3 $b "DROP TABLE charts"
sqlite3 $a ".dump songs" | sqlite3 $b
sqlite3 $a ".dump charts" | sqlite3 $b

View file

@ -1,6 +1,7 @@
use std::array; use std::array;
use std::num::NonZeroU64; use std::num::NonZeroU64;
use anyhow::Context;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use chrono::Utc; use chrono::Utc;
use num::traits::Euclid; use num::traits::Euclid;
@ -83,7 +84,13 @@ impl CreatePlay {
self.far_notes, self.far_notes,
), ),
|row| Ok((row.get("id")?, row.get("created_at")?)), |row| Ok((row.get("id")?, row.get("created_at")?)),
)?; )
.with_context(|| {
format!(
"Could not create play {self:?} with user {:?} and chart {:?}",
user.id, chart.id
)
})?;
// }}} // }}}
// {{{ Update creation ptt data // {{{ Update creation ptt data
let scores = ScoreCollection::from_standard_score(self.score, chart); let scores = ScoreCollection::from_standard_score(self.score, chart);

View file

@ -145,7 +145,9 @@ pub mod mock {
let path = dir.join(&attachment.filename); let path = dir.join(&attachment.filename);
if path.exists() { if path.exists() {
assert_eq!(&attachment.data, &fs::read(path)?); if &attachment.data != &fs::read(&path)? {
panic!("Attachment differs from {path:?}");
}
} else { } else {
fs::write(&path, &attachment.data)?; fs::write(&path, &attachment.data)?;
} }

View file

@ -106,11 +106,16 @@ pub mod testing {
} }
pub fn import_songs_and_jackets_from(to: &Path) -> () { pub fn import_songs_and_jackets_from(to: &Path) -> () {
std::process::Command::new("scripts/copy-chart-info.sh") let out = std::process::Command::new("scripts/copy-chart-info.sh")
.arg(get_data_dir()) .arg(get_data_dir())
.arg(to) .arg(to)
.output() .output()
.expect("Could not run sh chart info copy script"); .expect("Could not run sh chart info copy script");
assert!(
out.status.success(),
"chart info copy script exited with non-0 code"
);
} }
#[macro_export] #[macro_export]

View file

@ -334,7 +334,7 @@ impl CharMeasurements {
.map(|(i, _, d)| (d.sqrt(), i)) .map(|(i, _, d)| (d.sqrt(), i))
.ok_or_else(|| anyhow!("No chars in cache"))?; .ok_or_else(|| anyhow!("No chars in cache"))?;
println!("char '{}', distance {}", best_match.1, best_match.0); // println!("char '{}', distance {}", best_match.1, best_match.0);
if best_match.0 <= 0.75 { if best_match.0 <= 0.75 {
result.push(best_match.1); result.push(best_match.1);
} }