mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-19 22:39:09 +00:00
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and comment styles started in #898. For the most part, the test coverage here is unchanged, with a few minor exceptions as noted below. - test_constants_and_functions: this adds more overload tests with overloads with different number of arguments for more comprehensive overload_cast testing. The test style conversion broke the overload tests under MSVC 2015, prompting the additional tests while looking for a workaround. - test_eigen: this dropped the unused functions `get_cm_corners` and `get_cm_corners_const`--these same tests were duplicates of the same things provided (and used) via ReturnTester methods. - test_opaque_types: this test had a hidden dependence on ExampleMandA which is now fixed by using the global UserType which suffices for the relevant test. - test_methods_and_attributes: this required some additions to UserType to make it usable as a replacement for the test's previous SimpleType: UserType gained a value mutator, and the `value` property is not mutable (it was previously readonly). Some overload tests were also added to better test overload_cast (as described above). - test_numpy_array: removed the untemplated mutate_data/mutate_data_t: the templated versions with an empty parameter pack expand to the same thing. - test_stl: this was already mostly in the new style; this just tweaks things a bit, localizing a class, and adding some missing `// test_whatever` comments. - test_virtual_functions: like `test_stl`, this was mostly in the new test style already, but needed some `// test_whatever` comments. This commit also moves the inherited virtual example code to the end of the file, after the main set of tests (since it is less important than the other tests, and rather length); it also got renamed to `test_inherited_virtuals` (from `test_inheriting_repeat`) because it tests both inherited virtual approaches, not just the repeat approach.
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import pytest
|
||||
from pybind11_tests import operators as m
|
||||
from pybind11_tests import ConstructorStats
|
||||
|
||||
|
||||
def test_operator_overloading():
|
||||
from pybind11_tests.operators import Vector2, Vector
|
||||
|
||||
v1 = Vector2(1, 2)
|
||||
v2 = Vector(3, -1)
|
||||
v1 = m.Vector2(1, 2)
|
||||
v2 = m.Vector(3, -1)
|
||||
assert str(v1) == "[1.000000, 2.000000]"
|
||||
assert str(v2) == "[3.000000, -1.000000]"
|
||||
|
||||
@@ -36,7 +35,7 @@ def test_operator_overloading():
|
||||
v2 /= v1
|
||||
assert str(v2) == "[2.000000, 8.000000]"
|
||||
|
||||
cstats = ConstructorStats.get(Vector2)
|
||||
cstats = ConstructorStats.get(m.Vector2)
|
||||
assert cstats.alive() == 2
|
||||
del v1
|
||||
assert cstats.alive() == 1
|
||||
@@ -59,9 +58,8 @@ def test_operator_overloading():
|
||||
|
||||
def test_operators_notimplemented():
|
||||
"""#393: need to return NotSupported to ensure correct arithmetic operator behavior"""
|
||||
from pybind11_tests.operators import C1, C2
|
||||
|
||||
c1, c2 = C1(), C2()
|
||||
c1, c2 = m.C1(), m.C2()
|
||||
assert c1 + c1 == 11
|
||||
assert c2 + c2 == 22
|
||||
assert c2 + c1 == 21
|
||||
@@ -70,24 +68,23 @@ def test_operators_notimplemented():
|
||||
|
||||
def test_nested():
|
||||
"""#328: first member in a class can't be used in operators"""
|
||||
from pybind11_tests.operators import NestA, NestB, NestC, get_NestA, get_NestB, get_NestC
|
||||
|
||||
a = NestA()
|
||||
b = NestB()
|
||||
c = NestC()
|
||||
a = m.NestA()
|
||||
b = m.NestB()
|
||||
c = m.NestC()
|
||||
|
||||
a += 10
|
||||
assert get_NestA(a) == 13
|
||||
assert m.get_NestA(a) == 13
|
||||
b.a += 100
|
||||
assert get_NestA(b.a) == 103
|
||||
assert m.get_NestA(b.a) == 103
|
||||
c.b.a += 1000
|
||||
assert get_NestA(c.b.a) == 1003
|
||||
assert m.get_NestA(c.b.a) == 1003
|
||||
b -= 1
|
||||
assert get_NestB(b) == 3
|
||||
assert m.get_NestB(b) == 3
|
||||
c.b -= 3
|
||||
assert get_NestB(c.b) == 1
|
||||
assert m.get_NestB(c.b) == 1
|
||||
c *= 7
|
||||
assert get_NestC(c) == 35
|
||||
assert m.get_NestC(c) == 35
|
||||
|
||||
abase = a.as_base()
|
||||
assert abase.value == -2
|
||||
|
||||
Reference in New Issue
Block a user