From 0b19afa1a3f199dd7ef8260c5be247533a570279 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 15 Jun 2020 15:19:48 +0200 Subject: [PATCH 1/3] parser-inc: fix invalid template args for std::map<> This fixes an interrogate warning. --- dtool/src/parser-inc/map | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dtool/src/parser-inc/map b/dtool/src/parser-inc/map index cabeb219bc..c7e01a8aab 100644 --- a/dtool/src/parser-inc/map +++ b/dtool/src/parser-inc/map @@ -28,19 +28,19 @@ namespace std { template class allocator; } -template, class Allocator = std::allocator > > +template, class Allocator = std::allocator > > class map { public: typedef Key key_type; - typedef Element data_type; - typedef Element mapped_type; - typedef pair value_type; + typedef T data_type; + typedef T mapped_type; + typedef pair value_type; typedef Compare key_compare; - typedef Element *pointer; - typedef const Element *const_pointer; - typedef Element &reference; - typedef const Element &const_reference; + typedef T *pointer; + typedef const T *const_pointer; + typedef T &reference; + typedef const T &const_reference; class iterator; class const_iterator; From 913ab6669e3b7cc9db116d166c18a2ecb3748966 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 15 Jun 2020 15:05:14 +0200 Subject: [PATCH 2/3] tests: Add more attribute tests to try to make coverage deterministic --- tests/pgraph/test_cullfaceattrib.py | 18 +++ tests/pgraph/test_lightattrib.py | 69 ++++++++++ tests/pgraph/test_shaderattrib.py | 20 +++ tests/pgraph/test_textureattrib.py | 202 ++++++++++++++++++++++++++++ 4 files changed, 309 insertions(+) create mode 100644 tests/pgraph/test_cullfaceattrib.py create mode 100644 tests/pgraph/test_shaderattrib.py create mode 100644 tests/pgraph/test_textureattrib.py diff --git a/tests/pgraph/test_cullfaceattrib.py b/tests/pgraph/test_cullfaceattrib.py new file mode 100644 index 0000000000..45bab0e1e5 --- /dev/null +++ b/tests/pgraph/test_cullfaceattrib.py @@ -0,0 +1,18 @@ +from panda3d.core import CullFaceAttrib + + +def test_cullfaceattrib_compare(): + clockwise1 = CullFaceAttrib.make() + clockwise2 = CullFaceAttrib.make() + reverse1 = CullFaceAttrib.make_reverse() + reverse2 = CullFaceAttrib.make_reverse() + + assert clockwise1.compare_to(clockwise2) == 0 + assert clockwise2.compare_to(clockwise1) == 0 + + assert reverse1.compare_to(reverse2) == 0 + assert reverse2.compare_to(reverse1) == 0 + + assert reverse1.compare_to(clockwise1) != 0 + assert clockwise1.compare_to(reverse1) != 0 + assert reverse1.compare_to(clockwise1) == -clockwise1.compare_to(reverse1) diff --git a/tests/pgraph/test_lightattrib.py b/tests/pgraph/test_lightattrib.py index 752f4c2717..a9f6268458 100644 --- a/tests/pgraph/test_lightattrib.py +++ b/tests/pgraph/test_lightattrib.py @@ -72,3 +72,72 @@ def test_lightattrib_compose_alloff(): assert lattr3.get_num_on_lights() == 0 assert lattr3.get_num_off_lights() == 0 assert lattr3.has_all_off() + + +def test_lightattrib_compare(): + lattr1 = core.LightAttrib.make() + lattr2 = core.LightAttrib.make() + assert lattr1.compare_to(lattr2) == 0 + + # All-off should not compare equal to empty + lattr2 = core.LightAttrib.make_all_off() + assert lattr1.compare_to(lattr2) != 0 + assert lattr2.compare_to(lattr1) != 0 + assert lattr2.compare_to(lattr1) == -lattr1.compare_to(lattr2) + + # If both have the same light, they are equal + lattr1 = core.LightAttrib.make() + lattr1 = lattr1.add_on_light(spot) + lattr2 = core.LightAttrib.make() + lattr2 = lattr2.add_on_light(spot) + assert lattr1.compare_to(lattr2) == 0 + assert lattr2.compare_to(lattr1) == 0 + + # Adding an extra light makes it unequal + lattr2 = lattr2.add_on_light(point) + assert lattr1.compare_to(lattr2) != 0 + assert lattr2.compare_to(lattr1) != 0 + assert lattr2.compare_to(lattr1) == -lattr1.compare_to(lattr2) + + # Different lights altogether is of course unequal + lattr1 = core.LightAttrib.make() + lattr1 = lattr1.add_on_light(point) + lattr2 = core.LightAttrib.make() + lattr2 = lattr2.add_on_light(spot) + assert lattr1.compare_to(lattr2) != 0 + assert lattr2.compare_to(lattr1) != 0 + assert lattr2.compare_to(lattr1) == -lattr1.compare_to(lattr2) + + # An on light is not the same as an off light + lattr1 = core.LightAttrib.make().add_on_light(spot) + lattr2 = core.LightAttrib.make().add_off_light(spot) + assert lattr1.compare_to(lattr2) != 0 + assert lattr2.compare_to(lattr1) != 0 + assert lattr2.compare_to(lattr1) == -lattr1.compare_to(lattr2) + + # If both have the same off light, they are equal + lattr1 = core.LightAttrib.make().add_off_light(spot) + lattr2 = core.LightAttrib.make().add_off_light(spot) + assert lattr1.compare_to(lattr2) == 0 + assert lattr2.compare_to(lattr1) == 0 + + # Off light should not be equal to empty + lattr1 = core.LightAttrib.make().add_off_light(spot) + lattr2 = core.LightAttrib.make_all_off() + assert lattr1.compare_to(lattr2) != 0 + assert lattr2.compare_to(lattr1) != 0 + assert lattr2.compare_to(lattr1) == -lattr1.compare_to(lattr2) + + # Off light should not be equal to all-off + lattr1 = core.LightAttrib.make().add_off_light(spot) + lattr2 = core.LightAttrib.make_all_off() + assert lattr1.compare_to(lattr2) != 0 + assert lattr2.compare_to(lattr1) != 0 + assert lattr2.compare_to(lattr1) == -lattr1.compare_to(lattr2) + + # Different off lights shouldn't be equal either, of course + lattr1 = core.LightAttrib.make().add_off_light(spot) + lattr2 = core.LightAttrib.make().add_off_light(point) + assert lattr1.compare_to(lattr2) != 0 + assert lattr2.compare_to(lattr1) != 0 + assert lattr2.compare_to(lattr1) == -lattr1.compare_to(lattr2) diff --git a/tests/pgraph/test_shaderattrib.py b/tests/pgraph/test_shaderattrib.py new file mode 100644 index 0000000000..9b136328ae --- /dev/null +++ b/tests/pgraph/test_shaderattrib.py @@ -0,0 +1,20 @@ +from panda3d import core + + +def test_shaderattrib_compare(): + shattr1 = core.ShaderAttrib.make() + shattr2 = core.ShaderAttrib.make() + assert shattr1.compare_to(shattr2) == 0 + assert shattr2.compare_to(shattr1) == 0 + + shattr2 = core.ShaderAttrib.make().set_flag(core.ShaderAttrib.F_subsume_alpha_test, False) + assert shattr1.compare_to(shattr2) != 0 + assert shattr2.compare_to(shattr1) != 0 + + shattr1 = core.ShaderAttrib.make().set_flag(core.ShaderAttrib.F_subsume_alpha_test, False) + assert shattr1.compare_to(shattr2) == 0 + assert shattr2.compare_to(shattr1) == 0 + + shattr2 = core.ShaderAttrib.make().set_flag(core.ShaderAttrib.F_subsume_alpha_test, True) + assert shattr1.compare_to(shattr2) != 0 + assert shattr2.compare_to(shattr1) != 0 diff --git a/tests/pgraph/test_textureattrib.py b/tests/pgraph/test_textureattrib.py new file mode 100644 index 0000000000..2be4b479f3 --- /dev/null +++ b/tests/pgraph/test_textureattrib.py @@ -0,0 +1,202 @@ +from panda3d import core + +# Some dummy textures we can use for our texture attributes. +stage1 = core.TextureStage("stage1") +stage2 = core.TextureStage("stage2") +stage3 = core.TextureStage("stage3") +tex1 = core.Texture("tex1") +tex2 = core.Texture("tex2") +tex3 = core.Texture("tex3") + + +def test_textureattrib_compose_empty(): + # Tests a case in which a child node does not alter the original. + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage1, tex1) + + tattr2 = core.TextureAttrib.make() + + tattr3 = tattr1.compose(tattr2) + assert tattr3.get_num_on_stages() == 1 + + assert stage1 in tattr3.on_stages + + +def test_textureattrib_compose_add(): + # Tests a case in which a child node adds another texture. + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage1, tex1) + + tattr2 = core.TextureAttrib.make() + tattr2 = tattr2.add_on_stage(stage2, tex2) + + tattr3 = tattr1.compose(tattr2) + assert tattr3.get_num_on_stages() == 2 + + assert stage1 in tattr3.on_stages + assert stage2 in tattr3.on_stages + + +def test_textureattrib_compose_override(): + # Tests a case in which a child node overrides a texture. + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage1, tex1) + + tattr2 = core.TextureAttrib.make() + tattr2 = tattr2.add_on_stage(stage1, tex2) + + tattr3 = tattr1.compose(tattr2) + assert tattr3.get_num_on_stages() == 1 + + assert stage1 in tattr3.on_stages + assert tattr3.get_on_texture(stage1) == tex2 + + +def test_textureattrib_compose_subtract(): + # Tests a case in which a child node disables a texture. + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage1, tex1) + tattr1 = tattr1.add_on_stage(stage2, tex2) + + tattr2 = core.TextureAttrib.make() + tattr2 = tattr2.add_off_stage(stage3) + tattr2 = tattr2.add_off_stage(stage2) + + tattr3 = tattr1.compose(tattr2) + assert tattr3.get_num_on_stages() == 1 + + assert stage1 in tattr3.on_stages + assert stage2 not in tattr3.on_stages + assert stage3 not in tattr3.on_stages + + +def test_textureattrib_compose_both(): + # Tests a case in which a child node both enables and disables a texture. + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage1, tex1) + tattr1 = tattr1.add_on_stage(stage2, tex2) + + tattr2 = core.TextureAttrib.make() + tattr2 = tattr2.add_on_stage(stage3, tex3) + tattr2 = tattr2.add_on_stage(stage1, tex1) + tattr2 = tattr2.add_off_stage(stage2) + + tattr3 = tattr1.compose(tattr2) + assert tattr3.get_num_on_stages() == 2 + + assert stage1 in tattr3.on_stages + assert stage2 not in tattr3.on_stages + assert stage3 in tattr3.on_stages + + +def test_textureattrib_implicit_sort(): + # Tests that two TextureStages with same sort retain insertion order. + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage1, tex1) + tattr1 = tattr1.add_on_stage(stage2, tex2) + + assert tattr1.get_on_stage(0) == stage1 + assert tattr1.get_on_stage(1) == stage2 + + tattr2 = core.TextureAttrib.make() + tattr2 = tattr1.add_on_stage(stage2, tex2) + tattr2 = tattr1.add_on_stage(stage1, tex1) + + assert tattr2.get_on_stage(0) == stage2 + assert tattr2.get_on_stage(1) == stage1 + + assert tattr1.compare_to(tattr2) == -tattr2.compare_to(tattr1) + + +def test_textureattrib_compose_alloff(): + # Tests a case in which a child node disables all textures. + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage1, tex1) + tattr1 = tattr1.add_on_stage(stage2, tex2) + assert tattr1.get_num_on_stages() == 2 + + tattr2 = core.TextureAttrib.make_all_off() + assert tattr2.has_all_off() + + tattr3 = tattr1.compose(tattr2) + assert tattr3.get_num_on_stages() == 0 + assert tattr3.get_num_off_stages() == 0 + assert tattr3.has_all_off() + + +def test_textureattrib_compare(): + tattr1 = core.TextureAttrib.make() + tattr2 = core.TextureAttrib.make() + assert tattr1.compare_to(tattr2) == 0 + + # All-off should not compare equal to empty + tattr2 = core.TextureAttrib.make_all_off() + assert tattr1.compare_to(tattr2) != 0 + assert tattr2.compare_to(tattr1) != 0 + assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2) + + # Empty stage is not the same as a single off stage + tattr1 = core.TextureAttrib.make() + tattr2 = core.TextureAttrib.make() + tattr2 = tattr2.add_off_stage(stage1) + assert tattr1.compare_to(tattr2) != 0 + assert tattr2.compare_to(tattr1) != 0 + assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2) + + # All-off stage is not the same as a single off stage + tattr1 = core.TextureAttrib.make_all_off() + tattr2 = core.TextureAttrib.make() + tattr2 = tattr2.add_off_stage(stage1) + assert tattr1.compare_to(tattr2) != 0 + assert tattr2.compare_to(tattr1) != 0 + assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2) + + # Different off stages are non-equal + tattr1 = core.TextureAttrib.make_all_off() + tattr1 = tattr2.add_off_stage(stage1) + tattr2 = core.TextureAttrib.make() + tattr2 = tattr2.add_off_stage(stage2) + assert tattr1.compare_to(tattr2) != 0 + assert tattr2.compare_to(tattr1) != 0 + assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2) + + # If both have a different texture, but same stage, they are not equal + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage1, tex1) + tattr2 = core.TextureAttrib.make() + tattr2 = tattr2.add_on_stage(stage1, tex2) + assert tattr1.compare_to(tattr2) != 0 + assert tattr2.compare_to(tattr1) != 0 + assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2) + + # If both have the same texture, but different stage, they are not equal + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage1, tex1) + tattr2 = core.TextureAttrib.make() + tattr2 = tattr2.add_on_stage(stage2, tex2) + assert tattr1.compare_to(tattr2) != 0 + assert tattr2.compare_to(tattr1) != 0 + assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2) + + # If both have the same texture and stage, they are equal + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage1, tex1) + tattr2 = core.TextureAttrib.make() + tattr2 = tattr2.add_on_stage(stage1, tex1) + assert tattr1.compare_to(tattr2) == 0 + assert tattr2.compare_to(tattr1) == 0 + + # Adding an extra texture makes it unequal + tattr2 = tattr2.add_on_stage(stage2, tex2) + assert tattr1.compare_to(tattr2) != 0 + assert tattr2.compare_to(tattr1) != 0 + assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2) + + # Different textures altogether is of course unequal + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage2, tex2) + tattr2 = core.TextureAttrib.make() + tattr2 = tattr2.add_on_stage(stage1, tex1) + assert tattr1.compare_to(tattr2) != 0 + assert tattr2.compare_to(tattr1) != 0 + assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2) From 86cfbc22b1cebdde998f9705a7a7b8aba94b5b7e Mon Sep 17 00:00:00 2001 From: Fireclaw Date: Mon, 15 Jun 2020 11:29:46 +0200 Subject: [PATCH 3/3] direct: Fix errors in PythonUtil.detectLeaks() function (#955) * Replaced removed choice() function with ternary expression * Add sanity check for _crashOnProactiveLeakDetect, don't crash by default Closes #955 --- direct/src/showbase/DirectObject.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/direct/src/showbase/DirectObject.py b/direct/src/showbase/DirectObject.py index 778328ea50..0833b1890a 100644 --- a/direct/src/showbase/DirectObject.py +++ b/direct/src/showbase/DirectObject.py @@ -94,12 +94,12 @@ class DirectObject: if hasattr(self, '_taskList'): tasks = [task.name for task in self._taskList.values()] if len(events) or len(tasks): - estr = choice(len(events), 'listening to events: %s' % events, '') - andStr = choice(len(events) and len(tasks), ' and ', '') - tstr = choice(len(tasks), '%srunning tasks: %s' % (andStr, tasks), '') + estr = ('listening to events: %s' % events if len(events) else '') + andStr = (' and ' if len(events) and len(tasks) else '') + tstr = ('%srunning tasks: %s' % (andStr, tasks) if len(tasks) else '') notify = directNotify.newCategory('LeakDetect') - func = choice(getRepository()._crashOnProactiveLeakDetect, - self.notify.error, self.notify.warning) + crash = getattr(getRepository(), '_crashOnProactiveLeakDetect', False) + func = (self.notify.error if crash else self.notify.warning) func('destroyed %s instance is still %s%s' % (self.__class__.__name__, estr, tstr)) #snake_case alias: