-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathcommon.rs
More file actions
66 lines (57 loc) · 1.56 KB
/
common.rs
File metadata and controls
66 lines (57 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use std::{collections::HashMap, path::PathBuf};
use pet_core::os_environment::Environment;
use pet_pyenv::env_variables::EnvVariables;
#[allow(dead_code)]
pub fn resolve_test_path(paths: &[&str]) -> PathBuf {
let mut root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests");
paths.iter().for_each(|p| root.push(p));
root
}
#[allow(dead_code)]
pub fn create_env_variables(home: PathBuf, root: PathBuf) -> EnvVariables {
EnvVariables {
home: Some(home),
root: Some(root),
path: None,
pyenv_root: None,
pyenv: None,
known_global_search_locations: vec![],
}
}
#[allow(dead_code)]
pub struct TestEnvironment {
vars: HashMap<String, String>,
home: Option<PathBuf>,
root: Option<PathBuf>,
globals_locations: Vec<PathBuf>,
}
impl Environment for TestEnvironment {
fn get_env_var(&self, key: String) -> Option<String> {
self.vars.get(&key).cloned()
}
fn get_root(&self) -> Option<PathBuf> {
self.root.clone()
}
fn get_user_home(&self) -> Option<PathBuf> {
self.home.clone()
}
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
self.globals_locations.clone()
}
}
#[allow(dead_code)]
pub fn create_test_environment(
vars: HashMap<String, String>,
home: Option<PathBuf>,
globals_locations: Vec<PathBuf>,
root: Option<PathBuf>,
) -> TestEnvironment {
TestEnvironment {
vars,
home,
root,
globals_locations,
}
}