cc-4232: fixed some tests

This commit is contained in:
Rudi Grinberg 2012-08-17 15:08:11 -04:00
parent 99437147dc
commit 1c865fc3f1
3 changed files with 15 additions and 15 deletions

View file

@ -163,11 +163,13 @@ def apply_rules_dict(d, rules):
"""
Consumes a dictionary of rules that maps some keys to lambdas which it
applies to every matching element in d and returns a new dictionary with
the rules applied
the rules applied. If a rule returns none then it's not applied
"""
new_d = copy.deepcopy(d)
for k, rule in rules.iteritems():
if k in d: new_d[k] = rule(d[k])
if k in d:
new_val = rule(d[k])
if new_val is not None: new_d[k] = new_val
return new_d
def default_to_f(dictionary, keys, default, condition):
@ -183,10 +185,6 @@ def default_to(dictionary, keys, default):
"""
cnd = lambda dictionary, key: key not in dictionary
return default_to_f(dictionary, keys, default, cnd)
#new_d = copy.deepcopy(dictionary)
#for k in keys:
#if not (k in new_d): new_d[k] = default
#return new_d
def remove_whitespace(dictionary):
"""
@ -205,18 +203,18 @@ def remove_whitespace(dictionary):
def parse_int(s):
"""
Tries very hard to get some sort of integer result from s. Defaults to 0
when it failes
when it fails
>>> parse_int("123")
'123'
>>> parse_int("123saf")
'123'
>>> parse_int("asdf")
''
nothing
"""
if s.isdigit(): return s
else:
try : return str(reduce(op.add, takewhile(lambda x: x.isdigit(), s)))
except: return ''
except: return None
def normalized_metadata(md, original_path):
"""