diff options
Diffstat (limited to 'tests')
134 files changed, 7905 insertions, 13 deletions
diff --git a/tests/gtests/alembic/CMakeLists.txt b/tests/gtests/alembic/CMakeLists.txt index 1511024ee51..3e794898ebe 100644 --- a/tests/gtests/alembic/CMakeLists.txt +++ b/tests/gtests/alembic/CMakeLists.txt @@ -28,6 +28,7 @@ set(INC ../../../source/blender/blenkernel ../../../source/blender/alembic ../../../source/blender/makesdna + ../../../source/blender/depsgraph ${ALEMBIC_INCLUDE_DIRS} ${BOOST_INCLUDE_DIR} ${HDF5_INCLUDE_DIRS} diff --git a/tests/gtests/alembic/abc_export_test.cc b/tests/gtests/alembic/abc_export_test.cc index a3eb2c412df..b040f375221 100644 --- a/tests/gtests/alembic/abc_export_test.cc +++ b/tests/gtests/alembic/abc_export_test.cc @@ -11,11 +11,16 @@ extern "C" { #include "DNA_scene_types.h" } +#include "DEG_depsgraph.h" + class TestableAbcExporter : public AbcExporter { public: - TestableAbcExporter(Main *bmain, Scene *scene, const char *filename, ExportSettings &settings) - : AbcExporter(bmain, scene, filename, settings) - {} + TestableAbcExporter(Main *bmain, EvaluationContext *eval_ctx, + Scene *scene, ViewLayer *view_layer, Depsgraph *depsgraph, + const char *filename, ExportSettings &settings) + : AbcExporter(bmain, eval_ctx, scene, view_layer, depsgraph, filename, settings) + { + } void getShutterSamples(unsigned int nr_of_samples, bool time_relative, @@ -28,7 +33,6 @@ public: std::set<double> &frames) { AbcExporter::getFrameSet(nr_of_samples, frames); } - }; class AlembicExportTest : public testing::Test @@ -36,6 +40,8 @@ class AlembicExportTest : public testing::Test protected: ExportSettings settings; Scene scene; + EvaluationContext eval_ctx; + Depsgraph *depsgraph; TestableAbcExporter *exporter; Main *bmain; @@ -50,19 +56,25 @@ protected: bmain = BKE_main_new(); + /* TODO(sergey): Pass scene layer somehow? */ + DEG_evaluation_context_init(&eval_ctx, DAG_EVAL_VIEWPORT); + depsgraph = DEG_graph_new(); + exporter = NULL; } virtual void TearDown() { BKE_main_free(bmain); + DEG_graph_free(depsgraph); delete exporter; } // Call after setting up the settings. void createExporter() { - exporter = new TestableAbcExporter(bmain, &scene, "somefile.abc", settings); + ViewLayer *view_layer = (ViewLayer *)scene.view_layers.first; + exporter = new TestableAbcExporter(bmain, &eval_ctx, &scene, view_layer, depsgraph, "somefile.abc", settings); } }; diff --git a/tests/gtests/blenlib/BLI_memiter_test.cc b/tests/gtests/blenlib/BLI_memiter_test.cc new file mode 100644 index 00000000000..601eadea267 --- /dev/null +++ b/tests/gtests/blenlib/BLI_memiter_test.cc @@ -0,0 +1,206 @@ +/* Apache License, Version 2.0 */ + +#include "testing/testing.h" + +extern "C" { +#include "BLI_array_utils.h" +#include "BLI_memiter.h" +#include "MEM_guardedalloc.h" + +#include "BLI_string.h" +#include "BLI_ressource_strings.h" +} + +TEST(memiter, Nop) +{ + BLI_memiter *mi = BLI_memiter_create(64); + BLI_memiter_destroy(mi); +} + +void memiter_empty_test(int num_elems, const int chunk_size) +{ + BLI_memiter *mi = BLI_memiter_create(chunk_size); + void *data; + for (int index = 0; index < num_elems; index++) { + data = BLI_memiter_alloc(mi, 0); + } + int index = 0, total_size = 0; + BLI_memiter_handle it; + BLI_memiter_iter_init(mi, &it); + uint elem_size; + while ((data = BLI_memiter_iter_step_size(&it, &elem_size))) { + index += 1; + total_size += elem_size; + } + EXPECT_EQ(0, total_size); + EXPECT_EQ(num_elems, index); + + BLI_memiter_destroy(mi); +} + +#define MEMITER_NUMBER_TEST_FN(fn, number_type) \ +void fn(int num_elems, const int chunk_size) \ +{ \ + BLI_memiter *mi = BLI_memiter_create(chunk_size); \ + number_type *data; \ + for (int index = 0; index < num_elems; index++) { \ + data = (number_type *)BLI_memiter_alloc(mi, sizeof(number_type)); \ + *data = index; \ + } \ + BLI_memiter_handle it; \ + BLI_memiter_iter_init(mi, &it); \ + uint elem_size; \ + int index = 0; \ + while ((data = (number_type *)BLI_memiter_iter_step_size(&it, &elem_size))) { \ + EXPECT_EQ(sizeof(number_type), elem_size); \ + EXPECT_EQ(index, *data); \ + index += 1; \ + } \ + BLI_memiter_destroy(mi); \ +} + +/* generate number functions */ +MEMITER_NUMBER_TEST_FN(memiter_char_test, char) +MEMITER_NUMBER_TEST_FN(memiter_short_test, short) +MEMITER_NUMBER_TEST_FN(memiter_int_test, int) +MEMITER_NUMBER_TEST_FN(memiter_long_test, int64_t) + +void memiter_string_test(const char *strings[], const int chunk_size) +{ + BLI_memiter *mi = BLI_memiter_create(chunk_size); + char *data; + int index = 0; + int total_size_expect = 0; + while (strings[index]) { + const int size = strlen(strings[index]) + 1; + BLI_memiter_alloc_from(mi, size, strings[index]); + total_size_expect += size; + index += 1; + } + const int strings_len = index; + int total_size = 0; + BLI_memiter_handle it; + BLI_memiter_iter_init(mi, &it); + uint elem_size; + index = 0; + while ((data = (char *)BLI_memiter_iter_step_size(&it, &elem_size))) { + EXPECT_EQ(strlen(strings[index]) + 1, elem_size); + EXPECT_STREQ(strings[index], data); + total_size += elem_size; + index += 1; + } + EXPECT_EQ(total_size_expect, total_size); + EXPECT_EQ(strings_len, index); + + BLI_memiter_destroy(mi); +} + +void memiter_words10k_test(const char split_char, const int chunk_size) +{ + const int words_len = sizeof(words10k) - 1; + char *words = BLI_strdupn(words10k, words_len); + BLI_str_replace_char(words, split_char, '\0'); + + BLI_memiter *mi = BLI_memiter_create(chunk_size); + + char *data; + int index; + char *c_end, *c; + c_end = words + words_len; + c = words; + index = 0; + while (c < c_end) { + int elem_size = strlen(c) + 1; + data = (char *)BLI_memiter_alloc(mi, elem_size); + memcpy(data, c, elem_size); + c += elem_size; + index += 1; + } + const int len_expect = index; + c = words; + uint size; + BLI_memiter_handle it; + BLI_memiter_iter_init(mi, &it); + index = 0; + while ((data = (char *)BLI_memiter_iter_step_size(&it, &size))) { + int size_expect = strlen(c) + 1; + EXPECT_EQ(size_expect, size); + EXPECT_STREQ(c, data); + c += size; + index += 1; + } + EXPECT_EQ(len_expect, index); + BLI_memiter_destroy(mi); + MEM_freeN(words); +} + + +#define TEST_EMPTY_AT_CHUNK_SIZE(chunk_size) \ +TEST(memiter, Empty0_##chunk_size) { memiter_empty_test(0, chunk_size); } \ +TEST(memiter, Empty1_##chunk_size) { memiter_empty_test(1, chunk_size); } \ +TEST(memiter, Empty2_##chunk_size) { memiter_empty_test(2, chunk_size); } \ +TEST(memiter, Empty3_##chunk_size) { memiter_empty_test(3, chunk_size); } \ +TEST(memiter, Empty13_##chunk_size) { memiter_empty_test(13, chunk_size); } \ +TEST(memiter, Empty256_##chunk_size) { memiter_empty_test(256, chunk_size); } \ + +TEST_EMPTY_AT_CHUNK_SIZE(1) +TEST_EMPTY_AT_CHUNK_SIZE(2) +TEST_EMPTY_AT_CHUNK_SIZE(3) +TEST_EMPTY_AT_CHUNK_SIZE(13) +TEST_EMPTY_AT_CHUNK_SIZE(256) + +#define TEST_NUMBER_AT_CHUNK_SIZE(chunk_size) \ +TEST(memiter, Char1_##chunk_size) { memiter_char_test(1, chunk_size); } \ +TEST(memiter, Short1_##chunk_size) { memiter_short_test(1, chunk_size); } \ +TEST(memiter, Int1_##chunk_size) { memiter_int_test(1, chunk_size); } \ +TEST(memiter, Long1_##chunk_size) { memiter_long_test(1, chunk_size); } \ +\ +TEST(memiter, Char2_##chunk_size) { memiter_char_test(2, chunk_size); } \ +TEST(memiter, Short2_##chunk_size) { memiter_short_test(2, chunk_size); } \ +TEST(memiter, Int2_##chunk_size) { memiter_int_test(2, chunk_size); } \ +TEST(memiter, Long2_##chunk_size) { memiter_long_test(2, chunk_size); } \ +\ +TEST(memiter, Char3_##chunk_size) { memiter_char_test(3, chunk_size); } \ +TEST(memiter, Short3_##chunk_size) { memiter_short_test(3, chunk_size); } \ +TEST(memiter, Int3_##chunk_size) { memiter_int_test(3, chunk_size); } \ +TEST(memiter, Long3_##chunk_size) { memiter_long_test(3, chunk_size); } \ +\ +TEST(memiter, Char256_##chunk_size) { memiter_char_test(256, chunk_size); } \ +TEST(memiter, Short256_##chunk_size) { memiter_short_test(256, chunk_size); } \ +TEST(memiter, Int256_##chunk_size) { memiter_int_test(256, chunk_size); } \ +TEST(memiter, Long256_##chunk_size) { memiter_long_test(256, chunk_size); } \ + +TEST_NUMBER_AT_CHUNK_SIZE(1) +TEST_NUMBER_AT_CHUNK_SIZE(2) +TEST_NUMBER_AT_CHUNK_SIZE(3) +TEST_NUMBER_AT_CHUNK_SIZE(13) +TEST_NUMBER_AT_CHUNK_SIZE(256) + +#define STRINGS_TEST(chunk_size, ...) { \ + const char *data[] = {__VA_ARGS__, NULL}; \ + memiter_string_test(data, chunk_size); \ +} + +#define TEST_STRINGS_AT_CHUNK_SIZE(chunk_size) \ +TEST(memiter, Strings_##chunk_size) { \ + STRINGS_TEST(chunk_size, ""); \ + STRINGS_TEST(chunk_size, "test", "me"); \ + STRINGS_TEST(chunk_size, "more", "test", "data", "to", "follow"); \ +} + +TEST_STRINGS_AT_CHUNK_SIZE(1) +TEST_STRINGS_AT_CHUNK_SIZE(2) +TEST_STRINGS_AT_CHUNK_SIZE(3) +TEST_STRINGS_AT_CHUNK_SIZE(13) +TEST_STRINGS_AT_CHUNK_SIZE(256) + + +#define TEST_WORDS10K_AT_CHUNK_SIZE(chunk_size) \ +TEST(memiter, Words10kSentence_##chunk_size) { memiter_words10k_test('.', chunk_size); } \ +TEST(memiter, Words10kWords_##chunk_size) { memiter_words10k_test(' ', chunk_size); } \ + +TEST_WORDS10K_AT_CHUNK_SIZE(1) +TEST_WORDS10K_AT_CHUNK_SIZE(2) +TEST_WORDS10K_AT_CHUNK_SIZE(3) +TEST_WORDS10K_AT_CHUNK_SIZE(13) +TEST_WORDS10K_AT_CHUNK_SIZE(256) diff --git a/tests/gtests/blenlib/CMakeLists.txt b/tests/gtests/blenlib/CMakeLists.txt index cc1c95bd0fe..ea2b2741f8c 100644 --- a/tests/gtests/blenlib/CMakeLists.txt +++ b/tests/gtests/blenlib/CMakeLists.txt @@ -51,6 +51,7 @@ BLENDER_TEST(BLI_listbase "bf_blenlib") BLENDER_TEST(BLI_math_base "bf_blenlib") BLENDER_TEST(BLI_math_color "bf_blenlib") BLENDER_TEST(BLI_math_geom "bf_blenlib") +BLENDER_TEST(BLI_memiter "bf_blenlib") BLENDER_TEST(BLI_path_util "${BLI_path_util_extra_libs}") BLENDER_TEST(BLI_polyfill_2d "bf_blenlib") BLENDER_TEST(BLI_stack "bf_blenlib") diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt index 9b1807b796b..3abfe29c000 100644 --- a/tests/python/CMakeLists.txt +++ b/tests/python/CMakeLists.txt @@ -630,3 +630,4 @@ if(WITH_CODEC_FFMPEG) endif() add_subdirectory(collada) +add_subdirectory(view_layer) diff --git a/tests/python/bl_alembic_import_test.py b/tests/python/bl_alembic_import_test.py index 1b526b3ebba..e9499fb08f0 100644 --- a/tests/python/bl_alembic_import_test.py +++ b/tests/python/bl_alembic_import_test.py @@ -63,7 +63,7 @@ class SimpleImportTest(AbstractAlembicTest): # The objects should be linked to scene_collection in Blender 2.8, # and to scene in Blender 2.7x. - objects = bpy.context.scene.objects + objects = bpy.context.scene_collection.objects self.assertEqual(13, len(objects)) # Test the hierarchy. @@ -83,7 +83,7 @@ class SimpleImportTest(AbstractAlembicTest): # The objects should be linked to scene_collection in Blender 2.8, # and to scene in Blender 2.7x. - objects = bpy.context.scene.objects + objects = bpy.context.scene_collection.objects # ABC parent is top-level object, which translates to nothing in Blender self.assertIsNone(objects['locator1'].parent) @@ -128,7 +128,7 @@ class SimpleImportTest(AbstractAlembicTest): # All cubes should be selected, but the sphere shouldn't be. for ob in bpy.data.objects: - self.assertEqual('Cube' in ob.name, ob.select) + self.assertEqual('Cube' in ob.name, ob.select_get()) def test_change_path_constraint(self): import math @@ -183,17 +183,19 @@ class SimpleImportTest(AbstractAlembicTest): # Check that the file loaded ok. bpy.context.scene.frame_set(6) - mesh = plane.to_mesh(bpy.context.scene, True, 'RENDER') + scene = bpy.context.scene + layer = scene.view_layers[scene.active_layer] + mesh = plane.to_mesh(scene, layer, True, 'RENDER') self.assertAlmostEqual(-1, mesh.vertices[0].co.x) self.assertAlmostEqual(-1, mesh.vertices[0].co.y) self.assertAlmostEqual(0.5905638933181763, mesh.vertices[0].co.z) # Change path from absolute to relative. This should not break the animation. - bpy.context.scene.frame_set(1) + scene.frame_set(1) bpy.data.cache_files[fname].filepath = relpath - bpy.context.scene.frame_set(6) + scene.frame_set(6) - mesh = plane.to_mesh(bpy.context.scene, True, 'RENDER') + mesh = plane.to_mesh(scene, layer, True, 'RENDER') self.assertAlmostEqual(1, mesh.vertices[3].co.x) self.assertAlmostEqual(1, mesh.vertices[3].co.y) self.assertAlmostEqual(0.5905638933181763, mesh.vertices[3].co.z) diff --git a/tests/python/bl_mesh_modifiers.py b/tests/python/bl_mesh_modifiers.py index bff2c31984c..f202e5b6611 100644 --- a/tests/python/bl_mesh_modifiers.py +++ b/tests/python/bl_mesh_modifiers.py @@ -248,7 +248,7 @@ def mesh_uv_add(obj): (1.0, 1.0), (1.0, 0.0)) - uv_lay = obj.data.uv_textures.new() + uv_lay = obj.data.uv_layers.new() # XXX, odd that we need to do this. until UV's and texface # are separated we will need to keep it diff --git a/tests/python/view_layer/CMakeLists.txt b/tests/python/view_layer/CMakeLists.txt new file mode 100644 index 00000000000..77a56fb47f9 --- /dev/null +++ b/tests/python/view_layer/CMakeLists.txt @@ -0,0 +1,187 @@ +# ***** BEGIN GPL LICENSE BLOCK ***** +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# Contributor(s): Jacques Beaurain, Dalai Felinto. +# +# ***** END GPL LICENSE BLOCK ***** + +# --env-system-scripts allows to run without the install target. + +# Use '--write-blend=/tmp/test.blend' to view output + +set(TEST_SRC_DIR ${CMAKE_SOURCE_DIR}/../lib/tests) +set(TEST_OUT_DIR ${CMAKE_BINARY_DIR}/tests) + +# ugh, any better way to do this on testing only? +execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_OUT_DIR}) + +#~ if(NOT IS_DIRECTORY ${TEST_SRC_DIR}) +#~ message(FATAL_ERROR "CMake test directory not found!") +#~ endif() + +# all calls to blender use this +if(APPLE) + if(${CMAKE_GENERATOR} MATCHES "Xcode") + set(TEST_BLENDER_EXE ${EXECUTABLE_OUTPUT_PATH}/Debug/blender.app/Contents/MacOS/blender) + else() + set(TEST_BLENDER_EXE ${EXECUTABLE_OUTPUT_PATH}/blender.app/Contents/MacOS/blender) + endif() +else() + set(TEST_BLENDER_EXE ${EXECUTABLE_OUTPUT_PATH}/blender) +endif() + +# for testing with valgrind prefix: valgrind --track-origins=yes --error-limit=no +set(TEST_BLENDER_EXE ${TEST_BLENDER_EXE} --background -noaudio --factory-startup --env-system-scripts ${CMAKE_SOURCE_DIR}/release/scripts) + + +# ------------------------------------------------------------------------------ + +macro(VIEW_LAYER_TEST test_name) + # Adds ${CMAKE_CURRENT_LIST_DIR} to sys.path so that the tests can import + # things from view_layer_common.py + add_test(view_layer_${test_name} ${TEST_BLENDER_EXE} + --python-expr "import sys; sys.path.append('${CMAKE_CURRENT_LIST_DIR}')" + --python-exit-code 1 + --python ${CMAKE_CURRENT_LIST_DIR}/test_${test_name}.py -- + --testdir="${TEST_SRC_DIR}/layers" + ) +endmacro() + +VIEW_LAYER_TEST(active_collection) +VIEW_LAYER_TEST(background_set) +VIEW_LAYER_TEST(collection_new_sync) +VIEW_LAYER_TEST(collection_rename_a) +VIEW_LAYER_TEST(collection_rename_b) +VIEW_LAYER_TEST(evaluation_render_settings_a) +VIEW_LAYER_TEST(evaluation_render_settings_b) +VIEW_LAYER_TEST(evaluation_render_settings_c) +VIEW_LAYER_TEST(evaluation_render_settings_d) +VIEW_LAYER_TEST(evaluation_render_settings_e) +VIEW_LAYER_TEST(evaluation_render_settings_f) +VIEW_LAYER_TEST(evaluation_render_settings_g) +VIEW_LAYER_TEST(evaluation_render_settings_h) +VIEW_LAYER_TEST(evaluation_render_settings_i) +VIEW_LAYER_TEST(evaluation_visibility_a) +VIEW_LAYER_TEST(evaluation_visibility_b) +VIEW_LAYER_TEST(evaluation_visibility_c) +VIEW_LAYER_TEST(evaluation_visibility_d) +VIEW_LAYER_TEST(evaluation_visibility_e) +VIEW_LAYER_TEST(evaluation_visibility_f) +VIEW_LAYER_TEST(evaluation_visibility_g) +VIEW_LAYER_TEST(evaluation_visibility_h) +VIEW_LAYER_TEST(evaluation_visibility_i) +VIEW_LAYER_TEST(evaluation_visibility_j) +VIEW_LAYER_TEST(evaluation_selectability_a) +VIEW_LAYER_TEST(evaluation_selectability_b) +VIEW_LAYER_TEST(evaluation_selectability_c) +VIEW_LAYER_TEST(evaluation_selectability_d) +VIEW_LAYER_TEST(evaluation_selectability_e) +VIEW_LAYER_TEST(evaluation_selectability_f) +VIEW_LAYER_TEST(group_a) +VIEW_LAYER_TEST(group_b) +VIEW_LAYER_TEST(group_c) +VIEW_LAYER_TEST(group_d) +VIEW_LAYER_TEST(group_e) +VIEW_LAYER_TEST(object_add_cylinder) +VIEW_LAYER_TEST(object_add_empty) +VIEW_LAYER_TEST(object_add_torus) +VIEW_LAYER_TEST(object_add_no_collection_cylinder) +VIEW_LAYER_TEST(object_add_no_collection_empty) +VIEW_LAYER_TEST(object_add_no_collection_torus) +VIEW_LAYER_TEST(object_copy) +VIEW_LAYER_TEST(object_delete_a) +VIEW_LAYER_TEST(object_delete_b) +VIEW_LAYER_TEST(object_link_a) +VIEW_LAYER_TEST(object_link_b) +VIEW_LAYER_TEST(object_link_c) +VIEW_LAYER_TEST(operator_context) +VIEW_LAYER_TEST(move_above_below_scene_collection_a) +VIEW_LAYER_TEST(move_above_below_scene_collection_b) +VIEW_LAYER_TEST(move_above_below_scene_collection_c) +VIEW_LAYER_TEST(move_above_below_scene_collection_d) +VIEW_LAYER_TEST(move_above_below_scene_collection_e) +VIEW_LAYER_TEST(move_above_below_scene_collection_f) +VIEW_LAYER_TEST(move_above_below_scene_collection_g) +VIEW_LAYER_TEST(move_above_below_scene_collection_h) +VIEW_LAYER_TEST(move_above_below_scene_collection_i) +VIEW_LAYER_TEST(move_above_below_scene_collection_sync_a) +VIEW_LAYER_TEST(move_above_below_scene_collection_sync_b) +VIEW_LAYER_TEST(move_above_below_scene_collection_sync_c) +VIEW_LAYER_TEST(move_above_below_scene_collection_sync_d) +VIEW_LAYER_TEST(move_above_below_scene_collection_sync_e) +VIEW_LAYER_TEST(move_above_below_scene_collection_sync_f) +VIEW_LAYER_TEST(move_above_below_scene_collection_sync_g) +VIEW_LAYER_TEST(move_above_below_scene_collection_sync_h) +VIEW_LAYER_TEST(move_above_below_scene_collection_sync_i) +VIEW_LAYER_TEST(move_into_scene_collection_a) +VIEW_LAYER_TEST(move_into_scene_collection_b) +VIEW_LAYER_TEST(move_into_scene_collection_c) +VIEW_LAYER_TEST(move_into_scene_collection_d) +VIEW_LAYER_TEST(move_into_scene_collection_e) +VIEW_LAYER_TEST(move_into_scene_collection_f) +VIEW_LAYER_TEST(move_into_scene_collection_g) +VIEW_LAYER_TEST(move_into_scene_collection_h) +VIEW_LAYER_TEST(move_into_scene_collection_i) +VIEW_LAYER_TEST(move_into_scene_collection_j) +VIEW_LAYER_TEST(move_into_scene_collection_k) +VIEW_LAYER_TEST(move_into_scene_collection_l) +VIEW_LAYER_TEST(move_into_scene_collection_sync_a) +VIEW_LAYER_TEST(move_into_scene_collection_sync_b) +VIEW_LAYER_TEST(move_into_scene_collection_sync_c) +VIEW_LAYER_TEST(move_into_scene_collection_sync_d) +VIEW_LAYER_TEST(move_into_scene_collection_sync_e) +VIEW_LAYER_TEST(move_into_scene_collection_sync_f) +VIEW_LAYER_TEST(move_into_scene_collection_sync_g) +VIEW_LAYER_TEST(move_into_scene_collection_sync_h) +VIEW_LAYER_TEST(move_into_scene_collection_sync_i) +VIEW_LAYER_TEST(move_into_scene_collection_sync_j) +VIEW_LAYER_TEST(move_into_scene_collection_sync_k) +VIEW_LAYER_TEST(move_into_scene_collection_sync_l) +VIEW_LAYER_TEST(move_above_below_layer_collection_a) +VIEW_LAYER_TEST(move_above_below_layer_collection_b) +VIEW_LAYER_TEST(move_above_below_layer_collection_c) +VIEW_LAYER_TEST(move_above_below_layer_collection_d) +VIEW_LAYER_TEST(move_above_below_layer_collection_e) +VIEW_LAYER_TEST(move_above_below_layer_collection_f) +VIEW_LAYER_TEST(move_above_below_layer_collection_g) +VIEW_LAYER_TEST(move_above_below_layer_collection_h) +VIEW_LAYER_TEST(move_above_below_layer_collection_i) +VIEW_LAYER_TEST(move_above_below_layer_collection_j) +VIEW_LAYER_TEST(move_above_below_layer_collection_k) +VIEW_LAYER_TEST(move_above_below_layer_collection_l) +VIEW_LAYER_TEST(move_into_layer_collection_a) +VIEW_LAYER_TEST(move_into_layer_collection_b) +VIEW_LAYER_TEST(move_into_layer_collection_c) +VIEW_LAYER_TEST(move_into_layer_collection_d) +VIEW_LAYER_TEST(move_into_layer_collection_e) +VIEW_LAYER_TEST(move_into_layer_collection_f) +VIEW_LAYER_TEST(move_into_layer_collection_g) +VIEW_LAYER_TEST(move_into_layer_collection_h) +VIEW_LAYER_TEST(move_into_layer_collection_i) +VIEW_LAYER_TEST(move_into_layer_collection_j) +VIEW_LAYER_TEST(layer_linking) +VIEW_LAYER_TEST(layer_syncing) +VIEW_LAYER_TEST(scene_collection_delete) +VIEW_LAYER_TEST(scene_copy_a) +VIEW_LAYER_TEST(scene_copy_b) +VIEW_LAYER_TEST(scene_copy_c) +VIEW_LAYER_TEST(scene_copy_d) +VIEW_LAYER_TEST(scene_copy_e) +VIEW_LAYER_TEST(scene_copy_f) +VIEW_LAYER_TEST(scene_delete) +VIEW_LAYER_TEST(scene_objects) +VIEW_LAYER_TEST(scene_write_read) +VIEW_LAYER_TEST(view_layer_rename) diff --git a/tests/python/view_layer/test_active_collection.py b/tests/python/view_layer/test_active_collection.py new file mode 100644 index 00000000000..10df71f77ce --- /dev/null +++ b/tests/python/view_layer/test_active_collection.py @@ -0,0 +1,70 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_active_collection(self): + """ + See if active collection index is working + layer.collections.active_index works recursively + """ + import bpy + import os + + ROOT = self.get_root() + filepath_layers = os.path.join(ROOT, 'layers.blend') + + # open file + bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_layers) + self.rename_collections() + + # create sub-collections + three_b = bpy.data.objects.get('T.3b') + three_c = bpy.data.objects.get('T.3c') + + scene = bpy.context.scene + subzero = scene.master_collection.collections['1'].collections.new('sub-zero') + scorpion = subzero.collections.new('scorpion') + subzero.objects.link(three_b) + scorpion.objects.link(three_c) + layer = scene.view_layers.new('Fresh new Layer') + layer.collections.link(subzero) + + lookup = [ + 'Master Collection', + '1', + 'sub-zero', + 'scorpion', + '2', + '3', + '4', + '5', + 'sub-zero', + 'scorpion'] + + for i, name in enumerate(lookup): + layer.collections.active_index = i + self.assertEqual( + name, layer.collections.active.name, + "Collection index mismatch: [{0}] : {1} != {2}".format( + i, name, layer.collections.active.name)) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_background_set.py b/tests/python/view_layer/test_background_set.py new file mode 100644 index 00000000000..a26229d53a9 --- /dev/null +++ b/tests/python/view_layer/test_background_set.py @@ -0,0 +1,64 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_background_set(self): + """ + See if background sets are properly added and removed + """ + import bpy + + background_scene = bpy.data.scenes[0] + main_scene = bpy.data.scenes.new('main') + bpy.context.window.scene = main_scene + + # Update depsgraph. + main_scene.update() + + # Safety check, there should be no objects in thew newly created scene. + self.assertEqual(0, len(bpy.context.depsgraph.objects)) + + # Now set the background set, and objects relationship. + main_scene.background_set = background_scene + background_scene.objects[0].parent = background_scene.objects[1] + + # Update depsgraph. + main_scene.update() + + # Test if objects were properly added to depsgraph. + self.assertEqual(3, len(bpy.context.depsgraph.objects)) + + # We now check if the objects are properly flagged as from set + # These objects can't be possible nor show their origins or + # relationship lines + for ob in bpy.context.depsgraph.objects: + self.assertTrue(ob.is_from_set) + + # Test if removing is working fine. + main_scene.background_set = None + + # Update depsgraph. + main_scene.update() + + self.assertEqual(0, len(bpy.context.depsgraph.objects)) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_collection_new_sync.py b/tests/python/view_layer/test_collection_new_sync.py new file mode 100644 index 00000000000..582e6c13d89 --- /dev/null +++ b/tests/python/view_layer/test_collection_new_sync.py @@ -0,0 +1,47 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_view_layer_syncing(self): + """ + See if we can copy view layers. + """ + import bpy + scene = bpy.context.scene + view_layer = scene.view_layers.new("All") + + self.assertEqual(len(view_layer.collections), 1) + self.assertEqual(view_layer.collections[0].collection, scene.master_collection) + + self.assertEqual( + {collection.name for collection in view_layer.collections[0].collections}, + {'Collection 1'}) + + self.assertEqual( + bpy.ops.outliner.collection_new(), + {'FINISHED'}) + + self.assertEqual( + {collection.name for collection in view_layer.collections[0].collections}, + {'Collection 1', 'Collection 2'}) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_collection_rename_a.py b/tests/python/view_layer/test_collection_rename_a.py new file mode 100644 index 00000000000..ea156d7346f --- /dev/null +++ b/tests/python/view_layer/test_collection_rename_a.py @@ -0,0 +1,91 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def setup_family(self): + import bpy + scene = bpy.context.scene + + # Just add a bunch of collections on which we can do various tests. + grandma = scene.master_collection.collections.new('grandma') + grandpa = scene.master_collection.collections.new('grandpa') + mom = grandma.collections.new('mom') + son = mom.collections.new('son') + daughter = mom.collections.new('daughter') + uncle = grandma.collections.new('uncle') + cousin = uncle.collections.new('cousin') + + lookup = {c.name: c for c in (grandma, grandpa, mom, son, daughter, uncle, cousin)} + return lookup + + def test_rename_a(self): + family = self.setup_family() + + family['mom'].name = family['daughter'].name + # Since they are not siblings, we allow them to have the same name. + self.assertEqual(family['mom'].name, family['daughter'].name) + + def test_rename_b(self): + family = self.setup_family() + + family['grandma'].name = family['grandpa'].name + self.assertNotEqual(family['grandma'].name, family['grandpa'].name) + + def test_rename_c(self): + family = self.setup_family() + + family['cousin'].name = family['daughter'].name + # Since they are not siblings, we allow them to have the same name. + self.assertEqual(family['cousin'].name, family['daughter'].name) + + def test_rename_d(self): + family = self.setup_family() + + family['son'].name = family['daughter'].name + self.assertNotEqual(family['son'].name, family['daughter'].name) + + def test_rename_e(self): + family = self.setup_family() + + family['grandma'].name = family['grandpa'].name + self.assertNotEqual(family['grandma'].name, family['grandpa'].name) + + def test_add_equal_name_a(self): + family = self.setup_family() + + other_daughter = family['mom'].collections.new(family['daughter'].name) + self.assertNotEqual(other_daughter.name, family['daughter'].name) + + def test_add_equal_name_b(self): + family = self.setup_family() + + other_aunt = family['grandma'].collections.new(family['daughter'].name) + # Since they are not siblings, we allow them to have the same name. + self.assertEqual(other_aunt.name, family['daughter'].name) + + def test_add_equal_name_c(self): + family = self.setup_family() + + other_aunt = family['grandma'].collections.new(family['mom'].name) + self.assertNotEqual(other_aunt.name, family['mom'].name) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_collection_rename_b.py b/tests/python/view_layer/test_collection_rename_b.py new file mode 100644 index 00000000000..3787066e1b9 --- /dev/null +++ b/tests/python/view_layer/test_collection_rename_b.py @@ -0,0 +1,58 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def setup_collections(self): + import bpy + scene = bpy.context.scene + + master = scene.master_collection + one = master.collections[0] + two = master.collections.new() + sub = two.collections.new(one.name) + + self.assertEqual(one.name, sub.name) + + lookup = { + 'master': master, + 'one': one, + 'two': two, + 'sub': sub, + } + return lookup + + def test_move_above(self): + collections = self.setup_collections() + collections['sub'].move_above(collections['one']) + self.assertNotEqual(collections['one'].name, collections['sub'].name) + + def test_move_below(self): + collections = self.setup_collections() + collections['sub'].move_below(collections['one']) + self.assertNotEqual(collections['one'].name, collections['sub'].name) + + def test_move_into(self): + collections = self.setup_collections() + collections['sub'].move_into(collections['master']) + self.assertNotEqual(collections['one'].name, collections['sub'].name) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_render_settings_a.py b/tests/python/view_layer/test_evaluation_render_settings_a.py new file mode 100644 index 00000000000..e1e78ecdc13 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_render_settings_a.py @@ -0,0 +1,33 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_render_settings(self): + """ + See if the depsgraph evaluation is correct + """ + clay = Clay() + self.assertEqual(clay.get('object', 'matcap_icon'), '01') + clay.set('scene', 'matcap_icon', '05') + self.assertEqual(clay.get('object', 'matcap_icon'), '05') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_render_settings_b.py b/tests/python/view_layer/test_evaluation_render_settings_b.py new file mode 100644 index 00000000000..5cc055095a1 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_render_settings_b.py @@ -0,0 +1,34 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_render_settings(self): + """ + See if the depsgraph evaluation is correct + """ + clay = Clay() + self.assertEqual(clay.get('object', 'matcap_icon'), '01') + clay.set('scene', 'matcap_icon', '05') + clay.set('grandma', 'matcap_icon', '03') + self.assertEqual(clay.get('object', 'matcap_icon'), '03') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_render_settings_c.py b/tests/python/view_layer/test_evaluation_render_settings_c.py new file mode 100644 index 00000000000..805f6949ba2 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_render_settings_c.py @@ -0,0 +1,33 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_render_settings(self): + """ + See if the depsgraph evaluation is correct + """ + clay = Clay() + self.assertEqual(clay.get('object', 'matcap_icon'), '01') + clay.set('mom', 'matcap_icon', '02') + self.assertEqual(clay.get('object', 'matcap_icon'), '02') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_render_settings_d.py b/tests/python/view_layer/test_evaluation_render_settings_d.py new file mode 100644 index 00000000000..9fa90b66931 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_render_settings_d.py @@ -0,0 +1,33 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_render_settings(self): + """ + See if the depsgraph evaluation is correct + """ + clay = Clay() + self.assertEqual(clay.get('object', 'matcap_icon'), '01') + clay.set('kid', 'matcap_icon', '05') + self.assertEqual(clay.get('object', 'matcap_icon'), '05') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_render_settings_e.py b/tests/python/view_layer/test_evaluation_render_settings_e.py new file mode 100644 index 00000000000..e5cb8b2b295 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_render_settings_e.py @@ -0,0 +1,34 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_render_settings(self): + """ + See if the depsgraph evaluation is correct + """ + clay = Clay() + self.assertEqual(clay.get('object', 'matcap_icon'), '01') + clay.set('grandma', 'matcap_icon', '04') + clay.set('kid', 'matcap_icon', '05') + self.assertEqual(clay.get('object', 'matcap_icon'), '05') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_render_settings_f.py b/tests/python/view_layer/test_evaluation_render_settings_f.py new file mode 100644 index 00000000000..e7e834ff7fa --- /dev/null +++ b/tests/python/view_layer/test_evaluation_render_settings_f.py @@ -0,0 +1,35 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_render_settings(self): + """ + See if the depsgraph evaluation is correct + """ + clay = Clay(extra_kid_layer=True) + self.assertEqual(clay.get('object', 'matcap_icon'), '01') + + clay.set('scene', 'matcap_icon', '05') + clay.set('extra', 'matcap_icon', '07') + self.assertEqual(clay.get('object', 'matcap_icon'), '07') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_render_settings_g.py b/tests/python/view_layer/test_evaluation_render_settings_g.py new file mode 100644 index 00000000000..32f3529eef8 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_render_settings_g.py @@ -0,0 +1,35 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_render_settings(self): + """ + See if the depsgraph evaluation is correct + """ + clay = Clay(extra_kid_layer=True) + self.assertEqual(clay.get('object', 'matcap_icon'), '01') + + clay.set('mom', 'matcap_icon', '02') + clay.set('extra', 'matcap_icon', '06') + self.assertEqual(clay.get('object', 'matcap_icon'), '06') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_render_settings_h.py b/tests/python/view_layer/test_evaluation_render_settings_h.py new file mode 100644 index 00000000000..3e175068006 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_render_settings_h.py @@ -0,0 +1,35 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_render_settings(self): + """ + See if the depsgraph evaluation is correct + """ + clay = Clay(extra_kid_layer=True) + self.assertEqual(clay.get('object', 'matcap_icon'), '01') + + clay.set('kid', 'matcap_icon', '02') + clay.set('extra', 'matcap_icon', '04') + self.assertEqual(clay.get('object', 'matcap_icon'), '04') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_render_settings_i.py b/tests/python/view_layer/test_evaluation_render_settings_i.py new file mode 100644 index 00000000000..e84c360f859 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_render_settings_i.py @@ -0,0 +1,35 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_render_settings(self): + """ + See if the depsgraph evaluation is correct + """ + clay = Clay(extra_kid_layer=True) + self.assertEqual(clay.get('object', 'matcap_icon'), '01') + + clay.set('mom', 'matcap_icon', '02') + self.assertEqual(clay.get('extra', 'matcap_icon'), '01') + self.assertEqual(clay.get('object', 'matcap_icon'), '02') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_selectability_a.py b/tests/python/view_layer/test_evaluation_selectability_a.py new file mode 100644 index 00000000000..bd80f638ef4 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_selectability_a.py @@ -0,0 +1,54 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_selectability(self): + """ + See if the depsgraph evaluation is correct + """ + import bpy + + scene = bpy.context.scene + window = bpy.context.window + cube = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh')) + + layer = scene.view_layers.new('Selectability Test') + layer.collections.unlink(layer.collections[0]) + scene.view_layers.active = layer + window.view_layer = layer + + scene_collection_mom = scene.master_collection.collections.new("Mom") + scene_collection_kid = scene_collection_mom.collections.new("Kid") + + scene_collection_kid.objects.link(cube) + + layer_collection_mom = layer.collections.link(scene_collection_mom) + layer_collection_kid = layer.collections.link(scene_collection_kid) + + layer_collection_mom.enabled = False + bpy.context.scene.update() # update depsgraph + cube.select_set('SELECT') + + self.assertTrue(cube.visible_get(), "Cube should be visible") + self.assertTrue(cube.select_get(), "Cube should be selected") + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_selectability_b.py b/tests/python/view_layer/test_evaluation_selectability_b.py new file mode 100644 index 00000000000..a220d89445e --- /dev/null +++ b/tests/python/view_layer/test_evaluation_selectability_b.py @@ -0,0 +1,56 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_selectability(self): + """ + See if the depsgraph evaluation is correct + """ + import bpy + + scene = bpy.context.scene + window = bpy.context.window + cube = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh')) + + layer = scene.view_layers.new('Selectability Test') + layer.collections.unlink(layer.collections[0]) + scene.view_layers.active = layer + window.view_layer = layer + + scene_collection_mom = scene.master_collection.collections.new("Mom") + scene_collection_kid = scene_collection_mom.collections.new("Kid") + + scene_collection_kid.objects.link(cube) + + layer_collection_mom = layer.collections.link(scene_collection_mom) + layer_collection_kid = layer.collections.link(scene_collection_kid) + bpy.context.scene.update() # update depsgraph + cube.select_set('SELECT') + + layer_collection_mom.collections[layer_collection_kid.name].enabled = False + layer_collection_kid.enabled = False + + bpy.context.scene.update() # update depsgraph + self.assertFalse(cube.visible_get(), "Cube should be invisible") + self.assertFalse(cube.select_get(), "Cube should be unselected") + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_selectability_c.py b/tests/python/view_layer/test_evaluation_selectability_c.py new file mode 100644 index 00000000000..e551310cbbe --- /dev/null +++ b/tests/python/view_layer/test_evaluation_selectability_c.py @@ -0,0 +1,54 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_selectability(self): + """ + See if the depsgraph evaluation is correct + """ + import bpy + + scene = bpy.context.scene + window = bpy.context.window + cube = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh')) + + layer = scene.view_layers.new('Selectability Test') + layer.collections.unlink(layer.collections[0]) + scene.view_layers.active = layer + window.view_layer = layer + + scene_collection_mom = scene.master_collection.collections.new("Mom") + scene_collection_kid = scene_collection_mom.collections.new("Kid") + + scene_collection_kid.objects.link(cube) + + layer_collection_mom = layer.collections.link(scene_collection_mom) + layer_collection_kid = layer.collections.link(scene_collection_kid) + + layer_collection_mom.enabled = True + bpy.context.scene.update() # update depsgraph + cube.select_set('SELECT') + + self.assertTrue(cube.visible_get(), "Cube should be visible") + self.assertTrue(cube.select_get(), "Cube should be selected") + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_selectability_d.py b/tests/python/view_layer/test_evaluation_selectability_d.py new file mode 100644 index 00000000000..76adf12c666 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_selectability_d.py @@ -0,0 +1,57 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_selectability(self): + """ + See if the depsgraph evaluation is correct + """ + import bpy + + scene = bpy.context.scene + window = bpy.context.window + cube = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh')) + + layer = scene.view_layers.new('Selectability Test') + layer.collections.unlink(layer.collections[0]) + scene.view_layers.active = layer + window.view_layer = layer + + scene_collection_mom = scene.master_collection.collections.new("Mom") + scene_collection_kid = scene_collection_mom.collections.new("Kid") + + scene_collection_kid.objects.link(cube) + + layer_collection_mom = layer.collections.link(scene_collection_mom) + layer_collection_kid = layer.collections.link(scene_collection_kid) + + layer_collection_mom.enabled = True + bpy.context.scene.update() # update depsgraph + + cube.select_set('SELECT') + layer_collection_mom.collections[layer_collection_kid.name].selectable = False + + bpy.context.scene.update() # update depsgraph + self.assertTrue(cube.visible_get(), "Cube should be visible") + self.assertTrue(cube.select_get(), "Cube should be selected") + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_selectability_e.py b/tests/python/view_layer/test_evaluation_selectability_e.py new file mode 100644 index 00000000000..970c1cdd9d2 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_selectability_e.py @@ -0,0 +1,56 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_selectability(self): + """ + See if the depsgraph evaluation is correct + """ + import bpy + + scene = bpy.context.scene + window = bpy.context.window + cube = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh')) + + layer = scene.view_layers.new('Selectability Test') + layer.collections.unlink(layer.collections[0]) + scene.view_layers.active = layer + window.view_layer = layer + + scene_collection_mom = scene.master_collection.collections.new("Mom") + scene_collection_kid = scene_collection_mom.collections.new("Kid") + + scene_collection_kid.objects.link(cube) + + layer_collection_mom = layer.collections.link(scene_collection_mom) + layer_collection_kid = layer.collections.link(scene_collection_kid) + + layer_collection_mom.enabled = True + cube.select_set('SELECT') + layer_collection_mom.collections[layer_collection_kid.name].selectable = False + layer_collection_kid.enabled = False + + bpy.context.scene.update() # update depsgraph + self.assertTrue(cube.visible_get(), "Cube should be visible") + self.assertFalse(cube.select_get(), "Cube should be unselected") + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_selectability_f.py b/tests/python/view_layer/test_evaluation_selectability_f.py new file mode 100644 index 00000000000..54a070e4ae9 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_selectability_f.py @@ -0,0 +1,43 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_selectability(self): + import bpy + scene = bpy.context.scene + + cube = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh')) + scene_collection = scene.master_collection.collections.new('collection') + layer_collection = scene.view_layers.active.collections.link(scene_collection) + + bpy.context.scene.update() # update depsgraph + + scene_collection.objects.link(cube) + + self.assertTrue(layer_collection.enabled) + self.assertTrue(layer_collection.selectable) + + bpy.context.scene.update() # update depsgraph + cube.select_set(action='SELECT') + self.assertTrue(cube.select_get()) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_visibility_a.py b/tests/python/view_layer/test_evaluation_visibility_a.py new file mode 100644 index 00000000000..c1e6a427210 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_visibility_a.py @@ -0,0 +1,54 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_visibility(self): + """ + See if the depsgraph evaluation is correct + """ + import bpy + + scene = bpy.context.scene + window = bpy.context.window + cube = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh')) + + layer = scene.view_layers.new('Visibility Test') + layer.collections.unlink(layer.collections[0]) + scene.view_layers.active = layer + window.view_layer = layer + + scene_collection_mom = scene.master_collection.collections.new("Mom") + scene_collection_kid = scene.master_collection.collections.new("Kid") + + scene_collection_mom.objects.link(cube) + scene_collection_kid.objects.link(cube) + + layer_collection_mom = layer.collections.link(scene_collection_mom) + layer_collection_kid = layer.collections.link(scene_collection_kid) + + layer_collection_mom.enabled = False + layer_collection_kid.enabled = True + + bpy.context.scene.update() # update depsgraph + self.assertTrue(cube.visible_get(), "Object should be visible") + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_visibility_b.py b/tests/python/view_layer/test_evaluation_visibility_b.py new file mode 100644 index 00000000000..a6859ba31ec --- /dev/null +++ b/tests/python/view_layer/test_evaluation_visibility_b.py @@ -0,0 +1,54 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_visibility(self): + """ + See if the depsgraph evaluation is correct + """ + import bpy + + scene = bpy.context.scene + window = bpy.context.window + cube = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh')) + + layer = scene.view_layers.new('Visibility Test') + layer.collections.unlink(layer.collections[0]) + scene.view_layers.active = layer + window.view_layer = layer + + scene_collection_mom = scene.master_collection.collections.new("Mom") + scene_collection_kid = scene_collection_mom.collections.new("Kid") + + scene_collection_kid.objects.link(cube) + + layer_collection_mom = layer.collections.link(scene_collection_mom) + layer_collection_kid = layer.collections.link(scene_collection_kid) + + layer_collection_mom.enabled = True + layer_collection_mom.collections[layer_collection_kid.name].enabled = False + layer_collection_kid.enabled = False + + bpy.context.scene.update() # update depsgraph + self.assertFalse(cube.visible_get(), "Object should be invisible") + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_visibility_c.py b/tests/python/view_layer/test_evaluation_visibility_c.py new file mode 100644 index 00000000000..8c88a045c99 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_visibility_c.py @@ -0,0 +1,54 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_visibility(self): + """ + See if the depsgraph evaluation is correct + """ + import bpy + + scene = bpy.context.scene + window = bpy.context.window + cube = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh')) + + layer = scene.view_layers.new('Visibility Test') + layer.collections.unlink(layer.collections[0]) + scene.view_layers.active = layer + window.view_layer = layer + + scene_collection_mom = scene.master_collection.collections.new("Mom") + scene_collection_kid = scene_collection_mom.collections.new("Kid") + + scene_collection_kid.objects.link(cube) + + layer_collection_mom = layer.collections.link(scene_collection_mom) + layer_collection_kid = layer.collections.link(scene_collection_kid) + + layer_collection_mom.enabled = True + layer_collection_mom.collections[layer_collection_kid.name].enabled = False + layer_collection_kid.enabled = True + + bpy.context.scene.update() # update depsgraph + self.assertTrue(cube.visible_get(), "Object should be visible") + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_visibility_d.py b/tests/python/view_layer/test_evaluation_visibility_d.py new file mode 100644 index 00000000000..1836fae9802 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_visibility_d.py @@ -0,0 +1,51 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_visibility(self): + """ + See if the depsgraph evaluation is correct + """ + import bpy + + scene = bpy.context.scene + window = bpy.context.window + cube = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh')) + + layer = scene.view_layers.new('Visibility Test') + layer.collections.unlink(layer.collections[0]) + scene.view_layers.active = layer + window.view_layer = layer + + scene_collection_mom = scene.master_collection.collections.new("Mom") + scene_collection_kid = scene_collection_mom.collections.new("Kid") + + scene_collection_kid.objects.link(cube) + + layer_collection_mom = layer.collections.link(scene_collection_mom) + layer_collection_kid = layer.collections.link(scene_collection_kid) + + layer_collection_mom.enabled = True + bpy.context.scene.update() # update depsgraph + self.assertTrue(cube.visible_get(), "Object should be visible") + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_visibility_e.py b/tests/python/view_layer/test_evaluation_visibility_e.py new file mode 100644 index 00000000000..f05d797ecdc --- /dev/null +++ b/tests/python/view_layer/test_evaluation_visibility_e.py @@ -0,0 +1,55 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_visibility(self): + """ + See if the depsgraph evaluation is correct + """ + import bpy + + scene = bpy.context.scene + window = bpy.context.window + cube = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh')) + + layer = scene.view_layers.new('Visibility Test') + layer.collections.unlink(layer.collections[0]) + scene.view_layers.active = layer + window.view_layer = layer + + scene_collection_mom = scene.master_collection.collections.new("Mom") + scene_collection_kid = scene_collection_mom.collections.new("Kid") + + scene_collection_mom.objects.link(cube) + scene_collection_kid.objects.link(cube) + + layer_collection_mom = layer.collections.link(scene_collection_mom) + layer_collection_kid = layer.collections.link(scene_collection_kid) + + layer_collection_mom.enabled = True + layer_collection_kid.enabled = False + + bpy.context.scene.update() # update depsgraph + self.assertTrue(cube.visible_get(), "Object should be visible") + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + # XXX, above statement is not true, why skip the first argument? + UnitTesting._extra_arguments = setup_extra_arguments(__file__)[1:] + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_visibility_f.py b/tests/python/view_layer/test_evaluation_visibility_f.py new file mode 100644 index 00000000000..9034d0ce6f8 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_visibility_f.py @@ -0,0 +1,55 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_visibility(self): + """ + See if the depsgraph evaluation is correct + """ + import bpy + + scene = bpy.context.scene + window = bpy.context.window + cube = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh')) + + layer = scene.view_layers.new('Visibility Test') + layer.collections.unlink(layer.collections[0]) + scene.view_layers.active = layer + window.view_layer = layer + + scene_collection_mom = scene.master_collection.collections.new("Mom") + scene_collection_kid = scene_collection_mom.collections.new("Kid") + + scene_collection_mom.objects.link(cube) + scene_collection_kid.objects.link(cube) + + layer_collection_mom = layer.collections.link(scene_collection_mom) + layer_collection_kid = layer.collections.link(scene_collection_kid) + + layer_collection_mom.enabled = True + layer_collection_mom.collections[layer_collection_kid.name].enabled = False + layer_collection_kid.enabled = False + + bpy.context.scene.update() # update depsgraph + self.assertTrue(cube.visible_get(), "Object should be visible") + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_visibility_g.py b/tests/python/view_layer/test_evaluation_visibility_g.py new file mode 100644 index 00000000000..d2dc7f27e87 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_visibility_g.py @@ -0,0 +1,30 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_visibility_empty(self): + """ + See if the depsgraph evaluation is correct + """ + self.do_visibility_object_add('EMPTY') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_visibility_h.py b/tests/python/view_layer/test_evaluation_visibility_h.py new file mode 100644 index 00000000000..0b1d779c152 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_visibility_h.py @@ -0,0 +1,30 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_visibility_cylinder(self): + """ + See if the depsgraph evaluation is correct + """ + self.do_visibility_object_add('CYLINDER') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_visibility_i.py b/tests/python/view_layer/test_evaluation_visibility_i.py new file mode 100644 index 00000000000..5a292eadd91 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_visibility_i.py @@ -0,0 +1,30 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_visibility_torus(self): + """ + See if the depsgraph evaluation is correct + """ + self.do_visibility_object_add('TORUS') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_evaluation_visibility_j.py b/tests/python/view_layer/test_evaluation_visibility_j.py new file mode 100644 index 00000000000..53810fe5599 --- /dev/null +++ b/tests/python/view_layer/test_evaluation_visibility_j.py @@ -0,0 +1,61 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_visibility_nested(self): + """ + See if the depsgraph evaluation is correct + """ + import bpy + + # delete all initial objects + while bpy.data.objects: + bpy.data.objects.remove(bpy.data.objects[0]) + + # delete all initial collections + scene = bpy.context.scene + master_collection = scene.master_collection + while master_collection.collections: + master_collection.collections.remove(master_collection.collections[0]) + + collection_parent = master_collection.collections.new('parent') + collection_nested = collection_parent.collections.new('child linked') + ob = bpy.data.objects.new('An Empty', None) + collection_nested.objects.link(ob) + + layer_collection = bpy.context.view_layer.collections.link(master_collection) + self.assertTrue(layer_collection.enabled) + + # Update depsgraph. + scene.update() + + self.assertTrue(ob.visible_get()) + + layer_collection.enabled = False + self.assertFalse(layer_collection.enabled) + + # Update depsgraph. + scene.update() + + self.assertFalse(ob.visible_get()) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_group_a.py b/tests/python/view_layer/test_group_a.py new file mode 100644 index 00000000000..6e1b83efbe5 --- /dev/null +++ b/tests/python/view_layer/test_group_a.py @@ -0,0 +1,46 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_group_create_basic(self): + """ + See if the creation of new groups is not crashing anything. + """ + import bpy + scene = bpy.context.scene + layer_collection = bpy.context.layer_collection + + # Cleanup Viewport view layer + # technically this shouldn't be needed but + # for now we need it because depsgraph build all the view layers + # at once. + + while len(scene.view_layers) > 1: + scene.view_layers.remove(scene.view_layers[1]) + + # create group + group = layer_collection.create_group() + + # update depsgraph + scene.update() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_group_b.py b/tests/python/view_layer/test_group_b.py new file mode 100644 index 00000000000..5d3a03b129b --- /dev/null +++ b/tests/python/view_layer/test_group_b.py @@ -0,0 +1,72 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_group_create_basic(self): + """ + See if the creation of new groups is preserving visibility flags + from the original collections. + """ + import bpy + scene = bpy.context.scene + + # clean slate + self.cleanup_tree() + + master_collection = scene.master_collection + grandma = master_collection.collections.new('бабушка') + mom = grandma.collections.new('матушка') + + child = bpy.data.objects.new("Child", None) + mom.objects.link(child) + + grandma_layer_collection = scene.view_layers[0].collections.link(grandma) + mom_layer_collection = grandma_layer_collection.collections[0] + + grandma_layer_collection.enabled = True + grandma_layer_collection.enabled = True + mom_layer_collection.enabled = False + mom_layer_collection.selectable = True + + # update depsgraph + scene.update() + + # create group + group = grandma_layer_collection.create_group() + + # update depsgraph + scene.update() + + # compare + self.assertEqual(len(group.view_layer.collections), 1) + grandma_group_layer = group.view_layer.collections[0] + + self.assertTrue(grandma_group_layer.enabled, True) + self.assertTrue(grandma_group_layer.selectable) + + self.assertEqual(len(grandma_group_layer.collections), 1) + mom_group_layer = grandma_group_layer.collections[0] + + self.assertFalse(mom_group_layer.enabled) + self.assertTrue(mom_group_layer.selectable) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_group_c.py b/tests/python/view_layer/test_group_c.py new file mode 100644 index 00000000000..69feab1a56e --- /dev/null +++ b/tests/python/view_layer/test_group_c.py @@ -0,0 +1,56 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_group_create_basic(self): + """ + More advanced creation of group from a collection not directly linked + to the scene layer. + """ + import bpy + scene = bpy.context.scene + + # clean slate + self.cleanup_tree() + + children = [bpy.data.objects.new("Child", None) for i in range(3)] + master_collection = scene.master_collection + + grandma_scene_collection = master_collection.collections.new('Grand-Mother') + mom_scene_collection = grandma_scene_collection.collections.new('Mother') + + grandma_scene_collection.objects.link(children[0]) + mom_scene_collection.objects.link(children[1]) + + grandma_layer_collection = scene.view_layers[0].collections.link(grandma_scene_collection) + mom_layer_collection = grandma_layer_collection.collections[mom_scene_collection.name] + + # update depsgraph + scene.update() + + # create group + group = mom_layer_collection.create_group() + + # update depsgraph + scene.update() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_group_d.py b/tests/python/view_layer/test_group_d.py new file mode 100644 index 00000000000..6f54ca5340a --- /dev/null +++ b/tests/python/view_layer/test_group_d.py @@ -0,0 +1,76 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_group_write_load(self): + """ + See if saving/loading is working for groups + """ + import bpy + scene = bpy.context.scene + layer_collection = bpy.context.layer_collection + + while len(scene.view_layers) > 1: + scene.view_layers.remove(scene.view_layers[1]) + + # create group + group = layer_collection.create_group() + + self.assertEqual(1, len(bpy.data.groups)) + self.assertEqual(1, bpy.data.groups[0].users) + self.assertEqual(3, len(bpy.data.groups[0].objects)) + + import os + import tempfile + with tempfile.TemporaryDirectory() as dirpath: + filepath = os.path.join(dirpath, 'layers.blend') + + for i in range(3): + # save and re-open file + bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath) + bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath) + + self.assertEqual(1, len(bpy.data.groups)) + self.assertEqual(1, bpy.data.groups[0].users) + self.assertEqual(3, len(bpy.data.groups[0].objects)) + + + # empty the group of objects + group = bpy.data.groups[0] + while group.objects: + group.view_layer.collections[0].collection.objects.unlink(group.objects[0]) + + # save and re-open file + bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath) + bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath) + + self.assertEqual(1, len(bpy.data.groups)) + self.assertEqual(0, bpy.data.groups[0].users) + self.assertEqual(0, len(bpy.data.groups[0].objects)) + + # save and re-open file + bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath) + bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath) + + self.assertEqual(0, len(bpy.data.groups)) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_group_e.py b/tests/python/view_layer/test_group_e.py new file mode 100644 index 00000000000..566c043572e --- /dev/null +++ b/tests/python/view_layer/test_group_e.py @@ -0,0 +1,72 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_group_delete_object(self): + """ + See if we can safely remove instanced objects + """ + import bpy + scene = bpy.context.scene + view_layer = bpy.context.view_layer + ob = bpy.context.object + + # clean up the scene a bit + for o in (o for o in view_layer.objects if o != ob): + view_layer.collections[0].collection.objects.unlink(o) + + for v in (v for v in scene.view_layers if v != view_layer): + scene.view_layers.remove(v) + + # update depsgraph + scene.update() + + # create group + group = bpy.data.groups.new("Switch") + group.objects.link(ob) + + # update depsgraph + scene.update() + + # instance the group + empty = bpy.data.objects.new("Empty", None) + bpy.context.scene_collection.objects.link(empty) + layer_collection = bpy.context.layer_collection + empty.dupli_type = 'GROUP' + empty.dupli_group = group + + # prepare to delete the original object + # we could just pass an overridden context + # but let's do it the old fashion way + view_layer.objects.active = ob + ob.select_set('SELECT') + self.assertTrue(ob.select_get()) + empty.select_set('DESELECT') + self.assertFalse(empty.select_get()) + + # update depsgraph + scene.update() + + # delete the original object + bpy.ops.object.delete() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_layer_linking.py b/tests/python/view_layer/test_layer_linking.py new file mode 100644 index 00000000000..4c66c564d7c --- /dev/null +++ b/tests/python/view_layer/test_layer_linking.py @@ -0,0 +1,109 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def do_layer_linking(self, filepath_json, link_mode): + import bpy + import os + import tempfile + import filecmp + + ROOT = self.get_root() + with tempfile.TemporaryDirectory() as dirpath: + filepath_layers = os.path.join(ROOT, 'layers.blend') + + # open file + bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_layers) + self.rename_collections() + + # create sub-collections + three_b = bpy.data.objects.get('T.3b') + three_c = bpy.data.objects.get('T.3c') + + scene = bpy.context.scene + + subzero = scene.master_collection.collections['1'].collections.new('sub-zero') + scorpion = subzero.collections.new('scorpion') + + # test linking sync + subzero.objects.link(three_b) + scorpion.objects.link(three_c) + + # test unlinking sync + layer = scene.view_layers.new('Fresh new Layer') + + if link_mode in {'COLLECTION_LINK', 'COLLECTION_UNLINK'}: + layer.collections.link(subzero) + + if link_mode == 'COLLECTION_UNLINK': + initial_collection = layer.collections['Master Collection'] + layer.collections.unlink(initial_collection) + + # save file + filepath_nested = os.path.join(dirpath, 'nested.blend') + bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath_nested) + + # get the generated json + datas = query_scene(filepath_nested, 'Main', (get_scene_collections, get_layers)) + self.assertTrue(datas, "Data is not valid") + + filepath_nested_json = os.path.join(dirpath, "nested.json") + with open(filepath_nested_json, "w") as f: + for data in datas: + f.write(dump(data)) + + self.assertTrue(compare_files( + filepath_nested_json, + filepath_json, + ), + "Scene dump files differ") + + def test_syncing_layer_new(self): + """ + See if the creation of new layers is going well + """ + import os + ROOT = self.get_root() + filepath_json = os.path.join(ROOT, 'layers_new_layer.json') + self.do_layer_linking(filepath_json, 'LAYER_NEW') + + def test_syncing_layer_collection_link(self): + """ + See if the creation of new layers is going well + And linking a new scene collection in the layer works + """ + import os + ROOT = self.get_root() + filepath_json = os.path.join(ROOT, 'layers_layer_collection_link.json') + self.do_layer_linking(filepath_json, 'COLLECTION_LINK') + + def test_syncing_layer_collection_unlink(self): + """ + See if the creation of new layers is going well + And unlinking the origin scene collection works + """ + import os + ROOT = self.get_root() + filepath_json = os.path.join(ROOT, 'layers_layer_collection_unlink.json') + self.do_layer_linking(filepath_json, 'COLLECTION_UNLINK') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_layer_syncing.py b/tests/python/view_layer/test_layer_syncing.py new file mode 100644 index 00000000000..d8175c4850f --- /dev/null +++ b/tests/python/view_layer/test_layer_syncing.py @@ -0,0 +1,113 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def do_syncing(self, filepath_json, unlink_mode): + import bpy + import os + import tempfile + import filecmp + + ROOT = self.get_root() + with tempfile.TemporaryDirectory() as dirpath: + filepath_layers = os.path.join(ROOT, 'layers.blend') + + # open file + bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_layers) + self.rename_collections() + + # create sub-collections + three_b = bpy.data.objects.get('T.3b') + three_c = bpy.data.objects.get('T.3c') + three_d = bpy.data.objects.get('T.3d') + + scene = bpy.context.scene + + subzero = scene.master_collection.collections['1'].collections.new('sub-zero') + scorpion = scene.master_collection.collections['1'].collections.new('scorpion') + + # test linking sync + subzero.objects.link(three_b) + scorpion.objects.link(three_c) + + # test unlinking sync + if unlink_mode in {'OBJECT', 'COLLECTION'}: + scorpion.objects.link(three_d) + scorpion.objects.unlink(three_d) + + if unlink_mode == 'COLLECTION': + scorpion.objects.link(three_d) + scene.master_collection.collections['1'].collections.remove(subzero) + scene.master_collection.collections['1'].collections.remove(scorpion) + + # save file + filepath_nested = os.path.join(dirpath, 'nested.blend') + bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath_nested) + + # get the generated json + datas = query_scene(filepath_nested, 'Main', (get_scene_collections, get_layers)) + self.assertTrue(datas, "Data is not valid") + + filepath_nested_json = os.path.join(dirpath, "nested.json") + with open(filepath_nested_json, "w") as f: + for data in datas: + f.write(dump(data)) + + self.assertTrue(compare_files( + filepath_nested_json, + filepath_json, + ), + "Scene dump files differ") + + def test_syncing_link(self): + """ + See if scene collections and layer collections are in sync + when we create new subcollections and link new objects + """ + import os + ROOT = self.get_root() + filepath_json = os.path.join(ROOT, 'layers_nested.json') + self.do_syncing(filepath_json, 'NONE') + + def test_syncing_unlink_object(self): + """ + See if scene collections and layer collections are in sync + when we create new subcollections, link new objects and unlink + some. + """ + import os + ROOT = self.get_root() + filepath_json = os.path.join(ROOT, 'layers_nested.json') + self.do_syncing(filepath_json, 'OBJECT') + + def test_syncing_unlink_collection(self): + """ + See if scene collections and layer collections are in sync + when we create new subcollections, link new objects and unlink full collections + some. + """ + import os + ROOT = self.get_root() + filepath_json = os.path.join(ROOT, 'layers.json') + self.do_syncing(filepath_json, 'COLLECTION') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_layer_collection_a.py b/tests/python/view_layer/test_move_above_below_layer_collection_a.py new file mode 100644 index 00000000000..7c6c1fccfa9 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_layer_collection_a.py @@ -0,0 +1,48 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + # original tree, no changes + return self.get_initial_layers_tree_map() + + def test_layer_collection_move_a(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertFalse(self.move_below('Layer 1.3', 'Layer 1.C')) + self.compare_tree_maps() + + def test_layer_collection_move_b(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertFalse(self.move_above('Layer 1.C', 'Layer 1.3')) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_layer_collection_b.py b/tests/python/view_layer/test_move_above_below_layer_collection_b.py new file mode 100644 index 00000000000..671978a27f3 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_layer_collection_b.py @@ -0,0 +1,48 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + # original tree, no changes + return self.get_initial_layers_tree_map() + + def test_layer_collection_move_a(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertFalse(self.move_below('Layer 1.3.cat', 'Layer 1.3.dog')) + self.compare_tree_maps() + + def test_layer_collection_move_b(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertFalse(self.move_above('Layer 1.3.dog', 'Layer 1.3.cat')) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_layer_collection_c.py b/tests/python/view_layer/test_move_above_below_layer_collection_c.py new file mode 100644 index 00000000000..671978a27f3 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_layer_collection_c.py @@ -0,0 +1,48 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + # original tree, no changes + return self.get_initial_layers_tree_map() + + def test_layer_collection_move_a(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertFalse(self.move_below('Layer 1.3.cat', 'Layer 1.3.dog')) + self.compare_tree_maps() + + def test_layer_collection_move_b(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertFalse(self.move_above('Layer 1.3.dog', 'Layer 1.3.cat')) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_layer_collection_d.py b/tests/python/view_layer/test_move_above_below_layer_collection_d.py new file mode 100644 index 00000000000..b13e87985ee --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_layer_collection_d.py @@ -0,0 +1,48 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + # original tree, no changes + return self.get_initial_layers_tree_map() + + def test_layer_collection_move_a(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertFalse(self.move_above('Layer 2.3.dog', 'Layer 1.C.2')) + self.compare_tree_maps() + + def test_layer_collection_move_b(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertFalse(self.move_below('Layer 1.C.2', 'Layer 2.3.dog')) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_layer_collection_e.py b/tests/python/view_layer/test_move_above_below_layer_collection_e.py new file mode 100644 index 00000000000..a9b0181083e --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_layer_collection_e.py @@ -0,0 +1,40 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + # original tree, no changes + return self.get_initial_layers_tree_map() + + def test_layer_collection_move(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertFalse(self.move_below('Layer 1.Master Collection', 'Layer 1.C.1')) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_layer_collection_f.py b/tests/python/view_layer/test_move_above_below_layer_collection_f.py new file mode 100644 index 00000000000..77d65ef8671 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_layer_collection_f.py @@ -0,0 +1,100 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['3', [ + ['dog', None], + ['cat', None], + ]], + ['2', None], + ]], + ] + return reference_tree_map + + def get_reference_layers_tree_map(self): + reference_layers_map = [ + ['Layer 1', [ + 'Master Collection', + 'C', + '3', + ]], + ['Layer 2', [ + 'C', + 'dog', + 'cat', + ]], + ] + return reference_layers_map + + def test_layer_collection_move_a(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertTrue(self.move_below('Layer 2.3', 'Layer 2.C.1')) + self.compare_tree_maps() + + def test_layer_collection_move_b(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertTrue(self.move_above('Layer 2.3', 'Layer 2.C.2')) + self.compare_tree_maps() + + def test_layer_collection_move_c(self): + """ + Test outliner operations + """ + self.setup_tree() + + # collection that will be moved + collection_original = self.parse_move('Layer 2.3') + collection_original.enabled = True + collection_original.selectable = False + + # collection that will disappear + collection_old = self.parse_move('Layer 2.C.3') + collection_old.enabled = False + collection_old.selectable = True + + # move + self.assertTrue(self.move_below('Layer 2.3', 'Layer 2.C.1')) + self.compare_tree_maps() + + # we expect the settings to be carried along from the + # original layer collection + collection_new = self.parse_move('Layer 2.C.3') + self.assertEqual(collection_new.enabled, True) + self.assertEqual(collection_new.selectable, False) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_layer_collection_g.py b/tests/python/view_layer/test_move_above_below_layer_collection_g.py new file mode 100644 index 00000000000..16cd628edfc --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_layer_collection_g.py @@ -0,0 +1,81 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['cat', None], + ['dog', None], + ]], + ]], + ] + return reference_tree_map + + def get_reference_layers_tree_map(self): + # original tree, no changes + return self.get_initial_layers_tree_map() + + def test_layer_collection_move_a(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertTrue(self.move_above('Layer 2.C.3.cat', 'Layer 2.3.dog')) + self.compare_tree_maps() + + def test_layer_collection_move_b(self): + """ + Test outliner operations + """ + self.setup_tree() + + # collection that will be moved + collection_original = self.parse_move('Layer 2.C.3.cat') + collection_original.enabled = True + collection_original.selectable = False + + # collection that will disappear + collection_old = self.parse_move('Layer 2.3.cat') + collection_old.enabled = False + collection_old.selectable = True + + # move + self.assertTrue(self.move_above('Layer 2.C.3.cat', 'Layer 2.3.dog')) + self.compare_tree_maps() + + # we expect the settings to be carried along from the + # original layer collection + collection_new = self.parse_move('Layer 2.3.cat') + self.assertEqual(collection_new.enabled, True) + self.assertEqual(collection_new.selectable, False) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_layer_collection_h.py b/tests/python/view_layer/test_move_above_below_layer_collection_h.py new file mode 100644 index 00000000000..4fe2c857e50 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_layer_collection_h.py @@ -0,0 +1,66 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + # original tree, no changes + return self.get_initial_layers_tree_map() + + def test_layer_collection_move_a(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertTrue(self.move_below('Layer 2.C.3.cat', 'Layer 2.3.dog')) + self.compare_tree_maps() + + def test_layer_collection_move_b(self): + """ + Test outliner operations + """ + self.setup_tree() + + # collection that will be moved + collection_original = self.parse_move('Layer 2.C.3.cat') + collection_original.enabled = True + collection_original.selectable = False + + # collection that will disappear + collection_old = self.parse_move('Layer 2.3.cat') + collection_old.enabled = False + collection_old.selectable = True + + # move + self.assertTrue(self.move_below('Layer 2.C.3.cat', 'Layer 2.3.dog')) + self.compare_tree_maps() + + # we expect the settings to be carried along from the + # original layer collection + collection_new = self.parse_move('Layer 2.3.cat') + self.assertEqual(collection_new.enabled, True) + self.assertEqual(collection_new.selectable, False) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_layer_collection_i.py b/tests/python/view_layer/test_move_above_below_layer_collection_i.py new file mode 100644 index 00000000000..0134d11adcd --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_layer_collection_i.py @@ -0,0 +1,73 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + reference_layers_map = [ + ['Layer 1', [ + 'Master Collection', + 'C', + '3', + ]], + ['Layer 2', [ + '3', + 'C', + 'dog', + 'cat', + ]], + ] + return reference_layers_map + + def test_layer_collection_move_a(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertTrue(self.move_below('Layer 2.C', 'Layer 2.3')) + self.compare_tree_maps() + + def test_layer_collection_move_b(self): + """ + Test outliner operations + """ + self.setup_tree() + + # collection that will be moved + collection_original = self.parse_move('Layer 2.C') + collection_original.enabled = True + collection_original.selectable = False + + # move + self.assertTrue(self.move_below('Layer 2.C', 'Layer 2.3')) + self.compare_tree_maps() + + # we expect the settings to be carried along from the + # original layer collection + collection_new = self.parse_move('Layer 2.C') + self.assertEqual(collection_new.enabled, True) + self.assertEqual(collection_new.selectable, False) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_layer_collection_j.py b/tests/python/view_layer/test_move_above_below_layer_collection_j.py new file mode 100644 index 00000000000..cb56ca0b963 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_layer_collection_j.py @@ -0,0 +1,63 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + # original tree, no changes + return self.get_initial_layers_tree_map() + + def test_layer_collection_move_a(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertTrue(self.move_below('Layer 1.3.dog', 'Layer 1.3.cat')) + self.assertTrue(self.move_above('Layer 1.3.dog', 'Layer 1.3.cat')) + self.compare_tree_maps() + + def test_layer_collection_move_b(self): + """ + Test outliner operations + """ + self.setup_tree() + + # collection that will be moved + collection_original = self.parse_move('Layer 1.3.dog') + collection_original.enabled = True + collection_original.selectable = False + + # move + self.assertTrue(self.move_below('Layer 1.3.dog', 'Layer 1.3.cat')) + self.assertTrue(self.move_above('Layer 1.3.dog', 'Layer 1.3.cat')) + self.compare_tree_maps() + + # we expect the settings to be carried along from the + # original layer collection + collection_new = self.parse_move('Layer 1.3.dog') + self.assertEqual(collection_new.enabled, True) + self.assertEqual(collection_new.selectable, False) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_layer_collection_k.py b/tests/python/view_layer/test_move_above_below_layer_collection_k.py new file mode 100644 index 00000000000..f6d442619f5 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_layer_collection_k.py @@ -0,0 +1,40 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + # original tree, no changes + return self.get_initial_layers_tree_map() + + def test_layer_collection_move(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertFalse(self.move_below('Layer 2.C.2', 'Layer 2.3')) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_layer_collection_l.py b/tests/python/view_layer/test_move_above_below_layer_collection_l.py new file mode 100644 index 00000000000..2bc1054ec7e --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_layer_collection_l.py @@ -0,0 +1,60 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + reference_layers_map = [ + ['Layer 1', [ + 'Master Collection', + 'C', + '3', + ]], + ['Layer 2', [ + 'C', + 'cat', + '3', + 'dog', + ]], + ] + return reference_layers_map + + def test_layer_collection_move_a(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertTrue(self.move_below('Layer 2.cat', 'Layer 2.C')) + self.compare_tree_maps() + + def test_layer_collection_move_b(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertTrue(self.move_above('Layer 2.cat', 'Layer 2.3')) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_a.py b/tests/python/view_layer/test_move_above_below_scene_collection_a.py new file mode 100644 index 00000000000..3e45102e0b2 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_a.py @@ -0,0 +1,80 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', None], + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_move_a(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['cat'].move_above(tree['dog'])) + self.assertTrue(tree['dog'].move_above(tree['cat'])) + self.compare_tree_maps() + + def test_scene_collection_move_b(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['dog'].move_below(tree['cat'])) + self.assertTrue(tree['cat'].move_below(tree['dog'])) + self.compare_tree_maps() + + def test_scene_collection_move_c(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['dog'].move_below(tree['cat'])) + self.assertTrue(tree['dog'].move_above(tree['cat'])) + self.compare_tree_maps() + + def test_scene_collection_move_d(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['cat'].move_above(tree['dog'])) + self.assertTrue(tree['cat'].move_below(tree['dog'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_b.py b/tests/python/view_layer/test_move_above_below_scene_collection_b.py new file mode 100644 index 00000000000..83980705846 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_b.py @@ -0,0 +1,69 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['3', [ + ['dog', None], + ['cat', None], + ]], + ['1', None], + ['2', None], + ]], + ] + return reference_tree_map + + def test_scene_collection_move_a(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['3'].move_above(tree['1'])) + self.compare_tree_maps() + + def test_scene_collection_move_b(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['1'].move_below(tree['3'])) + self.assertTrue(tree['2'].move_below(tree['1'])) + self.compare_tree_maps() + + def test_scene_collection_move_c(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['3'].move_above(tree['2'])) + self.assertTrue(tree['1'].move_above(tree['2'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_c.py b/tests/python/view_layer/test_move_above_below_scene_collection_c.py new file mode 100644 index 00000000000..cceb2bb235b --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_c.py @@ -0,0 +1,51 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['3', [ + ['dog', None], + ['cat', None], + ]], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ]], + ] + return reference_tree_map + + def test_scene_collection_move(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['3'].move_below(tree['ii'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_d.py b/tests/python/view_layer/test_move_above_below_scene_collection_d.py new file mode 100644 index 00000000000..5917e9ceb6c --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_d.py @@ -0,0 +1,60 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', None], + ['B', None], + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_move_a(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['B'].move_above(tree['cat'])) + self.compare_tree_maps() + + def test_scene_collection_move_b(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['B'].move_below(tree['dog'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_e.py b/tests/python/view_layer/test_move_above_below_scene_collection_e.py new file mode 100644 index 00000000000..12778ff9131 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_e.py @@ -0,0 +1,60 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', None], + ['iii', None], + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_move_a(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['iii'].move_below(tree['dog'])) + self.compare_tree_maps() + + def test_scene_collection_move_b(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['iii'].move_above(tree['cat'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_f.py b/tests/python/view_layer/test_move_above_below_scene_collection_f.py new file mode 100644 index 00000000000..b9d5e8eff24 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_f.py @@ -0,0 +1,51 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['dog', None], + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_move(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['A'].move_above(tree['dog'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_g.py b/tests/python/view_layer/test_move_above_below_scene_collection_g.py new file mode 100644 index 00000000000..39848103ca2 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_g.py @@ -0,0 +1,44 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def test_scene_collection_move_a(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertFalse(tree['dog'].move_above(tree['cat'])) + self.compare_tree_maps() + + def test_scene_collection_move_b(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertFalse(tree['cat'].move_below(tree['dog'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_h.py b/tests/python/view_layer/test_move_above_below_scene_collection_h.py new file mode 100644 index 00000000000..af2f54f3db1 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_h.py @@ -0,0 +1,84 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def test_scene_collection_move_a(self): + """ + Test outliner operations + """ + import bpy + master_collection = bpy.context.scene.master_collection + + tree = self.setup_tree() + for collection in tree.values(): + # can't move into master_collection anywhere + self.assertFalse(master_collection.move_above(collection)) + + self.compare_tree_maps() + + def test_scene_collection_move_b(self): + """ + Test outliner operations + """ + import bpy + master_collection = bpy.context.scene.master_collection + + tree = self.setup_tree() + for collection in tree.values(): + # can't move into master_collection anywhere + self.assertFalse(master_collection.move_below(collection)) + + self.compare_tree_maps() + + def test_scene_collection_move_c(self): + """ + Test outliner operations + """ + import bpy + master_collection = bpy.context.scene.master_collection + + tree = self.setup_tree() + for collection in tree.values(): + # can't move into master_collection anywhere + self.assertFalse(collection.move_above(master_collection)) + + self.compare_tree_maps() + + def test_scene_collection_move_d(self): + """ + Test outliner operations + """ + import bpy + master_collection = bpy.context.scene.master_collection + + tree = self.setup_tree() + for collection in tree.values(): + # can't move into master_collection anywhere + self.assertFalse(collection.move_below(master_collection)) + + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_i.py b/tests/python/view_layer/test_move_above_below_scene_collection_i.py new file mode 100644 index 00000000000..a6b3cb568c9 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_i.py @@ -0,0 +1,60 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def test_scene_collection_move_a(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertFalse(tree['C'].move_above(tree['2'])) + self.compare_tree_maps() + + def test_scene_collection_move_b(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertFalse(tree['C'].move_below(tree['2'])) + self.compare_tree_maps() + + def test_scene_collection_move_c(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertFalse(tree['C'].move_above(tree['cat'])) + self.compare_tree_maps() + + def test_scene_collection_move_d(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertFalse(tree['C'].move_below(tree['cat'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_sync_a.py b/tests/python/view_layer/test_move_above_below_scene_collection_sync_a.py new file mode 100644 index 00000000000..d36930dcbc5 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_sync_a.py @@ -0,0 +1,80 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', None], + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_move_a(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['cat'].move_above(tree['dog'])) + self.assertTrue(tree['dog'].move_above(tree['cat'])) + self.compare_tree_maps() + + def test_scene_collection_move_b(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['dog'].move_below(tree['cat'])) + self.assertTrue(tree['cat'].move_below(tree['dog'])) + self.compare_tree_maps() + + def test_scene_collection_move_c(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['dog'].move_below(tree['cat'])) + self.assertTrue(tree['dog'].move_above(tree['cat'])) + self.compare_tree_maps() + + def test_scene_collection_move_d(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['cat'].move_above(tree['dog'])) + self.assertTrue(tree['cat'].move_below(tree['dog'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_sync_b.py b/tests/python/view_layer/test_move_above_below_scene_collection_sync_b.py new file mode 100644 index 00000000000..79718e1168a --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_sync_b.py @@ -0,0 +1,69 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['3', [ + ['dog', None], + ['cat', None], + ]], + ['1', None], + ['2', None], + ]], + ] + return reference_tree_map + + def test_scene_collection_move_a(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['3'].move_above(tree['1'])) + self.compare_tree_maps() + + def test_scene_collection_move_b(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['1'].move_below(tree['3'])) + self.assertTrue(tree['2'].move_below(tree['1'])) + self.compare_tree_maps() + + def test_scene_collection_move_c(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['3'].move_above(tree['2'])) + self.assertTrue(tree['1'].move_above(tree['2'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_sync_c.py b/tests/python/view_layer/test_move_above_below_scene_collection_sync_c.py new file mode 100644 index 00000000000..ef23b722b8b --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_sync_c.py @@ -0,0 +1,51 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['3', [ + ['dog', None], + ['cat', None], + ]], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ]], + ] + return reference_tree_map + + def test_scene_collection_move(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['3'].move_below(tree['ii'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_sync_d.py b/tests/python/view_layer/test_move_above_below_scene_collection_sync_d.py new file mode 100644 index 00000000000..05c3bcdbcbb --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_sync_d.py @@ -0,0 +1,60 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', None], + ['B', None], + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_move_a(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['B'].move_above(tree['cat'])) + self.compare_tree_maps() + + def test_scene_collection_move_b(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['B'].move_below(tree['dog'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_sync_e.py b/tests/python/view_layer/test_move_above_below_scene_collection_sync_e.py new file mode 100644 index 00000000000..ebab970ba19 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_sync_e.py @@ -0,0 +1,60 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', None], + ['iii', None], + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_move_a(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['iii'].move_below(tree['dog'])) + self.compare_tree_maps() + + def test_scene_collection_move_b(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['iii'].move_above(tree['cat'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_sync_f.py b/tests/python/view_layer/test_move_above_below_scene_collection_sync_f.py new file mode 100644 index 00000000000..7e4f0bc4a9c --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_sync_f.py @@ -0,0 +1,51 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['dog', None], + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_move(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['A'].move_above(tree['dog'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_sync_g.py b/tests/python/view_layer/test_move_above_below_scene_collection_sync_g.py new file mode 100644 index 00000000000..8c64dd6f32d --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_sync_g.py @@ -0,0 +1,44 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def test_scene_collection_move_a(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertFalse(tree['dog'].move_above(tree['cat'])) + self.compare_tree_maps() + + def test_scene_collection_move_b(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertFalse(tree['cat'].move_below(tree['dog'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_sync_h.py b/tests/python/view_layer/test_move_above_below_scene_collection_sync_h.py new file mode 100644 index 00000000000..dd0fcc1f732 --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_sync_h.py @@ -0,0 +1,84 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def test_scene_collection_move_a(self): + """ + Test outliner operations + """ + import bpy + master_collection = bpy.context.scene.master_collection + + tree = self.setup_tree() + for collection in tree.values(): + # can't move into master_collection anywhere + self.assertFalse(master_collection.move_above(collection)) + + self.compare_tree_maps() + + def test_scene_collection_move_b(self): + """ + Test outliner operations + """ + import bpy + master_collection = bpy.context.scene.master_collection + + tree = self.setup_tree() + for collection in tree.values(): + # can't move into master_collection anywhere + self.assertFalse(master_collection.move_below(collection)) + + self.compare_tree_maps() + + def test_scene_collection_move_c(self): + """ + Test outliner operations + """ + import bpy + master_collection = bpy.context.scene.master_collection + + tree = self.setup_tree() + for collection in tree.values(): + # can't move into master_collection anywhere + self.assertFalse(collection.move_above(master_collection)) + + self.compare_tree_maps() + + def test_scene_collection_move_d(self): + """ + Test outliner operations + """ + import bpy + master_collection = bpy.context.scene.master_collection + + tree = self.setup_tree() + for collection in tree.values(): + # can't move into master_collection anywhere + self.assertFalse(collection.move_below(master_collection)) + + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_above_below_scene_collection_sync_i.py b/tests/python/view_layer/test_move_above_below_scene_collection_sync_i.py new file mode 100644 index 00000000000..cdd43f5b8df --- /dev/null +++ b/tests/python/view_layer/test_move_above_below_scene_collection_sync_i.py @@ -0,0 +1,60 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def test_scene_collection_move_a(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertFalse(tree['C'].move_above(tree['2'])) + self.compare_tree_maps() + + def test_scene_collection_move_b(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertFalse(tree['C'].move_below(tree['2'])) + self.compare_tree_maps() + + def test_scene_collection_move_c(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertFalse(tree['C'].move_above(tree['cat'])) + self.compare_tree_maps() + + def test_scene_collection_move_d(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertFalse(tree['C'].move_below(tree['cat'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_layer_collection_a.py b/tests/python/view_layer/test_move_into_layer_collection_a.py new file mode 100644 index 00000000000..ef5a839a44a --- /dev/null +++ b/tests/python/view_layer/test_move_into_layer_collection_a.py @@ -0,0 +1,69 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', None], + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def get_reference_layers_tree_map(self): + # original tree, no changes + reference_layers_map = [ + ['Layer 1', [ + 'Master Collection', + 'C', + '3', + ]], + ['Layer 2', [ + 'C', + '3', + 'dog', + 'cat', + ]], + ] + return reference_layers_map + + def test_layer_collection_into(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertFalse(self.move_into("Layer 1.C.2", "Layer 2.3")) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_layer_collection_b.py b/tests/python/view_layer/test_move_into_layer_collection_b.py new file mode 100644 index 00000000000..77f5d2f2630 --- /dev/null +++ b/tests/python/view_layer/test_move_into_layer_collection_b.py @@ -0,0 +1,40 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + # original tree, no changes + return self.get_initial_layers_tree_map() + + def test_layer_collection_into(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertFalse(self.move_into('Layer 1.3', 'Layer 1.3.cat')) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_layer_collection_c.py b/tests/python/view_layer/test_move_into_layer_collection_c.py new file mode 100644 index 00000000000..8ce07dd332e --- /dev/null +++ b/tests/python/view_layer/test_move_into_layer_collection_c.py @@ -0,0 +1,40 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + # original tree, no changes + return self.get_initial_layers_tree_map() + + def test_layer_collection_into(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertFalse(self.move_into("Layer 2.C", "Layer 2.3")) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_layer_collection_d.py b/tests/python/view_layer/test_move_into_layer_collection_d.py new file mode 100644 index 00000000000..715ea6de1da --- /dev/null +++ b/tests/python/view_layer/test_move_into_layer_collection_d.py @@ -0,0 +1,40 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + # original tree, no changes + return self.get_initial_layers_tree_map() + + def test_layer_collection_into(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertFalse(self.move_into("Layer 2.3.cat", "Layer 2.3")) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_layer_collection_e.py b/tests/python/view_layer/test_move_into_layer_collection_e.py new file mode 100644 index 00000000000..6be1a27481f --- /dev/null +++ b/tests/python/view_layer/test_move_into_layer_collection_e.py @@ -0,0 +1,40 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + # original tree, no changes + return self.get_initial_layers_tree_map() + + def test_layer_collection_into(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertFalse(self.move_into("Layer 1.Master Collection", "Layer 1.C")) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_layer_collection_f.py b/tests/python/view_layer/test_move_into_layer_collection_f.py new file mode 100644 index 00000000000..7bf007d2724 --- /dev/null +++ b/tests/python/view_layer/test_move_into_layer_collection_f.py @@ -0,0 +1,86 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ['3', [ + ['dog', None], + ['cat', None], + ]], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ]], + ] + return reference_tree_map + + def get_reference_layers_tree_map(self): + reference_layers_map = [ + ['Layer 1', [ + 'Master Collection', + 'C', + ]], + ['Layer 2', [ + 'C', + '3', + 'dog', + 'cat', + ]], + ] + return reference_layers_map + + def test_layer_collection_into_a(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertTrue(self.move_into("Layer 1.3", "Layer 1.Master Collection.A")) + self.compare_tree_maps() + + def test_layer_collection_into_b(self): + """ + Test outliner operations + """ + self.setup_tree() + + # collection that will be moved + collection_original = self.parse_move('Layer 1.3') + collection_original.enabled = True + collection_original.selectable = False + + self.assertTrue(self.move_into('Layer 1.3', 'Layer 1.Master Collection.A')) + self.compare_tree_maps() + + # we expect the settings to be carried along from the + # original layer collection + collection_new = self.parse_move('Layer 1.Master Collection.A.3') + self.assertEqual(collection_new.enabled, True) + self.assertEqual(collection_new.selectable, False) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_layer_collection_g.py b/tests/python/view_layer/test_move_into_layer_collection_g.py new file mode 100644 index 00000000000..efcdd44da97 --- /dev/null +++ b/tests/python/view_layer/test_move_into_layer_collection_g.py @@ -0,0 +1,77 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + reference_layers_map = [ + ['Layer 1', [ + 'Master Collection', + 'C', + '3', + ]], + ['Layer 2', [ + 'C', + 'dog', + 'cat', + ]], + ] + return reference_layers_map + + def test_layer_collection_into_a(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertTrue(self.move_into('Layer 2.3', 'Layer 2.C')) + self.compare_tree_maps() + + def test_layer_collection_into_b(self): + """ + Test outliner operations + """ + self.setup_tree() + + # collection that will be moved + collection_original = self.parse_move('Layer 2.3') + collection_original.enabled = True + collection_original.selectable = False + + # collection that will disappear + collection_old = self.parse_move('Layer 2.C.3') + collection_old.enabled = False + collection_old.selectable = True + + # move collection + self.assertTrue(self.move_into('Layer 2.3', 'Layer 2.C')) + self.compare_tree_maps() + + # we expect the settings to be carried along from the + # original layer collection + collection_new = self.parse_move('Layer 2.C.3') + self.assertEqual(collection_new.enabled, True) + self.assertEqual(collection_new.selectable, False) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_layer_collection_h.py b/tests/python/view_layer/test_move_into_layer_collection_h.py new file mode 100644 index 00000000000..82f5d70dceb --- /dev/null +++ b/tests/python/view_layer/test_move_into_layer_collection_h.py @@ -0,0 +1,76 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['1', [ + ['dog', None], + ]], + ['2', None], + ['3', [ + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def get_reference_layers_tree_map(self): + # original tree, no changes + return self.get_initial_layers_tree_map() + + def test_layer_collection_into_a(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertTrue(self.move_into('Layer 1.3.dog', 'Layer 1.C.1')) + self.compare_tree_maps() + + def test_layer_collection_into_b(self): + """ + Test outliner operations + """ + self.setup_tree() + + # collection that will be moved + collection_original = self.parse_move('Layer 1.3.dog') + collection_original.enabled = True + collection_original.selectable = False + + self.assertTrue(self.move_into('Layer 1.3.dog', 'Layer 1.C.1')) + self.compare_tree_maps() + + # we expect the settings to be carried along from the + # original layer collection + collection_new = self.parse_move('Layer 1.C.1.dog') + self.assertEqual(collection_new.enabled, True) + self.assertEqual(collection_new.selectable, False) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_layer_collection_i.py b/tests/python/view_layer/test_move_into_layer_collection_i.py new file mode 100644 index 00000000000..23c6e9f997c --- /dev/null +++ b/tests/python/view_layer/test_move_into_layer_collection_i.py @@ -0,0 +1,40 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + # original tree, no changes + return self.get_initial_layers_tree_map() + + def test_layer_collection_into(self): + """ + Test outliner operations + """ + self.setup_tree() + self.assertFalse(self.move_into('Layer 2.C.3', 'Layer 2.dog')) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_layer_collection_j.py b/tests/python/view_layer/test_move_into_layer_collection_j.py new file mode 100644 index 00000000000..e3d0f6c7cc8 --- /dev/null +++ b/tests/python/view_layer/test_move_into_layer_collection_j.py @@ -0,0 +1,41 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveLayerCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def get_reference_layers_tree_map(self): + # original tree, no changes + return self.get_initial_layers_tree_map() + + def test_layer_collection_into(self): + """ + Test outliner operations + Prevent collection from being dragged into itself + """ + self.setup_tree() + self.assertFalse(self.move_into("Layer 2.dog", "Layer 2.3.dog")) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_a.py b/tests/python/view_layer/test_move_into_scene_collection_a.py new file mode 100644 index 00000000000..c5671d46316 --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_a.py @@ -0,0 +1,53 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', None], + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['cat'].move_into(tree['2'])) + self.assertTrue(tree['cat'].move_into(tree['3'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_b.py b/tests/python/view_layer/test_move_into_scene_collection_b.py new file mode 100644 index 00000000000..08cacde6f0c --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_b.py @@ -0,0 +1,52 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['B', [ + ['3', [ + ['dog', None], + ['cat', None], + ]], + ]], + ['C', [ + ['1', None], + ['2', None], + ]], + ] + return reference_tree_map + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['3'].move_into(tree['B'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_c.py b/tests/python/view_layer/test_move_into_scene_collection_c.py new file mode 100644 index 00000000000..83b1d2fc52b --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_c.py @@ -0,0 +1,52 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', [ + ['cat', None], + ]], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['cat'].move_into(tree['dog'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_d.py b/tests/python/view_layer/test_move_into_scene_collection_d.py new file mode 100644 index 00000000000..c8346c43e05 --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_d.py @@ -0,0 +1,37 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + # can't move into a collection if already the last item of the collection + self.assertFalse(tree['cat'].move_into(tree['3'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_e.py b/tests/python/view_layer/test_move_into_scene_collection_e.py new file mode 100644 index 00000000000..00a4274c564 --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_e.py @@ -0,0 +1,52 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', None], + ['cat', [ + ['B', None], + ]], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['B'].move_into(tree['cat'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_f.py b/tests/python/view_layer/test_move_into_scene_collection_f.py new file mode 100644 index 00000000000..4cba04c35a5 --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_f.py @@ -0,0 +1,51 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', None], + ['cat', None], + ['B', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['B'].move_into(tree['3'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_g.py b/tests/python/view_layer/test_move_into_scene_collection_g.py new file mode 100644 index 00000000000..5ca2658407f --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_g.py @@ -0,0 +1,52 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ]], + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['A'].move_into(tree['dog'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_h.py b/tests/python/view_layer/test_move_into_scene_collection_h.py new file mode 100644 index 00000000000..1524dbad7bc --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_h.py @@ -0,0 +1,52 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', [ + ['ii', None], + ]], + ['3', [ + ['dog', None], + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['ii'].move_into(tree['2'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_i.py b/tests/python/view_layer/test_move_into_scene_collection_i.py new file mode 100644 index 00000000000..2240ba50d75 --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_i.py @@ -0,0 +1,52 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', [ + ['ii', None], + ]], + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['ii'].move_into(tree['dog'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_j.py b/tests/python/view_layer/test_move_into_scene_collection_j.py new file mode 100644 index 00000000000..1625b6c517e --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_j.py @@ -0,0 +1,43 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + import bpy + master_collection = bpy.context.scene.master_collection + + tree = self.setup_tree() + + for collection in tree.values(): + # can't move into master_collection anywhere + self.assertFalse(master_collection.move_into(collection)) + + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_k.py b/tests/python/view_layer/test_move_into_scene_collection_k.py new file mode 100644 index 00000000000..2d4d5b51e29 --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_k.py @@ -0,0 +1,36 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertFalse(tree['C'].move_into(tree['2'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_l.py b/tests/python/view_layer/test_move_into_scene_collection_l.py new file mode 100644 index 00000000000..f2d52b38fe5 --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_l.py @@ -0,0 +1,36 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertFalse(tree['C'].move_into(tree['cat'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_sync_a.py b/tests/python/view_layer/test_move_into_scene_collection_sync_a.py new file mode 100644 index 00000000000..60001b9b049 --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_sync_a.py @@ -0,0 +1,37 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['cat'].move_into(tree['2'])) + self.assertTrue(tree['cat'].move_into(tree['3'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_sync_b.py b/tests/python/view_layer/test_move_into_scene_collection_sync_b.py new file mode 100644 index 00000000000..a4d05b57f77 --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_sync_b.py @@ -0,0 +1,52 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['B', [ + ['3', [ + ['dog', None], + ['cat', None], + ]], + ]], + ['C', [ + ['1', None], + ['2', None], + ]], + ] + return reference_tree_map + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['3'].move_into(tree['B'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_sync_c.py b/tests/python/view_layer/test_move_into_scene_collection_sync_c.py new file mode 100644 index 00000000000..3f125d513ce --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_sync_c.py @@ -0,0 +1,52 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', [ + ['cat', None], + ]], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['cat'].move_into(tree['dog'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_sync_d.py b/tests/python/view_layer/test_move_into_scene_collection_sync_d.py new file mode 100644 index 00000000000..87234efef20 --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_sync_d.py @@ -0,0 +1,37 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + # can't move into a collection if already the last item of the collection + self.assertFalse(tree['cat'].move_into(tree['3'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_sync_e.py b/tests/python/view_layer/test_move_into_scene_collection_sync_e.py new file mode 100644 index 00000000000..689b4976dab --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_sync_e.py @@ -0,0 +1,52 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', None], + ['cat', [ + ['B', None], + ]], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['B'].move_into(tree['cat'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_sync_f.py b/tests/python/view_layer/test_move_into_scene_collection_sync_f.py new file mode 100644 index 00000000000..e486f48aac1 --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_sync_f.py @@ -0,0 +1,51 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', None], + ['cat', None], + ['B', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['B'].move_into(tree['3'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_sync_g.py b/tests/python/view_layer/test_move_into_scene_collection_sync_g.py new file mode 100644 index 00000000000..3792e9429a3 --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_sync_g.py @@ -0,0 +1,52 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ]], + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['A'].move_into(tree['dog'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_sync_h.py b/tests/python/view_layer/test_move_into_scene_collection_sync_h.py new file mode 100644 index 00000000000..8b3ceb14d73 --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_sync_h.py @@ -0,0 +1,52 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', [ + ['ii', None], + ]], + ['3', [ + ['dog', None], + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['ii'].move_into(tree['2'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_sync_i.py b/tests/python/view_layer/test_move_into_scene_collection_sync_i.py new file mode 100644 index 00000000000..8262dcc06c1 --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_sync_i.py @@ -0,0 +1,52 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + reference_tree_map = [ + ['A', [ + ['i', None], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', [ + ['ii', None], + ]], + ['cat', None], + ]], + ]], + ] + return reference_tree_map + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertTrue(tree['ii'].move_into(tree['dog'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_sync_j.py b/tests/python/view_layer/test_move_into_scene_collection_sync_j.py new file mode 100644 index 00000000000..519c1b81269 --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_sync_j.py @@ -0,0 +1,43 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + import bpy + master_collection = bpy.context.scene.master_collection + + tree = self.setup_tree() + + for collection in tree.values(): + # can't move into master_collection anywhere + self.assertFalse(master_collection.move_into(collection)) + + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_sync_k.py b/tests/python/view_layer/test_move_into_scene_collection_sync_k.py new file mode 100644 index 00000000000..4c785418b0e --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_sync_k.py @@ -0,0 +1,36 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertFalse(tree['C'].move_into(tree['2'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_move_into_scene_collection_sync_l.py b/tests/python/view_layer/test_move_into_scene_collection_sync_l.py new file mode 100644 index 00000000000..f50cd6f7072 --- /dev/null +++ b/tests/python/view_layer/test_move_into_scene_collection_sync_l.py @@ -0,0 +1,36 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(MoveSceneCollectionSyncTesting): + def get_reference_scene_tree_map(self): + # original tree, no changes + return self.get_initial_scene_tree_map() + + def test_scene_collection_into(self): + """ + Test outliner operations + """ + tree = self.setup_tree() + self.assertFalse(tree['C'].move_into(tree['cat'])) + self.compare_tree_maps() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_object_add_cylinder.py b/tests/python/view_layer/test_object_add_cylinder.py new file mode 100644 index 00000000000..c982219a2c9 --- /dev/null +++ b/tests/python/view_layer/test_object_add_cylinder.py @@ -0,0 +1,34 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_syncing_object_add_cylinder(self): + """ + See if new objects are added to the correct collection + bpy.ops.mesh.primitive_cylinder_add() + """ + import os + ROOT = self.get_root() + filepath_json = os.path.join(ROOT, 'layers_object_add_cylinder.json') + self.do_object_add(filepath_json, 'CYLINDER') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_object_add_empty.py b/tests/python/view_layer/test_object_add_empty.py new file mode 100644 index 00000000000..376d9361319 --- /dev/null +++ b/tests/python/view_layer/test_object_add_empty.py @@ -0,0 +1,34 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_syncing_object_add_empty(self): + """ + See if new objects are added to the correct collection + bpy.ops.object.add() + """ + import os + ROOT = self.get_root() + filepath_json = os.path.join(ROOT, 'layers_object_add_empty.json') + self.do_object_add(filepath_json, 'EMPTY') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_object_add_no_collection_cylinder.py b/tests/python/view_layer/test_object_add_no_collection_cylinder.py new file mode 100644 index 00000000000..d6138040092 --- /dev/null +++ b/tests/python/view_layer/test_object_add_no_collection_cylinder.py @@ -0,0 +1,32 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_object_add_cylinder(self): + """ + See if new objects are added to the correct collection + bpy.ops.mesh.primitive_cylinder_add() + """ + import os + self.do_object_add_no_collection('CYLINDER') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_object_add_no_collection_empty.py b/tests/python/view_layer/test_object_add_no_collection_empty.py new file mode 100644 index 00000000000..4c4ed45dfe8 --- /dev/null +++ b/tests/python/view_layer/test_object_add_no_collection_empty.py @@ -0,0 +1,31 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_syncing_object_add_empty(self): + """ + See if new objects are added to the correct collection + bpy.ops.object.add() + """ + self.do_object_add_no_collection('EMPTY') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_object_add_no_collection_torus.py b/tests/python/view_layer/test_object_add_no_collection_torus.py new file mode 100644 index 00000000000..0bb6b03692d --- /dev/null +++ b/tests/python/view_layer/test_object_add_no_collection_torus.py @@ -0,0 +1,31 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_syncing_object_add_torus(self): + """ + See if new objects are added to the correct collection + bpy.ops.mesh.primitive_torus_add() + """ + self.do_object_add_no_collection('TORUS') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_object_add_torus.py b/tests/python/view_layer/test_object_add_torus.py new file mode 100644 index 00000000000..7ee138bb93e --- /dev/null +++ b/tests/python/view_layer/test_object_add_torus.py @@ -0,0 +1,34 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_syncing_object_add_torus(self): + """ + See if new objects are added to the correct collection + bpy.ops.mesh.primitive_torus_add() + """ + import os + ROOT = self.get_root() + filepath_json = os.path.join(ROOT, 'layers_object_add_torus.json') + self.do_object_add(filepath_json, 'TORUS') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_object_copy.py b/tests/python/view_layer/test_object_copy.py new file mode 100644 index 00000000000..a15b9e2c941 --- /dev/null +++ b/tests/python/view_layer/test_object_copy.py @@ -0,0 +1,94 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def do_object_copy(self, mode): + import bpy + import os + import tempfile + import filecmp + + ROOT = self.get_root() + with tempfile.TemporaryDirectory() as dirpath: + filepath_layers = os.path.join(ROOT, 'layers.blend') + filepath_json = os.path.join(ROOT, 'layers_object_copy_duplicate.json') + + # open file + bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_layers) + self.rename_collections() + + # create sub-collections + three_b = bpy.data.objects.get('T.3b') + three_c = bpy.data.objects.get('T.3c') + + scene = bpy.context.scene + subzero = scene.master_collection.collections['1'].collections.new('sub-zero') + scorpion = subzero.collections.new('scorpion') + subzero.objects.link(three_b) + scorpion.objects.link(three_c) + layer = scene.view_layers.new('Fresh new Layer') + layer.collections.link(subzero) + + scene.view_layers.active_index = len(scene.view_layers) - 1 + bpy.context.window.view_layer = bpy.context.scene.view_layers['Fresh new Layer'] + + if mode == 'DUPLICATE': + # assuming the latest layer is the active layer + bpy.ops.object.select_all(action='DESELECT') + three_c.select_set(action='SELECT') + bpy.ops.object.duplicate() + + elif mode == 'NAMED': + bpy.ops.object.add_named(name=three_c.name) + + # save file + filepath_objects = os.path.join(dirpath, 'objects.blend') + bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath_objects) + + # get the generated json + datas = query_scene(filepath_objects, 'Main', (get_scene_collections, get_layers)) + self.assertTrue(datas, "Data is not valid") + + filepath_objects_json = os.path.join(dirpath, "objects.json") + with open(filepath_objects_json, "w") as f: + for data in datas: + f.write(dump(data)) + + self.assertTrue(compare_files( + filepath_objects_json, + filepath_json, + ), + "Scene dump files differ") + + def test_copy_object(self): + """ + OBJECT_OT_duplicate + """ + self.do_object_copy('DUPLICATE') + + def test_copy_object_named(self): + """ + OBJECT_OT_add_named + """ + self.do_object_copy('NAMED') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_object_delete_a.py b/tests/python/view_layer/test_object_delete_a.py new file mode 100644 index 00000000000..39304d1dcfc --- /dev/null +++ b/tests/python/view_layer/test_object_delete_a.py @@ -0,0 +1,31 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_object_delete_data(self): + """ + See if objects are removed correctly from all related collections + bpy.data.objects.remove() + """ + self.do_object_delete('DATA') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_object_delete_b.py b/tests/python/view_layer/test_object_delete_b.py new file mode 100644 index 00000000000..58dae9fc8a3 --- /dev/null +++ b/tests/python/view_layer/test_object_delete_b.py @@ -0,0 +1,31 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_object_delete_operator(self): + """ + See if new objects are added to the correct collection + bpy.ops.object.del() + """ + self.do_object_delete('OPERATOR') + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_object_link_a.py b/tests/python/view_layer/test_object_link_a.py new file mode 100644 index 00000000000..4f79e1c16ad --- /dev/null +++ b/tests/python/view_layer/test_object_link_a.py @@ -0,0 +1,32 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_object_link_scene(self): + """ + See if we can link objects + """ + import bpy + master_collection = bpy.context.scene.master_collection + self.do_object_link(master_collection) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_object_link_b.py b/tests/python/view_layer/test_object_link_b.py new file mode 100644 index 00000000000..361ea7fc3a5 --- /dev/null +++ b/tests/python/view_layer/test_object_link_b.py @@ -0,0 +1,34 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_object_link_context(self): + """ + See if we can link objects via bpy.context.scene_collection + """ + import bpy + bpy.context.scene.view_layers.active_index = len(bpy.context.scene.view_layers) - 1 + bpy.context.window.view_layer = bpy.context.scene.view_layers['Viewport'] + master_collection = bpy.context.scene_collection + self.do_object_link(master_collection) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_object_link_c.py b/tests/python/view_layer/test_object_link_c.py new file mode 100644 index 00000000000..f0118beaefe --- /dev/null +++ b/tests/python/view_layer/test_object_link_c.py @@ -0,0 +1,35 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_object_link_reload(self): + """ + See if we can link objects and not crash + """ + import bpy + master_collection = bpy.context.scene.master_collection + self.do_object_link(master_collection) + + # force depsgraph to update + bpy.ops.wm.read_factory_settings() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_operator_context.py b/tests/python/view_layer/test_operator_context.py new file mode 100644 index 00000000000..34f46c963bb --- /dev/null +++ b/tests/python/view_layer/test_operator_context.py @@ -0,0 +1,133 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_operator_context(self): + """ + See if view layer context is properly set/get with operators overrides + when we set view_layer in context, the collection should change as well + """ + import bpy + import os + + class SampleOperator(bpy.types.Operator): + bl_idname = "testing.sample" + bl_label = "Sample Operator" + + view_layer = bpy.props.StringProperty( + default="Not Set", + options={'SKIP_SAVE'}, + ) + + scene_collection = bpy.props.StringProperty( + default="", + options={'SKIP_SAVE'}, + ) + + use_verbose = bpy.props.BoolProperty( + default=False, + options={'SKIP_SAVE'}, + ) + + def execute(self, context): + view_layer = context.view_layer + ret = {'FINISHED'} + + # this is simply playing safe + if view_layer.name != self.view_layer: + if self.use_verbose: + print('ERROR: Render Layer mismatch: "{0}" != "{1}"'.format( + view_layer.name, self.view_layer)) + ret = {'CANCELLED'} + + scene_collection_name = None + if self.scene_collection: + scene_collection_name = self.scene_collection + else: + scene_collection_name = view_layer.collections.active.name + + # while this is the real test + if context.scene_collection.name != scene_collection_name: + if self.use_verbose: + print('ERROR: Scene Collection mismatch: "{0}" != "{1}"'.format( + context.scene_collection.name, scene_collection_name)) + ret = {'CANCELLED'} + return ret + + bpy.utils.register_class(SampleOperator) + + # open sample file + ROOT = self.get_root() + filepath_layers = os.path.join(ROOT, 'layers.blend') + bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_layers) + self.rename_collections() + + # change the file + three_b = bpy.data.objects.get('T.3b') + three_c = bpy.data.objects.get('T.3c') + scene = bpy.context.scene + subzero = scene.master_collection.collections['1'].collections.new('sub-zero') + scorpion = subzero.collections.new('scorpion') + subzero.objects.link(three_b) + scorpion.objects.link(three_c) + layer = scene.view_layers.new('Fresh new Layer') + layer.collections.unlink(layer.collections.active) + layer.collections.link(subzero) + layer.collections.active_index = 3 + self.assertEqual(layer.collections.active.name, 'scorpion') + + # Change active scene layer (do it for window too just to don't get mangled in window bugs) + scene = bpy.context.scene + scene.view_layers.active_index = len(scene.view_layers) - 2 + self.assertEqual(scene.view_layers.active.name, "Viewport") + bpy.context.window.view_layer = bpy.context.scene.view_layers['Viewport'] + + # old layer + self.assertEqual(bpy.ops.testing.sample(view_layer='Viewport', use_verbose=True), {'FINISHED'}) + + # expected to fail + self.assertTrue(bpy.ops.testing.sample(view_layer=layer.name), {'CANCELLED'}) + + # set view layer and scene collection + override = bpy.context.copy() + override["view_layer"] = layer + override["scene_collection"] = subzero + self.assertEqual(bpy.ops.testing.sample( + override, + view_layer=layer.name, + scene_collection=subzero.name, # 'sub-zero' + use_verbose=True), {'FINISHED'}) + + # set only view layer + override = bpy.context.copy() + override["view_layer"] = layer + + self.assertNotEqual(bpy.context.view_layer.name, layer.name) + self.assertNotEqual(bpy.context.scene_collection.name, layer.collections.active.name) + + self.assertEqual(bpy.ops.testing.sample( + override, + view_layer=layer.name, + scene_collection=layer.collections.active.name, # 'scorpion' + use_verbose=False), {'CANCELLED'}) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_scene_collection_delete.py b/tests/python/view_layer/test_scene_collection_delete.py new file mode 100644 index 00000000000..58893810545 --- /dev/null +++ b/tests/python/view_layer/test_scene_collection_delete.py @@ -0,0 +1,49 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_scene_collection_delete(self): + """ + See if a scene collection can be properly deleted even + when linked + """ + import bpy + + # delete all initial objects + while bpy.data.objects: + bpy.data.objects.remove(bpy.data.objects[0]) + + # delete all initial collections + scene = bpy.context.scene + master_collection = scene.master_collection + while master_collection.collections: + master_collection.collections.remove(master_collection.collections[0]) + + collection_parent = master_collection.collections.new('parent') + collection_nested = collection_parent.collections.new('child linked') + bpy.context.view_layer.collections.link(collection_nested) + master_collection.collections.remove(collection_parent) + + # Update depsgraph. + scene.update() + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_scene_copy_a.py b/tests/python/view_layer/test_scene_copy_a.py new file mode 100644 index 00000000000..8cccb26a92d --- /dev/null +++ b/tests/python/view_layer/test_scene_copy_a.py @@ -0,0 +1,37 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_scene_collections_copy_full(self): + """ + See if scene copying 'FULL_COPY' is working for scene collections + """ + import os + ROOT = self.get_root() + + filepath_layers_json_copy = os.path.join(ROOT, 'layers_copy_full_simple.json') + self.do_scene_copy( + filepath_layers_json_copy, + 'FULL_COPY', + (get_scene_collections,)) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_scene_copy_b.py b/tests/python/view_layer/test_scene_copy_b.py new file mode 100644 index 00000000000..1d53b56719d --- /dev/null +++ b/tests/python/view_layer/test_scene_copy_b.py @@ -0,0 +1,38 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_scene_collections_link(self): + """ + See if scene copying 'LINK_OBJECTS' is working for scene collections + """ + import os + ROOT = self.get_root() + + # note: nothing should change, so using `layers_simple.json` + filepath_layers_json_copy = os.path.join(ROOT, 'layers_simple.json') + self.do_scene_copy( + filepath_layers_json_copy, + 'LINK_OBJECTS', + (get_scene_collections,)) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_scene_copy_c.py b/tests/python/view_layer/test_scene_copy_c.py new file mode 100644 index 00000000000..c9bb0924848 --- /dev/null +++ b/tests/python/view_layer/test_scene_copy_c.py @@ -0,0 +1,37 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_scene_layers_copy(self): + """ + See if scene copying 'FULL_COPY' is working for scene layers + """ + import os + ROOT = self.get_root() + + filepath_layers_json_copy = os.path.join(ROOT, 'layers_copy_full.json') + self.do_scene_copy( + filepath_layers_json_copy, + 'FULL_COPY', + (get_scene_collections, get_layers)) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_scene_copy_d.py b/tests/python/view_layer/test_scene_copy_d.py new file mode 100644 index 00000000000..6efd93c7659 --- /dev/null +++ b/tests/python/view_layer/test_scene_copy_d.py @@ -0,0 +1,37 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_scene_layers_link(self): + """ + See if scene copying 'LINK_OBJECTS' is working for scene layers + """ + import os + ROOT = self.get_root() + + filepath_layers_json_copy = os.path.join(ROOT, 'layers_copy_link.json') + self.do_scene_copy( + filepath_layers_json_copy, + 'LINK_OBJECTS', + (get_scene_collections, get_layers)) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_scene_copy_e.py b/tests/python/view_layer/test_scene_copy_e.py new file mode 100644 index 00000000000..23d01b6a84b --- /dev/null +++ b/tests/python/view_layer/test_scene_copy_e.py @@ -0,0 +1,47 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_shared_layer_collections_copy_full(self): + """ + See if scene copying 'FULL_COPY' is working for scene collections + with a shared object + """ + import os + import bpy + + scene = bpy.context.scene + layer = bpy.context.view_layer + + original_cube = layer.objects.get('Cube') + original_cube.select_set('SELECT') + self.assertTrue(original_cube.select_get()) + + bpy.ops.scene.new(type='FULL_COPY') + new_layer = bpy.context.view_layer + + self.assertNotEqual(layer, new_layer) + new_cube = new_layer.objects.get('Cube.001') + self.assertNotEqual(original_cube, new_cube) + self.assertTrue(new_cube.select_get()) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_scene_copy_f.py b/tests/python/view_layer/test_scene_copy_f.py new file mode 100644 index 00000000000..13586a66f3d --- /dev/null +++ b/tests/python/view_layer/test_scene_copy_f.py @@ -0,0 +1,89 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_shared_layer_collections_copy_full(self): + """ + See if scene copying 'FULL_COPY' is keeping collections visibility + and selectability. + """ + import os + import bpy + + scene = bpy.context.scene + + enabled_lookup = [True, False, False, True] + enabled_lookup_sub = [False, True, False] + + selectable_lookup = [True, True, False, False] + selectable_lookup_sub = [False, True, False, True] + new_collections = [] + + # clean everything + for layer in scene.view_layers: + while layer.collections: + layer.collections.unlink(layer.collections[0]) + + # create new collections + for i in range(4): + collection = scene.master_collection.collections.new(str(i)) + new_collections.append(collection) + + for j in range(3): + sub_collection = collection.collections.new("{0}:{1}".format(i, j)) + + # link to the original scene + for layer in scene.view_layers: + for i, collection in enumerate(new_collections): + layer.collections.link(collection) + self.assertEqual(layer.collections[-1], layer.collections[i]) + + layer.collections[i].enabled = enabled_lookup[i] + layer.collections[i].selectable = selectable_lookup[i] + + for j, sub_collection in enumerate(layer.collections[i].collections): + sub_collection.enabled = enabled_lookup_sub[j] + sub_collection.selectable = selectable_lookup_sub[j] + + # copy scene + bpy.ops.scene.new(type='FULL_COPY') + new_scene = bpy.context.scene + self.assertNotEqual(scene, new_scene) + + # update depsgrah + scene.update() # update depsgraph + + # compare scenes + for h, layer in enumerate(scene.view_layers): + new_layer = new_scene.view_layers[h] + + for i, collection in enumerate(layer.collections): + new_collection = new_layer.collections[i] + self.assertEqual(collection.enabled, new_collection.enabled) + self.assertEqual(collection.selectable, new_collection.selectable) + + for j, sub_collection in enumerate(layer.collections[i].collections): + new_sub_collection = new_collection.collections[j] + self.assertEqual(sub_collection.enabled, new_sub_collection.enabled) + self.assertEqual(sub_collection.selectable, new_sub_collection.selectable) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_scene_delete.py b/tests/python/view_layer/test_scene_delete.py new file mode 100644 index 00000000000..edc997d6495 --- /dev/null +++ b/tests/python/view_layer/test_scene_delete.py @@ -0,0 +1,34 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_scene_delete(self): + """ + See if a scene can be properly deleted + """ + import bpy + + scene = bpy.context.scene + bpy.data.scenes.new('New') + bpy.data.scenes.remove(scene) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_scene_objects.py b/tests/python/view_layer/test_scene_objects.py new file mode 100644 index 00000000000..c5d3a0196ed --- /dev/null +++ b/tests/python/view_layer/test_scene_objects.py @@ -0,0 +1,53 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_scene_objects_a(self): + """ + Test vanilla scene + """ + import bpy + + scene = bpy.context.scene + self.assertEqual(len(scene.objects), 3) + + def test_scene_objects_b(self): + """ + Test scene with nested collections + """ + import bpy + scene = bpy.context.scene + + # move default objects to a nested collection + master_collection = scene.master_collection + collection = master_collection.collections[0] + collection_nested = collection.collections.new() + + for ob in collection.objects: + collection_nested.objects.link(ob) + + while collection.objects: + collection.objects.unlink(collection.objects[0]) + + self.assertEqual(len(scene.objects), 3) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_scene_write_read.py b/tests/python/view_layer/test_scene_write_read.py new file mode 100644 index 00000000000..6c750d87987 --- /dev/null +++ b/tests/python/view_layer/test_scene_write_read.py @@ -0,0 +1,144 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def do_scene_write_read(self, filepath_layers, filepath_layers_json, data_callbacks, do_read): + """ + See if write/read is working for scene collections and layers + """ + import bpy + import os + import tempfile + import filecmp + + with tempfile.TemporaryDirectory() as dirpath: + (self.path_exists(f) for f in (filepath_layers, filepath_layers_json)) + + filepath_doversion = os.path.join(dirpath, 'doversion.blend') + filepath_saved = os.path.join(dirpath, 'doversion_saved.blend') + filepath_read_json = os.path.join(dirpath, "read.json") + + # doversion + write test + bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_layers) + self.rename_collections() + bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath_doversion) + + datas = query_scene(filepath_doversion, 'Main', data_callbacks) + self.assertTrue(datas, "Data is not valid") + + filepath_doversion_json = os.path.join(dirpath, "doversion.json") + with open(filepath_doversion_json, "w") as f: + for data in datas: + f.write(dump(data)) + + self.assertTrue(compare_files( + filepath_doversion_json, + filepath_layers_json, + ), + "Run: test_scene_write_layers") + + if do_read: + # read test, simply open and save the file + bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_doversion) + self.rename_collections() + bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath_saved) + + datas = query_scene(filepath_saved, 'Main', data_callbacks) + self.assertTrue(datas, "Data is not valid") + + with open(filepath_read_json, "w") as f: + for data in datas: + f.write(dump(data)) + + self.assertTrue(compare_files( + filepath_read_json, + filepath_layers_json, + ), + "Scene dump files differ") + + def test_scene_write_collections(self): + """ + See if the doversion and writing are working for scene collections + """ + import os + + ROOT = self.get_root() + filepath_layers = os.path.join(ROOT, 'layers.blend') + filepath_layers_json = os.path.join(ROOT, 'layers_simple.json') + + self.do_scene_write_read( + filepath_layers, + filepath_layers_json, + (get_scene_collections,), + False) + + def test_scene_write_layers(self): + """ + See if the doversion and writing are working for collections and layers + """ + import os + + ROOT = self.get_root() + filepath_layers = os.path.join(ROOT, 'layers.blend') + filepath_layers_json = os.path.join(ROOT, 'layers.json') + + self.do_scene_write_read( + filepath_layers, + filepath_layers_json, + (get_scene_collections, get_layers), + False) + + def test_scene_read_collections(self): + """ + See if read is working for scene collections + (run `test_scene_write_colections` first) + """ + import os + + ROOT = self.get_root() + filepath_layers = os.path.join(ROOT, 'layers.blend') + filepath_layers_json = os.path.join(ROOT, 'layers_simple.json') + + self.do_scene_write_read( + filepath_layers, + filepath_layers_json, + (get_scene_collections,), + True) + + def test_scene_read_layers(self): + """ + See if read is working for scene layers + (run `test_scene_write_layers` first) + """ + import os + + ROOT = self.get_root() + filepath_layers = os.path.join(ROOT, 'layers.blend') + filepath_layers_json = os.path.join(ROOT, 'layers.json') + + self.do_scene_write_read( + filepath_layers, + filepath_layers_json, + (get_scene_collections, get_layers), + True) + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/test_view_layer_rename.py b/tests/python/view_layer/test_view_layer_rename.py new file mode 100644 index 00000000000..fefb317d0b1 --- /dev/null +++ b/tests/python/view_layer/test_view_layer_rename.py @@ -0,0 +1,33 @@ +# ############################################################ +# Importing - Same For All Render Layer Tests +# ############################################################ + +import unittest +import os +import sys + +from view_layer_common import * + + +# ############################################################ +# Testing +# ############################################################ + +class UnitTesting(ViewLayerTesting): + def test_view_layer_rename(self): + """ + See if we can rename view layers. + """ + import bpy + view_layer = bpy.context.view_layer + print("View layer name: " + view_layer.name) + view_layer.name = "New Name" + + +# ############################################################ +# Main - Same For All Render Layer Tests +# ############################################################ + +if __name__ == '__main__': + UnitTesting._extra_arguments = setup_extra_arguments(__file__) + unittest.main() diff --git a/tests/python/view_layer/view_layer_common.py b/tests/python/view_layer/view_layer_common.py new file mode 100644 index 00000000000..1ccd836c8d1 --- /dev/null +++ b/tests/python/view_layer/view_layer_common.py @@ -0,0 +1,821 @@ +import unittest + +__all__ = ( + "Clay", + "MoveLayerCollectionTesting", + "MoveSceneCollectionSyncTesting", + "MoveSceneCollectionTesting", + "ViewLayerTesting", + "compare_files", + "dump", + "get_layers", + "get_scene_collections", + "query_scene", + "setup_extra_arguments", +) + +# ############################################################ +# Layer Collection Crawler +# ############################################################ + + +def listbase_iter(data, struct, listbase): + element = data.get_pointer((struct, listbase, b'first')) + while element is not None: + yield element + element = element.get_pointer(b'next') + + +def linkdata_iter(collection, data): + element = collection.get_pointer((data, b'first')) + while element is not None: + yield element + element = element.get_pointer(b'next') + + +def get_layer_collection(layer_collection): + data = {} + flag = layer_collection.get(b'flag') + + data['is_visible'] = (flag & (1 << 0)) != 0 + data['is_selectable'] = (flag & (1 << 1)) != 0 + data['is_disabled'] = (flag & (1 << 2)) != 0 + + scene_collection = layer_collection.get_pointer(b'scene_collection') + if scene_collection is None: + name = 'Fail!' + else: + name = scene_collection.get(b'name') + data['name'] = name + + objects = [] + for link in linkdata_iter(layer_collection, b'object_bases'): + ob_base = link.get_pointer(b'data') + ob = ob_base.get_pointer(b'object') + objects.append(ob.get((b'id', b'name'))[2:]) + data['objects'] = objects + + collections = {} + for nested_layer_collection in linkdata_iter(layer_collection, b'layer_collections'): + subname, subdata = get_layer_collection(nested_layer_collection) + collections[subname] = subdata + data['collections'] = collections + + return name, data + + +def get_layer(scene, layer): + data = {} + name = layer.get(b'name') + + data['name'] = name + data['engine'] = scene.get((b'view_render', b'engine_id')) + + active_base = layer.get_pointer(b'basact') + if active_base: + ob = active_base.get_pointer(b'object') + data['active_object'] = ob.get((b'id', b'name'))[2:] + else: + data['active_object'] = "" + + objects = [] + for link in linkdata_iter(layer, b'object_bases'): + ob = link.get_pointer(b'object') + objects.append(ob.get((b'id', b'name'))[2:]) + data['objects'] = objects + + collections = {} + for layer_collection in linkdata_iter(layer, b'layer_collections'): + subname, subdata = get_layer_collection(layer_collection) + collections[subname] = subdata + data['collections'] = collections + + return name, data + + +def get_layers(scene): + """Return all the render layers and their data""" + layers = {} + for layer in linkdata_iter(scene, b'view_layers'): + name, data = get_layer(scene, layer) + layers[name] = data + return layers + + +def get_scene_collection_objects(collection, listbase): + objects = [] + for link in linkdata_iter(collection, listbase): + ob = link.get_pointer(b'data') + if ob is None: + name = 'Fail!' + else: + name = ob.get((b'id', b'name'))[2:] + objects.append(name) + return objects + + +def get_scene_collection(collection): + """""" + data = {} + name = collection.get(b'name') + + data['name'] = name + data['objects'] = get_scene_collection_objects(collection, b'objects') + + collections = {} + for nested_collection in linkdata_iter(collection, b'scene_collections'): + subname, subdata = get_scene_collection(nested_collection) + collections[subname] = subdata + data['collections'] = collections + + return name, data + + +def get_scene_collections(scene): + """Return all the scene collections ahd their data""" + master_collection = scene.get_pointer(b'collection') + return get_scene_collection(master_collection) + + +def query_scene(filepath, name, callbacks): + """Return the equivalent to bpy.context.scene""" + from io_blend_utils.blend import blendfile + + with blendfile.open_blend(filepath) as blend: + scenes = [block for block in blend.blocks if block.code == b'SC'] + for scene in scenes: + if scene.get((b'id', b'name'))[2:] != name: + continue + + return [callback(scene) for callback in callbacks] + + +# ############################################################ +# Utils +# ############################################################ + +def dump(data): + import json + return json.dumps( + data, + sort_keys=True, + indent=4, + separators=(',', ': '), + ) + + +# ############################################################ +# Tests +# ############################################################ + +PDB = False +DUMP_DIFF = True +UPDATE_DIFF = False # HACK used to update tests when something change + + +def compare_files(file_a, file_b): + import filecmp + + if not filecmp.cmp( + file_a, + file_b): + + if DUMP_DIFF: + import subprocess + subprocess.call(["diff", "-u", file_a, file_b]) + + if UPDATE_DIFF: + import subprocess + subprocess.call(["cp", "-u", file_a, file_b]) + + + if PDB: + import pdb + print("Files differ:", file_a, file_b) + pdb.set_trace() + + return False + + return True + + +class ViewLayerTesting(unittest.TestCase): + _test_simple = False + _extra_arguments = [] + + @classmethod + def setUpClass(cls): + """Runs once""" + cls.pretest_parsing() + + @classmethod + def get_root(cls): + """ + return the folder with the test files + """ + arguments = {} + for argument in cls._extra_arguments: + name, value = argument.split('=') + cls.assertTrue(name and name.startswith("--"), "Invalid argument \"{0}\"".format(argument)) + cls.assertTrue(value, "Invalid argument \"{0}\"".format(argument)) + arguments[name[2:]] = value.strip('"') + + return arguments.get('testdir') + + @classmethod + def pretest_parsing(cls): + """ + Test if the arguments are properly set, and store ROOT + name has extra _ because we need this test to run first + """ + root = cls.get_root() + cls.assertTrue(root, "Testdir not set") + + def setUp(self): + """Runs once per test""" + import bpy + bpy.ops.wm.read_factory_settings() + + def path_exists(self, filepath): + import os + self.assertTrue( + os.path.exists(filepath), + "Test file \"{0}\" not found".format(filepath)) + + def do_object_add(self, filepath_json, add_mode): + """ + Testing for adding objects and see if they + go to the right collection + """ + import bpy + import os + import tempfile + import filecmp + + ROOT = self.get_root() + with tempfile.TemporaryDirectory() as dirpath: + filepath_layers = os.path.join(ROOT, 'layers.blend') + + # open file + bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_layers) + self.rename_collections() + + # create sub-collections + three_b = bpy.data.objects.get('T.3b') + three_c = bpy.data.objects.get('T.3c') + + scene = bpy.context.scene + subzero = scene.master_collection.collections['1'].collections.new('sub-zero') + scorpion = subzero.collections.new('scorpion') + subzero.objects.link(three_b) + scorpion.objects.link(three_c) + layer = scene.view_layers.new('Fresh new Layer') + layer.collections.link(subzero) + + # change active collection + layer.collections.active_index = 3 + self.assertEqual(layer.collections.active.name, 'scorpion', "Run: test_syncing_object_add") + + # change active layer + override = bpy.context.copy() + override["view_layer"] = layer + override["scene_collection"] = layer.collections.active.collection + + # add new objects + if add_mode == 'EMPTY': + bpy.ops.object.add(override) # 'Empty' + + elif add_mode == 'CYLINDER': + bpy.ops.mesh.primitive_cylinder_add(override) # 'Cylinder' + + elif add_mode == 'TORUS': + bpy.ops.mesh.primitive_torus_add(override) # 'Torus' + + # save file + filepath_objects = os.path.join(dirpath, 'objects.blend') + bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath_objects) + + # get the generated json + datas = query_scene(filepath_objects, 'Main', (get_scene_collections, get_layers)) + self.assertTrue(datas, "Data is not valid") + + filepath_objects_json = os.path.join(dirpath, "objects.json") + with open(filepath_objects_json, "w") as f: + for data in datas: + f.write(dump(data)) + + self.assertTrue(compare_files( + filepath_objects_json, + filepath_json, + ), + "Scene dump files differ") + + def do_object_add_no_collection(self, add_mode): + """ + Test for adding objects when no collection + exists in render layer + """ + import bpy + + # empty layer of collections + + layer = bpy.context.view_layer + while layer.collections: + layer.collections.unlink(layer.collections[0]) + + # add new objects + if add_mode == 'EMPTY': + bpy.ops.object.add() # 'Empty' + + elif add_mode == 'CYLINDER': + bpy.ops.mesh.primitive_cylinder_add() # 'Cylinder' + + elif add_mode == 'TORUS': + bpy.ops.mesh.primitive_torus_add() # 'Torus' + + self.assertEqual(len(layer.collections), 1, "New collection not created") + collection = layer.collections[0] + self.assertEqual(len(collection.objects), 1, "New collection is empty") + + def do_object_link(self, master_collection): + import bpy + self.assertEqual(master_collection.name, "Master Collection") + self.assertEqual(master_collection, bpy.context.scene.master_collection) + master_collection.objects.link(bpy.data.objects.new('object', None)) + + def do_scene_copy(self, filepath_json_reference, copy_mode, data_callbacks): + import bpy + import os + import tempfile + import filecmp + + ROOT = self.get_root() + with tempfile.TemporaryDirectory() as dirpath: + filepath_layers = os.path.join(ROOT, 'layers.blend') + + (self.path_exists(f) for f in ( + filepath_layers, + filepath_json_reference, + )) + + filepath_saved = os.path.join(dirpath, '{0}.blend'.format(copy_mode)) + filepath_json = os.path.join(dirpath, "{0}.json".format(copy_mode)) + + bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_layers) + self.rename_collections() + bpy.ops.scene.new(type=copy_mode) + bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath_saved) + + datas = query_scene(filepath_saved, 'Main.001', data_callbacks) + self.assertTrue(datas, "Data is not valid") + + with open(filepath_json, "w") as f: + for data in datas: + f.write(dump(data)) + + self.assertTrue(compare_files( + filepath_json, + filepath_json_reference, + ), + "Scene copy \"{0}\" test failed".format(copy_mode.title())) + + def do_object_delete(self, del_mode): + import bpy + import os + import tempfile + import filecmp + + ROOT = self.get_root() + with tempfile.TemporaryDirectory() as dirpath: + filepath_layers = os.path.join(ROOT, 'layers.blend') + filepath_reference_json = os.path.join(ROOT, 'layers_object_delete.json') + + # open file + bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_layers) + self.rename_collections() + + # create sub-collections + three_b = bpy.data.objects.get('T.3b') + three_d = bpy.data.objects.get('T.3d') + + scene = bpy.context.scene + + # mangle the file a bit with some objects linked across collections + subzero = scene.master_collection.collections['1'].collections.new('sub-zero') + scorpion = subzero.collections.new('scorpion') + subzero.objects.link(three_d) + scorpion.objects.link(three_b) + scorpion.objects.link(three_d) + + # object to delete + ob = three_d + + # delete object + if del_mode == 'DATA': + bpy.data.objects.remove(ob, do_unlink=True) + + elif del_mode == 'OPERATOR': + bpy.context.scene.update() # update depsgraph + bpy.ops.object.select_all(action='DESELECT') + ob.select_set(action='SELECT') + self.assertTrue(ob.select_get()) + bpy.ops.object.delete() + + # save file + filepath_generated = os.path.join(dirpath, 'generated.blend') + bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath_generated) + + # get the generated json + datas = query_scene(filepath_generated, 'Main', (get_scene_collections, get_layers)) + self.assertTrue(datas, "Data is not valid") + + filepath_generated_json = os.path.join(dirpath, "generated.json") + with open(filepath_generated_json, "w") as f: + for data in datas: + f.write(dump(data)) + + self.assertTrue(compare_files( + filepath_generated_json, + filepath_reference_json, + ), + "Scene dump files differ") + + def do_visibility_object_add(self, add_mode): + import bpy + + scene = bpy.context.scene + + # delete all objects of the file + for ob in bpy.data.objects: + bpy.data.objects.remove(ob, do_unlink=True) + + # real test + layer = scene.view_layers.new('Visibility Test') + layer.collections.unlink(layer.collections[0]) + scene.view_layers.active = layer + + scene_collection = scene.master_collection.collections.new("Collection") + layer.collections.link(scene_collection) + + bpy.context.scene.update() # update depsgraph + + self.assertEqual(len(bpy.data.objects), 0) + + # add new objects + if add_mode == 'EMPTY': + bpy.ops.object.add() # 'Empty' + + elif add_mode == 'CYLINDER': + bpy.ops.mesh.primitive_cylinder_add() # 'Cylinder' + + elif add_mode == 'TORUS': + bpy.ops.mesh.primitive_torus_add() # 'Torus' + + self.assertEqual(len(bpy.data.objects), 1) + + new_ob = bpy.data.objects[0] + self.assertTrue(new_ob.visible_get(), "Object should be visible") + + def cleanup_tree(self): + """ + Remove any existent layer and collections, + leaving only the one view_layer we can't remove + """ + import bpy + scene = bpy.context.scene + while len(scene.view_layers) > 1: + scene.view_layers.remove(scene.view_layers[1]) + + layer = scene.view_layers[0] + while layer.collections: + layer.collections.unlink(layer.collections[0]) + + master_collection = scene.master_collection + while master_collection.collections: + master_collection.collections.remove(master_collection.collections[0]) + + def rename_collections(self, collection=None): + """ + Rename 'Collection 1' to '1' + """ + def strip_name(collection): + import re + if collection.name.startswith("Default Collection"): + collection.name = '1' + else: + collection.name = re.findall(r'\d+', collection.name)[0] + + if collection is None: + import bpy + collection = bpy.context.scene.master_collection + + for nested_collection in collection.collections: + strip_name(nested_collection) + self.rename_collections(nested_collection) + + +class MoveSceneCollectionTesting(ViewLayerTesting): + """ + To be used by tests of view_layer_move_into_scene_collection + """ + def get_initial_scene_tree_map(self): + collections_map = [ + ['A', [ + ['i', None], + ['ii', None], + ['iii', None], + ]], + ['B', None], + ['C', [ + ['1', None], + ['2', None], + ['3', [ + ['dog', None], + ['cat', None], + ]], + ]], + ] + return collections_map + + def build_scene_tree(self, tree_map, collection=None, ret_dict=None): + """ + Returns a flat dictionary with new scene collections + created from a nested tuple of nested tuples (name, tuple) + """ + import bpy + + if collection is None: + collection = bpy.context.scene.master_collection + + if ret_dict is None: + ret_dict = {collection.name: collection} + self.assertEqual(collection.name, "Master Collection") + + for name, nested_collections in tree_map: + new_collection = collection.collections.new(name) + ret_dict[name] = new_collection + + if nested_collections: + self.build_scene_tree(nested_collections, new_collection, ret_dict) + + return ret_dict + + def setup_tree(self): + """ + Cleanup file, and populate it with class scene tree map + """ + self.cleanup_tree() + self.assertTrue( + hasattr(self, "get_initial_scene_tree_map"), + "Test class has no get_initial_scene_tree_map method implemented") + + return self.build_scene_tree(self.get_initial_scene_tree_map()) + + def get_scene_tree_map(self, collection=None, ret_list=None): + """ + Extract the scene collection tree from scene + Return as a nested list of nested lists (name, list) + """ + import bpy + + if collection is None: + scene = bpy.context.scene + collection = scene.master_collection + + if ret_list is None: + ret_list = [] + + for nested_collection in collection.collections: + new_collection = [nested_collection.name, None] + ret_list.append(new_collection) + + if nested_collection.collections: + new_collection[1] = list() + self.get_scene_tree_map(nested_collection, new_collection[1]) + + return ret_list + + def compare_tree_maps(self): + """ + Compare scene with expected (class defined) data + """ + self.assertEqual(self.get_scene_tree_map(), self.get_reference_scene_tree_map()) + + +class MoveSceneCollectionSyncTesting(MoveSceneCollectionTesting): + """ + To be used by tests of view_layer_move_into_scene_collection_sync + """ + def get_initial_layers_tree_map(self): + layers_map = [ + ['Layer 1', [ + 'Master Collection', + 'C', + '3', + ]], + ['Layer 2', [ + 'C', + '3', + 'dog', + 'cat', + ]], + ] + return layers_map + + def get_reference_layers_tree_map(self): + """ + For those classes we don't expect any changes in the layer tree + """ + return self.get_initial_layers_tree_map() + + def setup_tree(self): + tree = super(MoveSceneCollectionSyncTesting, self).setup_tree() + + import bpy + scene = bpy.context.scene + + self.assertTrue( + hasattr(self, "get_initial_layers_tree_map"), + "Test class has no get_initial_layers_tree_map method implemented") + + layers_map = self.get_initial_layers_tree_map() + + for layer_name, collections_names in layers_map: + layer = scene.view_layers.new(layer_name) + layer.collections.unlink(layer.collections[0]) + + for collection_name in collections_names: + layer.collections.link(tree[collection_name]) + + return tree + + def compare_tree_maps(self): + """ + Compare scene with expected (class defined) data + """ + super(MoveSceneCollectionSyncTesting, self).compare_tree_maps() + + import bpy + scene = bpy.context.scene + layers_map = self.get_reference_layers_tree_map() + + for layer_name, collections_names in layers_map: + layer = scene.view_layers.get(layer_name) + self.assertTrue(layer) + self.assertEqual(len(collections_names), len(layer.collections)) + + for i, collection_name in enumerate(collections_names): + self.assertEqual(collection_name, layer.collections[i].name) + self.verify_collection_tree(layer.collections[i]) + + def verify_collection_tree(self, layer_collection): + """ + Check if the LayerCollection mimics the SceneLayer tree + """ + scene_collection = layer_collection.collection + self.assertEqual(len(layer_collection.collections), len(scene_collection.collections)) + + for i, nested_collection in enumerate(layer_collection.collections): + self.assertEqual(nested_collection.collection.name, scene_collection.collections[i].name) + self.assertEqual(nested_collection.collection, scene_collection.collections[i]) + self.verify_collection_tree(nested_collection) + + +class MoveLayerCollectionTesting(MoveSceneCollectionSyncTesting): + """ + To be used by tests of view_layer_move_into_layer_collection + """ + def parse_move(self, path, sep='.'): + """ + convert 'Layer 1.C.2' into: + bpy.context.scene.view_layers['Layer 1'].collections['C'].collections['2'] + """ + import bpy + + paths = path.split(sep) + layer = bpy.context.scene.view_layers[paths[0]] + collections = layer.collections + + for subpath in paths[1:]: + collection = collections[subpath] + collections = collection.collections + + return collection + + def move_into(self, src, dst): + layer_collection_src = self.parse_move(src) + layer_collection_dst = self.parse_move(dst) + return layer_collection_src.move_into(layer_collection_dst) + + def move_above(self, src, dst): + layer_collection_src = self.parse_move(src) + layer_collection_dst = self.parse_move(dst) + return layer_collection_src.move_above(layer_collection_dst) + + def move_below(self, src, dst): + layer_collection_src = self.parse_move(src) + layer_collection_dst = self.parse_move(dst) + return layer_collection_src.move_below(layer_collection_dst) + + +class Clay: + def __init__(self, extra_kid_layer=False): + import bpy + + self._scene = bpy.context.scene + self._layer = self._fresh_layer() + self._object = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh')) + + # update depsgraph + self._scene.update() + + scene_collection_grandma = self._scene.master_collection.collections.new("Grandma") + scene_collection_mom = scene_collection_grandma.collections.new("Mom") + scene_collection_kid = scene_collection_mom.collections.new("Kid") + scene_collection_kid.objects.link(self._object) + + layer_collection_grandma = self._layer.collections.link(scene_collection_grandma) + layer_collection_mom = layer_collection_grandma.collections[0] + layer_collection_kid = layer_collection_mom.collections[0] + + # store the variables + self._scene_collections = { + 'grandma': scene_collection_grandma, + 'mom': scene_collection_mom, + 'kid': scene_collection_kid, + } + self._layer_collections = { + 'grandma': layer_collection_grandma, + 'mom': layer_collection_mom, + 'kid': layer_collection_kid, + } + + if extra_kid_layer: + layer_collection_extra = self._layer.collections.link(scene_collection_kid) + self._layer_collections['extra'] = layer_collection_extra + + self._update() + + def _fresh_layer(self): + import bpy + + # remove all other objects + while bpy.data.objects: + bpy.data.objects.remove(bpy.data.objects[0]) + + # remove all the other collections + while self._scene.master_collection.collections: + self._scene.master_collection.collections.remove( + self._scene.master_collection.collections[0]) + + layer = self._scene.view_layers.new('Evaluation Test') + layer.collections.unlink(layer.collections[0]) + self._scene.view_layers.active = layer + bpy.context.window.view_layer = layer + + # remove all other layers + for layer_iter in self._scene.view_layers: + if layer_iter != layer: + self._scene.view_layers.remove(layer_iter) + + return layer + + def _update(self): + """ + Force depsgrpah evaluation + and update pointers to IDProperty collections + """ + ENGINE = 'BLENDER_CLAY' + + self._scene.update() # update depsgraph + self._layer.update() # flush depsgraph evaluation + + # change scene settings + self._properties = { + 'scene': self._scene.collection_properties[ENGINE], + 'object': self._object.collection_properties[ENGINE], + } + + for key, value in self._layer_collections.items(): + self._properties[key] = self._layer_collections[key].engine_overrides[ENGINE] + + def get(self, name, data_path): + self._update() + return getattr(self._properties[name], data_path) + + def set(self, name, data_path, value): + self._update() + self._properties[name].use(data_path) + setattr(self._properties[name], data_path, value) + + +def setup_extra_arguments(filepath): + """ + Create a value which is assigned to: ``UnitTesting._extra_arguments`` + """ + import sys + + extra_arguments = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [] + sys.argv = [filepath] + extra_arguments[1:] + + return extra_arguments |