Skip to content

Commit 6668d6e

Browse files
committed
fix test_inherited_size
1 parent bc6a302 commit 6668d6e

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

src/pycell/impl_.rs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,9 @@ mod tests {
615615
#[pyclass(crate = "crate", extends = ImmutableChildOfImmutableBase, frozen)]
616616
struct ImmutableChildOfImmutableChildOfImmutableBase;
617617

618+
#[pyclass(crate = "crate")]
619+
struct BaseWithoutData;
620+
618621
#[pyclass(crate = "crate", subclass)]
619622
struct BaseWithData(#[allow(unused)] u64);
620623

@@ -624,16 +627,35 @@ mod tests {
624627
#[pyclass(crate = "crate", extends = BaseWithData)]
625628
struct ChildWithoutData;
626629

627-
// #[test]
628-
// fn test_inherited_size() {
629-
// let base_size = PyStaticClassObject::<BaseWithData>::BASIC_SIZE;
630-
// assert!(base_size > 0); // negative indicates variable sized
631-
// assert_eq!(
632-
// base_size,
633-
// PyStaticClassObject::<ChildWithoutData>::BASIC_SIZE
634-
// );
635-
// assert!(base_size < PyStaticClassObject::<ChildWithData>::BASIC_SIZE);
636-
// }
630+
#[test]
631+
fn test_inherited_size() {
632+
#[cfg(_Py_OPAQUE_PYOBJECT)]
633+
type ClassObject<T> = PyVariableClassObject<T>;
634+
#[cfg(not(_Py_OPAQUE_PYOBJECT))]
635+
type ClassObject<T> = PyStaticClassObject<T>;
636+
637+
let base_without_data_size = ClassObject::<BaseWithoutData>::BASIC_SIZE;
638+
let base_with_data_size = ClassObject::<BaseWithData>::BASIC_SIZE;
639+
let child_without_data_size = ClassObject::<ChildWithoutData>::BASIC_SIZE;
640+
let child_with_data_size = ClassObject::<ChildWithData>::BASIC_SIZE;
641+
#[cfg(_Py_OPAQUE_PYOBJECT)]
642+
{
643+
assert!(base_without_data_size < 0); // negative indicates variable sized
644+
assert!(base_with_data_size < base_without_data_size);
645+
assert_eq!(child_without_data_size, 0);
646+
assert_eq!(
647+
base_with_data_size - base_without_data_size,
648+
child_with_data_size
649+
);
650+
}
651+
#[cfg(not(_Py_OPAQUE_PYOBJECT))]
652+
{
653+
assert!(base_without_data_size > 0);
654+
assert!(base_with_data_size > base_without_data_size);
655+
assert_eq!(base_with_data_size, child_without_data_size);
656+
assert!(base_with_data_size < child_with_data_size);
657+
}
658+
}
637659

638660
fn assert_mutable<T: PyClass<Frozen = False, PyClassMutability = MutableClass>>() {}
639661
fn assert_immutable<T: PyClass<Frozen = True, PyClassMutability = ImmutableClass>>() {}

0 commit comments

Comments
 (0)