Skip to content

Commit

Permalink
Get all the tests building, everythign except doctests passes!
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Sep 16, 2020
1 parent a2dc4c1 commit ba10560
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion guide/src/class.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ You can also inherit native types such as `PyDict`, if they implement
However, because of some technical problems, we don't currently provide safe upcasting methods for types
that inherit native types. Even in such cases, you can unsafely get a base class by raw pointer conversion.

```rust
```rust,no_run
# use pyo3::prelude::*;
use pyo3::types::PyDict;
use pyo3::{AsPyPointer, PyNativeType};
Expand Down
3 changes: 1 addition & 2 deletions pyo3-derive-backend/src/from_pyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl<'a> Container<'a> {
let self_ty = &self.path;
let mut fields: Punctuated<TokenStream, syn::Token![,]> = Punctuated::new();
for i in 0..len {
fields.push(quote!(slice[#i].extract()?));
fields.push(quote!(s.get_item(#i).extract()?));
}
let msg = if self.is_enum_variant {
quote!(format!(
Expand All @@ -265,7 +265,6 @@ impl<'a> Container<'a> {
if s.len() != #len {
return Err(::pyo3::exceptions::PyValueError::new_err(#msg))
}
let slice = s.as_slice();
Ok(#self_ty(#fields))
)
}
Expand Down
4 changes: 3 additions & 1 deletion src/types/floatob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ impl<'source> FromPyObject<'source> for f32 {
mod test {
#[cfg(not(Py_LIMITED_API))]
use crate::ffi::PyFloat_AS_DOUBLE;
use crate::{AsPyPointer, Python, ToPyObject};
#[cfg(not(Py_LIMITED_API))]
use crate::AsPyPointer;
use crate::{Python, ToPyObject};

macro_rules! num_to_py_object_and_back (
($func_name:ident, $t1:ty, $t2:ty) => (
Expand Down
2 changes: 2 additions & 0 deletions tests/test_buffer_protocol.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(not(Py_LIMITED_API))]

use pyo3::buffer::PyBuffer;
use pyo3::class::PyBufferProtocol;
use pyo3::exceptions::PyBufferError;
Expand Down
4 changes: 4 additions & 0 deletions tests/test_dunder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ fn test_cls_impl() {
struct DunderDictSupport {}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn dunder_dict_support() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand All @@ -472,6 +473,7 @@ fn dunder_dict_support() {
}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn access_dunder_dict() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand All @@ -493,6 +495,7 @@ struct InheritDict {
}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn inherited_dict() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand All @@ -511,6 +514,7 @@ fn inherited_dict() {
struct WeakRefDunderDictSupport {}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn weakref_dunder_dict_support() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand Down
14 changes: 13 additions & 1 deletion tests/test_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ fn gc_integration2() {
struct WeakRefSupport {}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn weakref_support() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand All @@ -168,6 +169,7 @@ struct InheritWeakRef {
}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn inherited_weakref() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand Down Expand Up @@ -269,6 +271,16 @@ impl PyGCProtocol for TraversableClass {
}
}

#[cfg(PyPy)]
unsafe fn get_type_traverse(tp: *mut pyo3::ffi::PyTypeObject) -> Option<pyo3::ffi::traverseproc> {
(*tp).tp_traverse
}

#[cfg(not(PyPy))]
unsafe fn get_type_traverse(tp: *mut pyo3::ffi::PyTypeObject) -> Option<pyo3::ffi::traverseproc> {
std::mem::transmute(pyo3::ffi::PyType_GetSlot(tp, pyo3::ffi::Py_tp_traverse))
}

#[test]
fn gc_during_borrow() {
let gil = Python::acquire_gil();
Expand All @@ -285,7 +297,7 @@ fn gc_during_borrow() {

// get the traverse function
let ty = TraversableClass::type_object(py).as_type_ptr();
let traverse = (*ty).tp_traverse.unwrap();
let traverse = get_type_traverse(ty).unwrap();

// create an object and check that traversing it works normally
// when it's not borrowed
Expand Down
4 changes: 4 additions & 0 deletions tests/test_inheritance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ impl SetWithName {
}
}

// Subclassing builtin types is not allowed in the LIMITED API.
#[test]
#[cfg_attr(Py_LIMITED_API, should_panic)]
fn inherit_set() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand All @@ -195,7 +197,9 @@ impl DictWithName {
}
}

// Subclassing builtin types is not allowed in the LIMITED API.
#[test]
#[cfg_attr(Py_LIMITED_API, should_panic)]
fn inherit_dict() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand Down
3 changes: 3 additions & 0 deletions tests/test_pyfunction.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(Py_LIMITED_API))]
use pyo3::buffer::PyBuffer;
use pyo3::prelude::*;
use pyo3::types::{PyCFunction, PyFunction};
Expand All @@ -23,6 +24,7 @@ fn test_optional_bool() {
py_assert!(py, f, "f(None) == 'None'");
}

#[cfg(not(Py_LIMITED_API))]
#[pyfunction]
fn buffer_inplace_add(py: Python, x: PyBuffer<i32>, y: PyBuffer<i32>) {
let x = x.as_mut_slice(py).unwrap();
Expand All @@ -33,6 +35,7 @@ fn buffer_inplace_add(py: Python, x: PyBuffer<i32>, y: PyBuffer<i32>) {
}
}

#[cfg(not(Py_LIMITED_API))]
#[test]
fn test_buffer_add() {
let gil = Python::acquire_gil();
Expand Down
2 changes: 2 additions & 0 deletions tests/test_unsendable_dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ impl UnsendableDictClass {
}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn test_unsendable_dict() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand All @@ -32,6 +33,7 @@ impl UnsendableDictClassWithWeakRef {
}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn test_unsendable_dict_with_weakref() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand Down
1 change: 1 addition & 0 deletions tests/test_various.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ fn add_module(py: Python, module: &PyModule) -> PyResult<()> {
}

#[test]
#[cfg_attr(Py_LIMITED_API, ignore)]
fn test_pickle() {
let gil = Python::acquire_gil();
let py = gil.python();
Expand Down

0 comments on commit ba10560

Please sign in to comment.