2020-06-23 10:35:02 +00:00
|
|
|
import pytest
|
2022-02-05 09:39:56 +00:00
|
|
|
from pyo3_pytests import pyclasses
|
|
|
|
|
|
|
|
|
|
|
|
def test_empty_class_init(benchmark):
|
|
|
|
benchmark(pyclasses.EmptyClass)
|
|
|
|
|
|
|
|
|
|
|
|
class EmptyClassPy:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def test_empty_class_init_py(benchmark):
|
|
|
|
benchmark(EmptyClassPy)
|
2020-06-23 10:35:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_iter():
|
2022-02-05 09:39:56 +00:00
|
|
|
i = pyclasses.PyClassIter()
|
2020-06-23 10:35:02 +00:00
|
|
|
assert next(i) == 1
|
|
|
|
assert next(i) == 2
|
|
|
|
assert next(i) == 3
|
|
|
|
assert next(i) == 4
|
|
|
|
assert next(i) == 5
|
|
|
|
|
|
|
|
with pytest.raises(StopIteration) as excinfo:
|
|
|
|
next(i)
|
|
|
|
assert excinfo.value.value == "Ended"
|
2023-05-16 18:39:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AssertingSubClass(pyclasses.AssertingBaseClass):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def test_new_classmethod():
|
|
|
|
# The `AssertingBaseClass` constructor errors if it is not passed the relevant subclass.
|
|
|
|
_ = AssertingSubClass(expected_type=AssertingSubClass)
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
_ = AssertingSubClass(expected_type=str)
|