Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
remove improper assert usage
There're many talks about it. An assert should be used for `never
happen` cases, not common paramaters validating.

With grep, we could many all assert statement used in none-test codes:

cinder/volume/drivers/san/solaris.py:110:
cinder/volume/drivers/san/solaris.py:116:
cinder/volume/drivers/san/solaris.py:161:
cinder/volume/drivers/san/solaris.py:162:
cinder/volume/drivers/san/solaris.py:163:
cinder/volume/drivers/san/solaris.py:164:
cinder/volume/drivers/san/solaris.py:170:
    checking cmd output which should never changed, so leave it
cinder/db/sqlalchemy/migration.py:113:
    ensure file existence from impossible cases, so leave it
cinder/utils.py:
    used for functional flow, so use ValueError instead

fixes bug #1199354
Change-Id: I2b1701269bdf7c8737548e57bd940921a6256372
  • Loading branch information
Kun Huang committed Jul 11, 2013
1 parent cfe8dc4 commit 718a529
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions cinder/utils.py
Expand Up @@ -590,21 +590,20 @@ def xhtml_escape(value):
def utf8(value):
"""Try to turn a string into utf-8 if possible.
Code is directly from the utf8 function in
http://github.com/facebook/tornado/blob/master/tornado/escape.py
"""
if isinstance(value, unicode):
return value.encode('utf-8')
assert isinstance(value, str)
return value
elif isinstance(value, str):
return value
else:
raise ValueError("%s is not a string" % value)


def get_from_path(items, path):
"""Returns a list of items matching the specified path.
Takes an XPath-like expression e.g. prop1/prop2/prop3, and for each item
in items, looks up items[prop1][prop2][prop3]. Like XPath, if any of the
in items, looks up items[prop1][prop2][prop3]. Like XPath, if any of the
intermediate results are lists it will treat each list item individually.
A 'None' in items or any child expressions will be ignored, this function
will not throw because of None (anywhere) in items. The returned list
Expand Down

0 comments on commit 718a529

Please sign in to comment.