expose mock executing to python library; (#6980)
* expose mock executing to python library; Signed-off-by: Jess Frazelle <github@jessfraz.com> * bump Signed-off-by: Jess Frazelle <github@jessfraz.com> * Update rust/kcl-python-bindings/src/lib.rs Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com> Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
This commit is contained in:
@ -426,14 +426,14 @@ impl ExecutorContext {
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub async fn new_mock() -> Self {
|
||||
pub async fn new_mock(settings: Option<ExecutorSettings>) -> Self {
|
||||
ExecutorContext {
|
||||
engine: Arc::new(Box::new(
|
||||
crate::engine::conn_mock::EngineConnection::new().await.unwrap(),
|
||||
)),
|
||||
fs: Arc::new(FileManager::new()),
|
||||
stdlib: Arc::new(StdLib::new()),
|
||||
settings: Default::default(),
|
||||
settings: settings.unwrap_or_default(),
|
||||
context_type: ContextType::Mock,
|
||||
}
|
||||
}
|
||||
@ -2232,7 +2232,7 @@ w = f() + f()
|
||||
let result = ctx.run_with_caching(program).await.unwrap();
|
||||
assert_eq!(result.variables.get("x").unwrap().as_f64().unwrap(), 2.0);
|
||||
|
||||
let ctx2 = ExecutorContext::new_mock().await;
|
||||
let ctx2 = ExecutorContext::new_mock(None).await;
|
||||
let program2 = crate::Program::parse_no_errs("z = x + 1").unwrap();
|
||||
let result = ctx2.run_mock(program2, true).await.unwrap();
|
||||
assert_eq!(result.variables.get("z").unwrap().as_f64().unwrap(), 3.0);
|
||||
|
@ -1460,7 +1460,7 @@ mod test {
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn coerce_idempotent() {
|
||||
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock().await);
|
||||
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock(None).await);
|
||||
let values = values(&mut exec_state);
|
||||
for v in &values {
|
||||
// Identity subtype
|
||||
@ -1550,7 +1550,7 @@ mod test {
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn coerce_none() {
|
||||
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock().await);
|
||||
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock(None).await);
|
||||
let none = KclValue::KclNone {
|
||||
value: crate::parsing::ast::types::KclNone::new(),
|
||||
meta: Vec::new(),
|
||||
@ -1608,7 +1608,7 @@ mod test {
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn coerce_record() {
|
||||
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock().await);
|
||||
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock(None).await);
|
||||
|
||||
let obj0 = KclValue::Object {
|
||||
value: HashMap::new(),
|
||||
@ -1690,7 +1690,7 @@ mod test {
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn coerce_array() {
|
||||
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock().await);
|
||||
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock(None).await);
|
||||
|
||||
let hom_arr = KclValue::HomArray {
|
||||
value: vec![
|
||||
@ -1843,7 +1843,7 @@ mod test {
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn coerce_union() {
|
||||
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock().await);
|
||||
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock(None).await);
|
||||
|
||||
// Subtyping smaller unions
|
||||
assert!(RuntimeType::Union(vec![]).subtype(&RuntimeType::Union(vec![
|
||||
@ -1894,7 +1894,7 @@ mod test {
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn coerce_axes() {
|
||||
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock().await);
|
||||
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock(None).await);
|
||||
|
||||
// Subtyping
|
||||
assert!(RuntimeType::Primitive(PrimitiveType::Axis2d).subtype(&RuntimeType::Primitive(PrimitiveType::Axis2d)));
|
||||
@ -2009,7 +2009,7 @@ mod test {
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn coerce_numeric() {
|
||||
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock().await);
|
||||
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock(None).await);
|
||||
|
||||
let count = KclValue::Number {
|
||||
value: 1.0,
|
||||
@ -2237,7 +2237,7 @@ d = cos(30)
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn coerce_nested_array() {
|
||||
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock().await);
|
||||
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock(None).await);
|
||||
|
||||
let mixed1 = KclValue::HomArray {
|
||||
value: vec![
|
||||
|
@ -674,7 +674,7 @@ mod tests {
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_array_to_point3d() {
|
||||
let mut exec_state = ExecState::new(&ExecutorContext::new_mock().await);
|
||||
let mut exec_state = ExecState::new(&ExecutorContext::new_mock(None).await);
|
||||
let input = KclValue::HomArray {
|
||||
value: vec![
|
||||
KclValue::Number {
|
||||
@ -706,7 +706,7 @@ mod tests {
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_tuple_to_point3d() {
|
||||
let mut exec_state = ExecState::new(&ExecutorContext::new_mock().await);
|
||||
let mut exec_state = ExecState::new(&ExecutorContext::new_mock(None).await);
|
||||
let input = KclValue::Tuple {
|
||||
value: vec![
|
||||
KclValue::Number {
|
||||
|
@ -267,7 +267,7 @@ import \"a.kcl\"
|
||||
);
|
||||
modules.insert("b.kcl".to_owned(), into_module_info(b));
|
||||
|
||||
let ctx = ExecutorContext::new_mock().await;
|
||||
let ctx = ExecutorContext::new_mock(None).await;
|
||||
let order = import_graph(&modules, &ctx).unwrap();
|
||||
assert_eq!(vec![vec!["a.kcl".to_owned()], vec!["b.kcl".to_owned()]], order);
|
||||
}
|
||||
@ -290,7 +290,7 @@ x = 1
|
||||
);
|
||||
modules.insert("b.kcl".to_owned(), into_module_info(b));
|
||||
|
||||
let ctx = ExecutorContext::new_mock().await;
|
||||
let ctx = ExecutorContext::new_mock(None).await;
|
||||
let order = import_graph(&modules, &ctx).unwrap();
|
||||
assert_eq!(vec![vec!["a.kcl".to_owned(), "b.kcl".to_owned()]], order);
|
||||
}
|
||||
@ -316,7 +316,7 @@ import \"a.kcl\"
|
||||
);
|
||||
modules.insert("c.kcl".to_owned(), into_module_info(c));
|
||||
|
||||
let ctx = ExecutorContext::new_mock().await;
|
||||
let ctx = ExecutorContext::new_mock(None).await;
|
||||
let order = import_graph(&modules, &ctx).unwrap();
|
||||
assert_eq!(
|
||||
vec![vec!["a.kcl".to_owned()], vec!["b.kcl".to_owned(), "c.kcl".to_owned()]],
|
||||
@ -342,7 +342,7 @@ import \"a.kcl\"
|
||||
);
|
||||
modules.insert("b.kcl".to_owned(), into_module_info(b));
|
||||
|
||||
let ctx = ExecutorContext::new_mock().await;
|
||||
let ctx = ExecutorContext::new_mock(None).await;
|
||||
import_graph(&modules, &ctx).unwrap_err();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user