From 856bd86cd1e635c940b8c4c8df8b33975daf9647 Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Fri, 8 May 2020 16:51:13 +0200 Subject: [PATCH 1/2] Add test for platform mesh sizes <=1MB As a result of Cura and Cookies discussion, we decided to limit the sizes of platform meshes to less than 1MB. This test checks that during the CI/CD process and displays an assertion error when a mesh excludes this limit. --- tests/Machines/TestPlatformMeshes.py | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/Machines/TestPlatformMeshes.py diff --git a/tests/Machines/TestPlatformMeshes.py b/tests/Machines/TestPlatformMeshes.py new file mode 100644 index 0000000000..2daf677112 --- /dev/null +++ b/tests/Machines/TestPlatformMeshes.py @@ -0,0 +1,31 @@ +import pytest + +import os +import os.path + + +__exclude_filenames = ["UltimakerRobot_support.stl"] + + +def collecAllPlatformMeshes(): + result = [] + for root, directories, filenames in os.walk(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "resources", "meshes"))): + for filename in filenames: + if os.path.basename(filename) not in __exclude_filenames: + result.append(os.path.join(root, filename)) + return result + + +platform_mesh_filepaths = collecAllPlatformMeshes() +MAX_MESH_FILE_SIZE = 1 * 1024 * 1024 # 1MB + + +# Check if the platform meshes adhere to the maximum file size (1MB) +@pytest.mark.parametrize("file_name", platform_mesh_filepaths) +def test_validatePlatformMeshSizes(file_name): + assert os.path.getsize(file_name) <= MAX_MESH_FILE_SIZE, \ + "Platform mesh {} should be less than {}KB. Current file size: {}KB.".format( + file_name, + round(MAX_MESH_FILE_SIZE / 1024), + round(os.path.getsize(file_name) / 1024, 2) + ) From 1e2764278edb40897869fa8df241d54d38017255 Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Fri, 8 May 2020 16:58:33 +0200 Subject: [PATCH 2/2] Remove unnecessary os.path.basename call --- tests/Machines/TestPlatformMeshes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Machines/TestPlatformMeshes.py b/tests/Machines/TestPlatformMeshes.py index 2daf677112..7c9de8daf5 100644 --- a/tests/Machines/TestPlatformMeshes.py +++ b/tests/Machines/TestPlatformMeshes.py @@ -11,7 +11,7 @@ def collecAllPlatformMeshes(): result = [] for root, directories, filenames in os.walk(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "resources", "meshes"))): for filename in filenames: - if os.path.basename(filename) not in __exclude_filenames: + if filename not in __exclude_filenames: result.append(os.path.join(root, filename)) return result