Skip to content

Commit

Permalink
GREEN: edgecase import modulefollowed by from module import function
Browse files Browse the repository at this point in the history
  • Loading branch information
MusicalNinjaDad committed Apr 17, 2024
1 parent d75b730 commit ec3b80b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pyo3-testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ fn wrap_testcase(testcase: Pyo3TestCase) -> TokenStream2 {
let mut pyo3_functionnames = Vec::<String>::new();
let mut AttributeErrormsgs = Vec::<String>::new();
let mut py_functionidents = Vec::<Ident>::new();
let mut py_moduleswithfnsidents = Vec::<Ident>::new();

for import in testcase.pythonimports {
o3_moduleidents.push(
Expand All @@ -121,21 +122,21 @@ fn wrap_testcase(testcase: Pyo3TestCase) -> TokenStream2 {
py_moduleidents.push(
Ident::new(&import.modulename, Span::mixed_site())
);
pyo3_modulenames.push(
import.modulename
);
ModuleNotFoundErrormsgs.push(
"Failed to import ".to_string() + pyo3_modulenames.iter().last().unwrap()
);
match import.functionname {
Some(functionname) => {
AttributeErrormsgs.push("Failed to get ".to_string() + &functionname + " function");
py_functionidents.push(Ident::new(&functionname, Span::call_site()));
py_moduleswithfnsidents.push(Ident::new(&import.modulename, Span::mixed_site()));
pyo3_functionnames.push(functionname);
}
None => {}
};

pyo3_modulenames.push(
import.modulename
);
ModuleNotFoundErrormsgs.push(
"Failed to import ".to_string() + pyo3_modulenames.iter().last().unwrap()
);
}

let testfn_signature = testcase.signature;
Expand All @@ -150,7 +151,7 @@ fn wrap_testcase(testcase: Pyo3TestCase) -> TokenStream2 {
#(let #py_moduleidents = py
.import_bound(#pyo3_modulenames) // import the wrapped module
.expect(#ModuleNotFoundErrormsgs);)*
#(let #py_functionidents = #py_moduleidents
#(let #py_functionidents = #py_moduleswithfnsidents
.getattr(#pyo3_functionnames) // import the wrapped function
.expect(#AttributeErrormsgs);)*
#(#testfn_statements)*
Expand Down

0 comments on commit ec3b80b

Please sign in to comment.