chrome/test/mini_installer/registry_operations.py
def VerifyRegistryEntryExpectation(expectation_name, expectation,
                                   variable_expander):
    """Verifies a registry key according to the |expectation|.

    Args:
        expectation_name: The registry key being verified. It is expanded using
            Expand.
        expectation: A dictionary with the following keys and values:
            'exists' a string indicating whether the registry key's existence is
                'required', 'optional', or 'forbidden'. Values are not checked
                if an 'optional' key is not present in the registry.
            'values' (optional) a dictionary where each key is a registry value
                (which is expanded using Expand) and its associated value is a
                dictionary with the following key and values:
                    'type' (optional) a string indicating the type of the
                        registry value. If not present, the corresponding value
                        is expected to be absent in the registry.
                    'data' (optional) the associated data of the registry value
                        if 'type' is specified. If it is a string, it is
                        expanded using Expand. If not present, only the value's
                        type is verified.
            'wow_key' (optional) a string indicating whether the view of the
                registry is KEY_WOW64_32KEY or KEY_WOW64_64KEY. If not present,
                the view of registry is determined by the bitness of the
                installer binary.
        variable_expander: A VariableExpander object.

    Raises:
        AssertionError: If an expectation is not satisfied.
    """
    key = variable_expander.Expand(expectation_name)
    root_key, sub_key = key.split('\\', 1)
    try:
        # Query the Windows registry for the registry key. It will throw a
        # WindowsError if the key doesn't exist.
        registry_view = _winreg.KEY_WOW64_32KEY
        if 'wow_key' in expectation:
            registry_view = _RegistryViewConstant(expectation['wow_key'])
        elif variable_expander.Expand('$MINI_INSTALLER_BITNESS') == '64':
            registry_view = _winreg.KEY_WOW64_64KEY

        key_handle = _winreg.OpenKey(_RootKeyConstant(root_key), sub_key, 0,
                                     _winreg.KEY_QUERY_VALUE | registry_view)
    except WindowsError:
        # Key doesn't exist. See that it matches the expectation.
        assert expectation['exists'] != 'required', ('Registry key %s is '
                                                     'missing' % key)
        # Values are not checked if the missing key's existence is optional.
        return
    # The key exists, see that it matches the expectation.
    assert expectation['exists'] != 'forbidden', ('Registry key %s exists' %
                                                  key)

    # Verify the expected values.
    if 'values' not in expectation:
        return
    for value, value_expectation in expectation['values'].iteritems():
        # Query the value. It will throw a WindowsError if the value doesn't
        # exist.
        value = variable_expander.Expand(value)
        try:
            data, value_type = _winreg.QueryValueEx(key_handle, value)
        except WindowsError:
            # The value does not exist. See that this matches the expectation.
            assert 'type' not in value_expectation, (
                'Value %s of registry key %s '
                'is missing' % (value, key))
            continue

        assert 'type' in value_expectation, (
            'Value %s of registry key %s exists '
            'with value %s' % (value, key, data))

        # Verify the type of the value.
        expected_value_type = value_expectation['type']
        assert _ValueTypeConstant(expected_value_type) == value_type, \
            "Value '%s' of registry key %s has unexpected type '%s'" % (
                value, key, expected_value_type)

        if 'data' not in value_expectation:
            return

        # Verify the associated data of the value.
        expected_data = value_expectation['data']
        if isinstance(expected_data, basestring):
            expected_data = variable_expander.Expand(expected_data)
        assert expected_data == data, \
            ("Value '%s' of registry key %s has unexpected data.\n"
             "  Expected: %s\n"
             "  Actual: %s" % (value, key, expected_data, data))
