While not strictly necessary for files containing only ASCII characters, adding a line with "coding: utf-8" can guard against future SyntaxError's in case someone inserts a Unicode literal. This commit adds such lines to all .py files. The syntax used by this commit works with Python (of course). It also works with Emacs, which will recognize the special "-*-" marker and use the "coding" variable to correctly decode the file, even in an environment where UTF-8 is not the default file encoding. Existing coding lines were normalized to match the new lines added. Partial-bug: #1325193 Change-Id: I58bf93fea711fd25890356a397e594bd820c99e3
67 lines
2.4 KiB
Python
67 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
#
|
|
# Copyright 2013 OpenStack LLC.
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
from ironicclient.common import utils
|
|
from ironicclient import exc
|
|
from ironicclient.tests import utils as test_utils
|
|
|
|
|
|
class UtilsTest(test_utils.BaseTestCase):
|
|
def test_args_array_to_dict(self):
|
|
my_args = {
|
|
'matching_metadata': ['metadata.key=metadata_value'],
|
|
'other': 'value'
|
|
}
|
|
cleaned_dict = utils.args_array_to_dict(my_args,
|
|
"matching_metadata")
|
|
self.assertEqual({
|
|
'matching_metadata': {'metadata.key': 'metadata_value'},
|
|
'other': 'value'
|
|
}, cleaned_dict)
|
|
|
|
def test_args_array_to_patch(self):
|
|
my_args = {
|
|
'attributes': ['foo=bar', '/extra/bar=baz'],
|
|
'op': 'add',
|
|
}
|
|
patch = utils.args_array_to_patch(my_args['op'],
|
|
my_args['attributes'])
|
|
self.assertEqual([{'op': 'add',
|
|
'value': 'bar',
|
|
'path': '/foo'},
|
|
{'op': 'add',
|
|
'value': 'baz',
|
|
'path': '/extra/bar'}], patch)
|
|
|
|
def test_args_array_to_patch_format_error(self):
|
|
my_args = {
|
|
'attributes': ['foobar'],
|
|
'op': 'add',
|
|
}
|
|
self.assertRaises(exc.CommandError, utils.args_array_to_patch,
|
|
my_args['op'], my_args['attributes'])
|
|
|
|
def test_args_array_to_patch_remove(self):
|
|
my_args = {
|
|
'attributes': ['/foo', 'extra/bar'],
|
|
'op': 'remove',
|
|
}
|
|
patch = utils.args_array_to_patch(my_args['op'],
|
|
my_args['attributes'])
|
|
self.assertEqual([{'op': 'remove', 'path': '/foo'},
|
|
{'op': 'remove', 'path': '/extra/bar'}], patch)
|