def test_variable_substitution_in_key()

in tools/plisttool/plisttool_unittest.py [0:0]


  def test_variable_substitution_in_key(self):
    plist1 = {
        'Foo${Braces}': 'Bar'
    }
    with self.assertRaisesRegex(
        plisttool.PlistToolError,
        re.escape(plisttool.UNSUPPORTED_SUBSTITUTATION_REFERENCE_IN_KEY_MSG % (
            _testing_target, '${Braces}', 'Foo${Braces}'))):
      _plisttool_result({'plists': [plist1]})

    plist2 = {
        'Foo$(Parens)': 'Bar'
    }
    with self.assertRaisesRegex(
        plisttool.PlistToolError,
        re.escape(plisttool.UNSUPPORTED_SUBSTITUTATION_REFERENCE_IN_KEY_MSG % (
            _testing_target, '$(Parens)', 'Foo$(Parens)'))):
      _plisttool_result({'plists': [plist2]})

    # Nested dict, will include the keypath.
    plist3 = {
        'Key1': {
            'Key${2}': 'value'
        }
    }
    with self.assertRaisesRegex(
        plisttool.PlistToolError,
        re.escape(plisttool.UNSUPPORTED_SUBSTITUTATION_REFERENCE_IN_KEY_MSG % (
            _testing_target, '${2}', 'Key1:Key${2}'))):
      _plisttool_result({'plists': [plist3]})

    # Array (of dict), will include the keypath.
    plist3 = {
        'Key1': [
            {'Foo': 'Bar'},
            {'Key${2}': 'value'},
        ]
    }
    with self.assertRaisesRegex(
        plisttool.PlistToolError,
        re.escape(plisttool.UNSUPPORTED_SUBSTITUTATION_REFERENCE_IN_KEY_MSG % (
            _testing_target, '${2}', 'Key1[1]:Key${2}'))):
      _plisttool_result({'plists': [plist3]})