Exemple #1
0
def test_repr():
    """Verify that __repr__ returns valid Python expressions"""
    match = Match('a pattern', msg='message')
    replace = Replace('you', 'I', msg='you and I')
    range_ = Range(min=0, max=42, min_included=False,
                   max_included=False, msg='number not in range')
    coerce_ = Coerce(int, msg="moo")
    all_ = All('10', Coerce(int), msg='all msg')

    assert_equal(repr(match), "Match('a pattern', msg='message')")
    assert_equal(repr(replace), "Replace('you', 'I', msg='you and I')")
    assert_equal(
        repr(range_),
        "Range(min=0, max=42, min_included=False, max_included=False, msg='number not in range')"
    )
    assert_equal(repr(coerce_), "Coerce(int, msg='moo')")
    assert_equal(repr(all_), "All('10', Coerce(int, msg=None), msg='all msg')")
Exemple #2
0
# Validator for each member of the 'entry' list in the feed.
# Includes some minor transformations to simplify later validations
ENTRY_SCHEMA = Schema(
    {'category': All({'@term': Any('Weather Forecasts', 'Current Conditions',
                                   'Warnings and Watches')}, dict.values,
                     ''.join),
     Remove('id'): unicode,
     Remove('link'):
     {'@href': unicode,
      '@type': 'text/html'},
     'published': unicode,
     'summary': All({'#text': unicode,
                     Remove('@type'): 'html'}, dict.values, ''.join),
     'title': unicode,
     'updated': unicode},
    extra=REMOVE_EXTRA)

WW_SCHEMA = Schema({Remove('category'): unicode}, extra=ALLOW_EXTRA)

CC_SCHEMA = Schema(
    {Remove('category'): unicode,
     All('summary', SetTo('data')):
     All(Replace('°', ' '), Replace(u'\N{DEGREE SIGN}', ' '),
         html_to_dict),
     'title': All(Replace('°', ' '), Replace(u'\N{DEGREE SIGN}', ' '))},
    extra=ALLOW_EXTRA)

WF_SCHEMA = Schema({Remove('category'): unicode,
                    'summary': All(Replace('Forecast issued.*$', ''), Strip),
}, extra=ALLOW_EXTRA)