From e969ac64137e53c0a375886d5e175f1e6b05073a Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Fri, 19 Jan 2018 18:44:11 -0200 Subject: Fix collections names no longer unique when moved around We were not checking for uniqueness after moving. And in some cases the new siblings of our collection may have conflicting names. --- tests/python/view_layer/CMakeLists.txt | 3 +- tests/python/view_layer/test_collection_rename.py | 91 ---------------------- .../python/view_layer/test_collection_rename_a.py | 91 ++++++++++++++++++++++ .../python/view_layer/test_collection_rename_b.py | 58 ++++++++++++++ 4 files changed, 151 insertions(+), 92 deletions(-) delete mode 100644 tests/python/view_layer/test_collection_rename.py create mode 100644 tests/python/view_layer/test_collection_rename_a.py create mode 100644 tests/python/view_layer/test_collection_rename_b.py (limited to 'tests') diff --git a/tests/python/view_layer/CMakeLists.txt b/tests/python/view_layer/CMakeLists.txt index 69b02416487..e308e2e0952 100644 --- a/tests/python/view_layer/CMakeLists.txt +++ b/tests/python/view_layer/CMakeLists.txt @@ -62,7 +62,8 @@ endmacro() VIEW_LAYER_TEST(active_collection) VIEW_LAYER_TEST(background_set) -VIEW_LAYER_TEST(collection_rename) +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) diff --git a/tests/python/view_layer/test_collection_rename.py b/tests/python/view_layer/test_collection_rename.py deleted file mode 100644 index ea156d7346f..00000000000 --- a/tests/python/view_layer/test_collection_rename.py +++ /dev/null @@ -1,91 +0,0 @@ -# ############################################################ -# 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_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() -- cgit v1.2.3