From 1dfabe25914d119b171cbd24f804108794d724a8 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 20 Feb 2023 18:11:08 +0500 Subject: [PATCH] Fixed issue with float vectors assertion during tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `sequence.feature` - Added `[:]` to make errors more readable values in errors (for example, (0.20000000298023224, 0.20000000298023224, 0.20000000298023224, 1.0) instead of `` `test_feature.py` - fixed `FAILED test/bim/test_feature.py::test_animate_the_consumption_of_a_wall - AssertionError: Value is ` Test was failing because of float garbage in object.color (the comparison was (0.20000000298023224, 0.20000000298023224, 0.20000000298023224, 1.0) <> [0.2, 0.2, 0.2, 1] ) After that fix all tests now are passed 🥲 --- .../test/bim/feature/sequence.feature | 32 +++++++++---------- src/blenderbim/test/bim/test_feature.py | 10 +++++- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/blenderbim/test/bim/feature/sequence.feature b/src/blenderbim/test/bim/feature/sequence.feature index 7073f30ff2..5f1612c518 100644 --- a/src/blenderbim/test/bim/feature/sequence.feature +++ b/src/blenderbim/test/bim/feature/sequence.feature @@ -365,9 +365,9 @@ Scenario: Animate the construction of a wall When I am on frame "2" Then "scene.objects.get('IfcWall/Cube').hide_viewport" is "False" And "scene.objects.get('IfcWall/Cube').hide_render" is "False" - And "scene.objects.get('IfcWall/Cube').color" is "[0.0, 1.0, 0.0, 1]" + And "scene.objects.get('IfcWall/Cube').color[:]" is "[0.0, 1.0, 0.0, 1]" When I am on frame "7" - Then "scene.objects.get('IfcWall/Cube').color" is "[1.0, 1.0, 1.0, 1]" + Then "scene.objects.get('IfcWall/Cube').color[:]" is "[1.0, 1.0, 1.0, 1]" Scenario: Animate the demolition of a wall Given an empty IFC project @@ -398,15 +398,15 @@ Scenario: Animate the demolition of a wall When I am on frame "1" Then "scene.objects.get('IfcWall/Cube').hide_viewport" is "False" And "scene.objects.get('IfcWall/Cube').hide_render" is "False" - And "scene.objects.get('IfcWall/Cube').color" is "[1.0, 1.0, 1.0, 1]" + And "scene.objects.get('IfcWall/Cube').color[:]" is "[1.0, 1.0, 1.0, 1]" When I am on frame "2" Then "scene.objects.get('IfcWall/Cube').hide_viewport" is "False" And "scene.objects.get('IfcWall/Cube').hide_render" is "False" - And "scene.objects.get('IfcWall/Cube').color" is "[1.0, 0.0, 0.0, 1]" + And "scene.objects.get('IfcWall/Cube').color[:]" is "[1.0, 0.0, 0.0, 1]" When I am on frame "7" Then "scene.objects.get('IfcWall/Cube').hide_viewport" is "True" And "scene.objects.get('IfcWall/Cube').hide_render" is "True" - And "scene.objects.get('IfcWall/Cube').color" is "[0.0, 0.0, 0.0, 1]" + And "scene.objects.get('IfcWall/Cube').color[:]" is "[0.0, 0.0, 0.0, 1]" Scenario: Animate the operation of a wall Given an empty IFC project @@ -435,11 +435,11 @@ Scenario: Animate the operation of a wall And I set "scene.BIMWorkScheduleProperties.speed_real_duration" to "P1W" And I press "bim.visualise_work_schedule_date_range(work_schedule={work_schedule})" When I am on frame "1" - Then "scene.objects.get('IfcWall/Cube').color" is "[1.0, 1.0, 1.0, 1]" + Then "scene.objects.get('IfcWall/Cube').color[:]" is "[1.0, 1.0, 1.0, 1]" When I am on frame "2" - Then "scene.objects.get('IfcWall/Cube').color" is "[0.0, 0.0, 1.0, 1]" + Then "scene.objects.get('IfcWall/Cube').color[:]" is "[0.0, 0.0, 1.0, 1]" When I am on frame "7" - Then "scene.objects.get('IfcWall/Cube').color" is "[1.0, 1.0, 1.0, 1]" + Then "scene.objects.get('IfcWall/Cube').color[:]" is "[1.0, 1.0, 1.0, 1]" Scenario: Animate the movement of a wall Given an empty IFC project @@ -475,23 +475,23 @@ Scenario: Animate the movement of a wall And I set "scene.BIMWorkScheduleProperties.speed_real_duration" to "P1W" And I press "bim.visualise_work_schedule_date_range(work_schedule={work_schedule})" When I am on frame "1" - Then "scene.objects.get('IfcWall/FromObject').color" is "[1.0, 1.0, 1.0, 1]" + Then "scene.objects.get('IfcWall/FromObject').color[:]" is "[1.0, 1.0, 1.0, 1]" And "scene.objects.get('IfcWall/FromObject').hide_viewport" is "False" And "scene.objects.get('IfcWall/FromObject').hide_render" is "False" And "scene.objects.get('IfcWall/ToObject').hide_viewport" is "True" And "scene.objects.get('IfcWall/ToObject').hide_render" is "True" When I am on frame "2" - Then "scene.objects.get('IfcWall/FromObject').color" is "[1.0, 0.5, 0.0, 1]" + Then "scene.objects.get('IfcWall/FromObject').color[:]" is "[1.0, 0.5, 0.0, 1]" And "scene.objects.get('IfcWall/FromObject').hide_viewport" is "False" And "scene.objects.get('IfcWall/FromObject').hide_render" is "False" - And "scene.objects.get('IfcWall/ToObject').color" is "[1.0, 1.0, 0.0, 1]" + And "scene.objects.get('IfcWall/ToObject').color[:]" is "[1.0, 1.0, 0.0, 1]" And "scene.objects.get('IfcWall/ToObject').hide_viewport" is "False" And "scene.objects.get('IfcWall/ToObject').hide_render" is "False" When I am on frame "7" - Then "scene.objects.get('IfcWall/FromObject').color" is "[0.0, 0.0, 0.0, 1]" + Then "scene.objects.get('IfcWall/FromObject').color[:]" is "[0.0, 0.0, 0.0, 1]" Then "scene.objects.get('IfcWall/FromObject').hide_viewport" is "True" Then "scene.objects.get('IfcWall/FromObject').hide_render" is "True" - And "scene.objects.get('IfcWall/ToObject').color" is "[1.0, 1.0, 1.0, 1]" + And "scene.objects.get('IfcWall/ToObject').color[:]" is "[1.0, 1.0, 1.0, 1]" And "scene.objects.get('IfcWall/ToObject').hide_viewport" is "False" And "scene.objects.get('IfcWall/ToObject').hide_render" is "False" @@ -519,15 +519,15 @@ Scenario: Animate the consumption of a wall And I set "scene.BIMWorkScheduleProperties.speed_real_duration" to "P1W" And I press "bim.visualise_work_schedule_date_range(work_schedule={work_schedule})" When I am on frame "1" - Then "scene.objects.get('IfcWall/Cube').color" is "[1.0, 1.0, 1.0, 1]" + Then "scene.objects.get('IfcWall/Cube').color[:]" is "[1.0, 1.0, 1.0, 1]" And "scene.objects.get('IfcWall/Cube').hide_viewport" is "False" And "scene.objects.get('IfcWall/Cube').hide_render" is "False" When I am on frame "2" - Then "scene.objects.get('IfcWall/Cube').color" is "[0.2, 0.2, 0.2, 1]" + Then "scene.objects.get('IfcWall/Cube').color[:]" is "[0.2, 0.2, 0.2, 1]" And "scene.objects.get('IfcWall/Cube').hide_viewport" is "False" And "scene.objects.get('IfcWall/Cube').hide_render" is "False" When I am on frame "7" - Then "scene.objects.get('IfcWall/Cube').color" is "[0.0, 0.0, 0.0, 1]" + Then "scene.objects.get('IfcWall/Cube').color[:]" is "[0.0, 0.0, 0.0, 1]" Then "scene.objects.get('IfcWall/Cube').hide_viewport" is "True" Then "scene.objects.get('IfcWall/Cube').hide_render" is "True" diff --git a/src/blenderbim/test/bim/test_feature.py b/src/blenderbim/test/bim/test_feature.py index e1d48426fe..602b858d46 100644 --- a/src/blenderbim/test/bim/test_feature.py +++ b/src/blenderbim/test/bim/test_feature.py @@ -51,6 +51,10 @@ def replace_variables(value): def is_x(number, x): return abs(number - x) < 1e-6 +def vectors_are_equal(v1, v2): + assert len(v1) == len(v2), f"Compared vectors are not equal length: {v1}, {v2}" + return all(is_x(v1[i], v2[i]) for i in range(len(v1))) + @given("an untestable scenario") def an_untestable_scenario(): @@ -490,7 +494,11 @@ def prop_is_value(prop, value): exec(f"assert list(bpy.context.{prop}) == {value}") is_value = True except: - pass + try: + exec(f"assert vectors_are_equal(bpy.context.{prop}, {value})") + is_value = True + except: + pass if not is_value: print(f"bpy.context.{prop}") actual_value = eval(f"bpy.context.{prop}")