-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af0a9ba
commit 89da7d8
Showing
2 changed files
with
45 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::{ | ||
fs, | ||
path::{Path, PathBuf}, | ||
thread, | ||
time::Duration, | ||
}; | ||
|
||
use crate::{ | ||
control::Control, defer_file_removal, tracing_setup::init_tracing_for_tests, ToolsDataMap, | ||
}; | ||
|
||
pub fn get_ctrl() -> Control { | ||
let mut ctrl = Control::default(); | ||
ctrl.cfg.usr.home_folder = Some(ctrl.cfg.tmpdir().to_string()); | ||
ctrl | ||
} | ||
|
||
pub fn tmp_copy(src: &Path) -> PathBuf { | ||
let tmp_file_stem = src.file_stem().unwrap().to_str().unwrap(); | ||
let tmp_file = get_test_folder().join(format!("tmp-{tmp_file_stem}")); | ||
tracing::debug!("Copying {src:?} to {tmp_file:?}"); | ||
fs::copy(src, &tmp_file).unwrap(); | ||
tmp_file | ||
} | ||
|
||
pub fn get_test_folder() -> PathBuf { | ||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("resources/test_data") | ||
} | ||
pub fn prj_load(file: &str) -> ToolsDataMap { | ||
init_tracing_for_tests(); | ||
let mut ctrl = get_ctrl(); | ||
let test_file_src = get_test_folder().join(get_test_folder().join(file)); | ||
let test_file = tmp_copy(&test_file_src); | ||
defer_file_removal!(&test_file); | ||
let mut tdm = ctrl.load(test_file.clone()).unwrap(); | ||
let pre_tdm = tdm.clone(); | ||
ctrl.import_annos(&test_file, &mut tdm).unwrap(); | ||
thread::sleep(Duration::from_millis(5)); | ||
assert_eq!(tdm, pre_tdm); | ||
tdm | ||
} |