Skip to content

Commit

Permalink
convert from ItemFn to Pyo3TestCase using From/Into
Browse files Browse the repository at this point in the history
  • Loading branch information
MusicalNinjaDad committed Apr 14, 2024
1 parent aeb3d56 commit eccc2c5
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions pyo3-testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,23 @@ struct Pyo3TestCase {
statements: Vec<Stmt>,
}

impl From<ItemFn> for Pyo3TestCase {
fn from(testcase: ItemFn) -> Pyo3TestCase {
Pyo3TestCase {
imports: testcase
.attrs
.into_iter()
.map(|attr| { parsepyo3import(&attr) }.unwrap())
.collect(),
signature: testcase.sig,
statements: testcase.block.stmts,
}
}
}

#[allow(dead_code)] // Not yet fully implemented
fn impl_pyo3test(_attr: TokenStream2, input: TokenStream2) -> TokenStream2 {
let input: ItemFn = parse2(input).unwrap();
let testcase = Pyo3TestCase {
imports: input
.attrs
.into_iter()
.map(|attr| { parsepyo3import(&attr) }.unwrap())
.collect(),
signature: input.sig,
statements: input.block.stmts,
};
let testcase: Pyo3TestCase = parse2::<ItemFn>(input).unwrap().into();
wrap_testcase(testcase)
}

Expand Down

0 comments on commit eccc2c5

Please sign in to comment.