def test_filter_with_predicate(self): x = Keyword(name='x') predicate = lambda item: item.name == 'x' body = Body(items=[Keyword(), x, Keyword()]) assert_equal(body.filter(predicate=predicate), [x]) body = Body(items=[Keyword(), If(), x, For(), Keyword()]) assert_equal(body.filter(keywords=True, predicate=predicate), [x])
def test_filter_when_included_or_excluded_type_is_disabled(self): class NoKeywords(Body): keyword_class = None f1, i1, i2 = For(), If(), If() body = NoKeywords(items=[f1, i1, i2]) assert_equal(body.filter(keywords=False), [f1, i1, i2]) assert_equal(body.filter(ifs=True, keywords=True), [i1, i2])
def test_string_reprs(self): for for_, exp_str, exp_repr in [ (For(), 'FOR IN ', "For(variables=(), flavor='IN', values=())"), (For(('${x}',), 'IN RANGE', ('10',)), 'FOR ${x} IN RANGE 10', "For(variables=('${x}',), flavor='IN RANGE', values=('10',))"), (For(('${x}', '${y}'), 'IN ENUMERATE', ('a', 'b')), 'FOR ${x} ${y} IN ENUMERATE a b', "For(variables=('${x}', '${y}'), flavor='IN ENUMERATE', values=('a', 'b'))"), (For([u'${\xfc}'], 'IN', [u'f\xf6\xf6']), u'FOR ${\xfc} IN f\xf6\xf6', u"For(variables=[%r], flavor='IN', values=[%r])" % (u'${\xfc}', u'f\xf6\xf6')) ]: assert_equal(str(for_), exp_str) assert_equal(repr(for_), 'robot.model.' + exp_repr)
def test_filter(self): k1, k2, k3 = Keyword(), Keyword(), Keyword() f1, i1, i2 = For(), If(), If() body = Body(items=[k1, f1, i1, i2, k2, k3]) assert_equal(body.filter(keywords=True), [k1, k2, k3]) assert_equal(body.filter(keywords=False), [f1, i1, i2]) assert_equal(body.filter(ifs=True, fors=True), [f1, i1, i2]) assert_equal(body.filter(ifs=False, fors=False), [k1, k2, k3]) assert_equal(body.filter(), [k1, f1, i1, i2, k2, k3])
def test_deprecated_keyword_specific_properties(self): for_ = For(['${x}', '${y}'], 'IN', ['a', 'b', 'c', 'd']) tmpl = "'For.%s' is deprecated since Robot Framework 4.0." for name, expected in [('name', '${x} | ${y} IN [ a | b | c | d ]'), ('doc', ''), ('args', ()), ('assign', ()), ('tags', Tags()), ('timeout', None)]: with warnings.catch_warnings(record=True) as w: assert_equal(getattr(for_, name), expected) assert_true(str(w[0].message).startswith(tmpl % name)) assert_equal(w[0].category, UserWarning)