Verifies a registry key according to the |expectation|.

    Args:
        expectation_name: The registry key being verified. It is expanded using
            Expand.
        expectation: A dictionary with the following keys and values:
            'exists' a string indicating whether the registry key's existence is
                'required', 'optional', or 'forbidden'. Values are not checked
                if an 'optional' key is not present in the registry.
            'values' (optional) a dictionary where each key is a registry value
                (which is expanded using Expand) and its associated value is a
                dictionary with the following key and values:
                    'type' (optional) a string indicating the type of the
                        registry value. If not present, the corresponding value
                        is expected to be absent in the registry.
                    'data' (optional) the associated data of the registry value
                        if 'type' is specified. If it is a string, it is
                        expanded using Expand. If not present, only the value's
                        type is verified.
            'wow_key' (optional) a string indicating whether the view of the
                registry is KEY_WOW64_32KEY or KEY_WOW64_64KEY. If not present,
                the view of registry is determined by the bitness of the
                installer binary.
        variable_expander: A VariableExpander object.

    Raises:
        AssertionError: If an expectation is not satisfied.
    
Verifies a registry key according to the |expectation|.
Verifies a registry key according to the |expectation| .
def VerifyRegistryEntryExpectation(expectation_name, expectation,
                                   variable_expander):
    key = variable_expander.Expand(expectation_name)
    root_key, sub_key = key.split('\\', 1)
    try:
        registry_view = _winreg.KEY_WOW64_32KEY
        if 'wow_key' in expectation:
            registry_view = _RegistryViewConstant(expectation['wow_key'])
        elif variable_expander.Expand('$MINI_INSTALLER_BITNESS') == '64':
            registry_view = _winreg.KEY_WOW64_64KEY
        key_handle = _winreg.OpenKey(_RootKeyConstant(root_key), sub_key, 0,
                                     _winreg.KEY_QUERY_VALUE | registry_view)
    except WindowsError:
        assert expectation['exists'] != 'required', ('Registry key %s is '
                                                     'missing' % key)
        return
    assert expectation['exists'] != 'forbidden', ('Registry key %s exists' %
                                                  key)
    if 'values' not in expectation:
        return
    for value, value_expectation in expectation['values'].iteritems():
        value = variable_expander.Expand(value)
        try:
            data, value_type = _winreg.QueryValueEx(key_handle, value)
        except WindowsError:
            assert 'type' not in value_expectation, (
                'Value %s of registry key %s '
                'is missing' % (value, key))
            continue
        assert 'type' in value_expectation, (
            'Value %s of registry key %s exists '
            'with value %s' % (value, key, data))
        expected_value_type = value_expectation['type']
        assert _ValueTypeConstant(expected_value_type) == value_type, \
            "Value '%s' of registry key %s has unexpected type '%s'" % (
                value, key, expected_value_type)
        if 'data' not in value_expectation:
            return
        expected_data = value_expectation['data']
        if isinstance(expected_data, basestring):
            expected_data = variable_expander.Expand(expected_data)
        assert expected_data == data, \
            ("Value '%s' of registry key %s has unexpected data.\n"
             "  Expected: %s\n"
             "  Actual: %s" % (value, key, expected_data, data))
