def test_ComposedListOpMetadata(self): '''Tests composition of list op-valued metadata fields''' def _TestComposition(fieldName, weakListOp, strongListOp, expectedListOp): for fmt in allFormats: s = Usd.Stage.CreateNew("TestComposedListOpMetadata."+fmt) ref = s.OverridePrim('/Ref') ref.SetMetadata(fieldName, weakListOp) root = s.OverridePrim('/Root') root.SetMetadata(fieldName, strongListOp) root.GetReferences().AddInternalReference('/Ref') self.assertEqual(root.GetMetadata(fieldName), expectedListOp) # Sdf.IntListOp weakListOp = Sdf.IntListOp() weakListOp.explicitItems = [10, 20, 30] strongListOp = Sdf.IntListOp() strongListOp.addedItems = [-2147483648, 1, 2, 3, 2147483647] strongListOp.deletedItems = [-2147483648, 10, 20, 30, 2147483647] strongListOp.orderedItems = [2147483647, 3, 2, 1, -2147483648] expectedListOp = Sdf.IntListOp() expectedListOp.explicitItems = [2147483647, 3, 2, 1, -2147483648] _TestComposition('intListOpTest', weakListOp, strongListOp, expectedListOp) # Sdf.Int64ListOp weakListOp = Sdf.Int64ListOp() weakListOp.explicitItems = [10, 20, 30] strongListOp = Sdf.Int64ListOp() strongListOp.addedItems = [-9223372036854775808, 1, 2, 3, 9223372036854775807] strongListOp.deletedItems = [-9223372036854775808, 10, 20, 30, 9223372036854775807] strongListOp.orderedItems = [9223372036854775807, 3, 2, 1, -9223372036854775808] expectedListOp = Sdf.Int64ListOp() expectedListOp.explicitItems = [9223372036854775807, 3, 2, 1, -9223372036854775808] _TestComposition('int64ListOpTest', weakListOp, strongListOp, expectedListOp) # Sdf.UIntListOp weakListOp = Sdf.UIntListOp() weakListOp.explicitItems = [10, 20, 30] strongListOp = Sdf.UIntListOp() strongListOp.addedItems = [1, 2, 3, 4294967295] strongListOp.deletedItems = [10, 20, 30, 4294967295] strongListOp.orderedItems = [4294967295, 3, 2, 1] expectedListOp = Sdf.UIntListOp() expectedListOp.explicitItems = [4294967295, 3, 2, 1] _TestComposition('uintListOpTest', weakListOp, strongListOp, expectedListOp) # Sdf.UInt64ListOp weakListOp = Sdf.UInt64ListOp() weakListOp.explicitItems = [10, 20, 30] strongListOp = Sdf.UInt64ListOp() strongListOp.addedItems = [1, 2, 3, 18446744073709551615] strongListOp.deletedItems = [10, 20, 30, 18446744073709551615] strongListOp.orderedItems = [18446744073709551615, 3, 2, 1] expectedListOp = Sdf.UInt64ListOp() expectedListOp.explicitItems = [18446744073709551615, 3, 2, 1] _TestComposition('uint64ListOpTest', weakListOp, strongListOp, expectedListOp) # Sdf.StringListOp weakListOp = Sdf.StringListOp() weakListOp.explicitItems = ["baz"] strongListOp = Sdf.StringListOp() strongListOp.addedItems = ["foo", "bar"] strongListOp.deletedItems = ["baz"] strongListOp.orderedItems = ["bar", "foo"] expectedListOp = Sdf.StringListOp() expectedListOp.explicitItems = ["bar", "foo"] _TestComposition('stringListOpTest', weakListOp, strongListOp, expectedListOp) # Sdf.TokenListOp weakListOp = Sdf.TokenListOp() weakListOp.explicitItems = ["baz"] strongListOp = Sdf.TokenListOp() strongListOp.addedItems = ["foo", "bar"] strongListOp.deletedItems = ["baz"] strongListOp.orderedItems = ["bar", "foo"] expectedListOp = Sdf.TokenListOp() expectedListOp.explicitItems = ["bar", "foo"] _TestComposition('tokenListOpTest', weakListOp, strongListOp, expectedListOp)
def test_BasicListOpMetadata(self): '''Tests basic metadata API with supported list op types''' def _TestBasic(fieldName, listOp, expectedListOp): for fmt in allFormats: s = Usd.Stage.CreateNew("TestBasicListOpMetadata."+fmt) prim = s.OverridePrim('/Root') assert not prim.HasMetadata(fieldName) assert not prim.HasAuthoredMetadata(fieldName) self.assertEqual(prim.GetMetadata(fieldName), None) assert prim.SetMetadata(fieldName, listOp) assert prim.HasMetadata(fieldName) assert prim.HasAuthoredMetadata(fieldName) self.assertEqual(prim.GetMetadata(fieldName), expectedListOp) prim.ClearMetadata(fieldName) assert not prim.HasMetadata(fieldName) assert not prim.HasAuthoredMetadata(fieldName) self.assertEqual(prim.GetMetadata(fieldName), None) # List ops are applied into a single explicit list op during # value resolution, so the expected list op isn't the same # as the given list op. # Sdf.IntListOp listOp = Sdf.IntListOp() listOp.addedItems = [-2147483648, 1, 2, 3, 2147483647] listOp.deletedItems = [-2147483648, 10, 20, 30, 2147483647] listOp.orderedItems = [2147483647, 3, 2, 1, -2147483648] expectedListOp = Sdf.IntListOp() expectedListOp.explicitItems = [2147483647, 3, 2, 1, -2147483648] _TestBasic('intListOpTest', listOp, expectedListOp) # Sdf.Int64ListOp listOp = Sdf.Int64ListOp() listOp.addedItems = [-9223372036854775808, 1, 2, 3, 9223372036854775807] listOp.deletedItems = [-9223372036854775808, 10, 20, 30, 9223372036854775807] listOp.orderedItems = [9223372036854775807, 3, 2, 1, -9223372036854775808] expectedListOp = Sdf.Int64ListOp() expectedListOp.explicitItems = [9223372036854775807, 3, 2, 1, -9223372036854775808] _TestBasic('int64ListOpTest', listOp, expectedListOp) # Sdf.UIntListOp listOp = Sdf.UIntListOp() listOp.addedItems = [1, 2, 3, 4294967295] listOp.deletedItems = [10, 20, 30, 4294967295] listOp.orderedItems = [4294967295, 3, 2, 1] expectedListOp = Sdf.UIntListOp() expectedListOp.explicitItems = [4294967295, 3, 2, 1] _TestBasic('uintListOpTest', listOp, expectedListOp) # Sdf.UInt64ListOp listOp = Sdf.UInt64ListOp() listOp.addedItems = [1, 2, 3, 18446744073709551615] listOp.deletedItems = [10, 20, 30, 18446744073709551615] listOp.orderedItems = [18446744073709551615, 3, 2, 1] expectedListOp = Sdf.UInt64ListOp() expectedListOp.explicitItems = [18446744073709551615, 3, 2, 1] _TestBasic('uint64ListOpTest', listOp, expectedListOp) # Sdf.StringListOp listOp = Sdf.StringListOp() listOp.addedItems = ["foo", "bar"] listOp.deletedItems = ["baz"] listOp.orderedItems = ["bar", "foo"] expectedListOp = Sdf.StringListOp() expectedListOp.explicitItems = ["bar", "foo"] _TestBasic('stringListOpTest', listOp, expectedListOp) # Sdf.TokenListOp listOp = Sdf.TokenListOp() listOp.addedItems = ["foo", "bar"] listOp.deletedItems = ["baz"] listOp.orderedItems = ["bar", "foo"] expectedListOp = Sdf.TokenListOp() expectedListOp.explicitItems = ["bar", "foo"] _TestBasic('tokenListOpTest', listOp, expectedListOp)