def VerifyRegistryEntryExpectation ( expectation_name , expectation , variable_expander ) : key = variable_expander . Expand ( expectation_name ) root_key , sub_key = key . split ( '\\' , 1 ) try : registry_view = _winreg . KEY_WOW64_32KEY if 'wow_key' in expectation : registry_view = _RegistryViewConstant ( expectation [ 'wow_key' ] ) elif variable_expander . Expand ( '$MINI_INSTALLER_BITNESS' ) == '64' : registry_view = _winreg . KEY_WOW64_64KEY key_handle = _winreg . OpenKey ( _RootKeyConstant ( root_key ) , sub_key , 0 , _winreg . KEY_QUERY_VALUE | registry_view ) except WindowsError : assert expectation [ 'exists' ] != 'required' , ( 'Registry key %s is ' 'missing' % key ) return assert expectation [ 'exists' ] != 'forbidden' , ( 'Registry key %s exists' % key ) if 'values' not in expectation : return for value , value_expectation in expectation [ 'values' ] . iteritems ( ) : value = variable_expander . Expand ( value ) try : data , value_type = _winreg . QueryValueEx ( key_handle , value ) except WindowsError : assert 'type' not in value_expectation , ( 'Value %s of registry key %s ' 'is missing' % ( value , key ) ) continue assert 'type' in value_expectation , ( 'Value %s of registry key %s exists ' 'with value %s' % ( value , key , data ) ) expected_value_type = value_expectation [ 'type' ] assert _ValueTypeConstant ( expected_value_type ) == value_type , "Value '%s' of registry key %s has unexpected type '%s'" % ( value , key , expected_value_type ) if 'data' not in value_expectation : return expected_data = value_expectation [ 'data' ] if isinstance ( expected_data , basestring ) : expected_data = variable_expander . Expand ( expected_data ) assert expected_data == data , ( "Value '%s' of registry key %s has unexpected data.\n" "  Expected: %s\n" "  Actual: %s" % ( value , key , expected_data , data ) )
Verifies a registry key according to the |expectation|.
Verifies a registry key according to the |expectation| .
"""Verifies a registry key according to the |expectation|.

    Args:
        expectation_name: The registry key being verified. It is expanded using
            Expand.
        expectation: A dictionary with the following keys and values:
            'exists' a string indicating whether the registry key's existence is
                'required', 'optional', or 'forbidden'. Values are not checked
                if an 'optional' key is not present in the registry.
            'values' (optional) a dictionary where each key is a registry value
                (which is expanded using Expand) and its associated value is a
                dictionary with the following key and values:
                    'type' (optional) a string indicating the type of the
                        registry value. If not present, the corresponding value
                        is expected to be absent in the registry.
                    'data' (optional) the associated data of the registry value
                        if 'type' is specified. If it is a string, it is
                        expanded using Expand. If not present, only the value's
                        type is verified.
            'wow_key' (optional) a string indicating whether the view of the
                registry is KEY_WOW64_32KEY or KEY_WOW64_64KEY. If not present,
                the view of registry is determined by the bitness of the
                installer binary.
        variable_expander: A VariableExpander object.

    Raises:
        AssertionError: If an expectation is not satisfied.
    """ # Query the Windows registry for the registry key. It will throw a # WindowsError if the key doesn't exist. # Key doesn't exist. See that it matches the expectation. # Values are not checked if the missing key's existence is optional. # The key exists, see that it matches the expectation. # Verify the expected values. # Query the value. It will throw a WindowsError if the value doesn't # exist. # The value does not exist. See that this matches the expectation. # Verify the type of the value. # Verify the associated data of the value.
If an expectation is not satisfied.
If an expectation is not satisfied .
AssertionError
expectation_name
The registry key being verified. It is expanded using
Expand.
The registry key being verified . It is expanded using Expand .
expectation
A dictionary with the following keys and values:
'exists' a string indicating whether the registry key's existence is
'required', 'optional', or 'forbidden'. Values are not checked
if an 'optional' key is not present in the registry.
'values' (optional) a dictionary where each key is a registry value
(which is expanded using Expand) and its associated value is a
dictionary with the following key and values:
'type' (optional) a string indicating the type of the
registry value. If not present, the corresponding value
is expected to be absent in the registry.
'data' (optional) the associated data of the registry value
if 'type' is specified. If it is a string, it is
expanded using Expand. If not present, only the value's
type is verified.
'wow_key' (optional) a string indicating whether the view of the
registry is KEY_WOW64_32KEY or KEY_WOW64_64KEY. If not present,
the view of registry is determined by the bitness of the
installer binary.
A dictionary with the following keys and values : ' exists ' a string indicating whether the registry key ' s existence is ' required ' ' optional ' or ' forbidden ' . Values are not checked if an ' optional ' key is not present in the registry . ' values ' ( optional ) a dictionary where each key is a registry value ( which is expanded using Expand ) and its associated value is a dictionary with the following key and values : ' type ' ( optional ) a string indicating the type of the registry value . If not present the corresponding value is expected to be absent in the registry . ' data ' ( optional ) the associated data of the registry value if ' type ' is specified . If it is a string it is expanded using Expand . If not present only the value ' s type is verified . ' wow_key ' ( optional ) a string indicating whether the view of the registry is KEY_WOW64_32KEY or KEY_WOW64_64KEY . If not present the view of registry is determined by the bitness of the installer binary .
variable_expander
A VariableExpander object.
A VariableExpander object .