Example #1
0
 def test_orelse_type(self):
     assert_equal(If().orelse.type, None)
     assert_equal(If().orelse.config().type, If.ELSE_TYPE)
     assert_equal(If().orelse.config(condition='$x').type, If.ELSE_IF_TYPE)
     assert_equal(If().orelse.config(condition='$x').orelse.type, None)
     assert_equal(If().orelse.config(condition='$x').orelse.config().type,
                  If.ELSE_TYPE)
Example #2
0
 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])
Example #3
0
 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])
Example #4
0
 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])
Example #5
0
 def test_deprecated_keyword_specific_properties(self):
     if_ = If('$x > 0')
     tmpl = "'If.%s' is deprecated since Robot Framework 4.0."
     for name, expected in [('name', '$x > 0'), ('doc', ''), ('args', ()),
                            ('assign', ()), ('tags', Tags()),
                            ('timeout', None)]:
         with warnings.catch_warnings(record=True) as w:
             assert_equal(getattr(if_, name), expected)
             assert_true(str(w[0].message).startswith(tmpl % name))
             assert_equal(w[0].category, UserWarning)
Example #6
0
 def test_config_does_not_set_type_if_its_set(self):
     assert_equal(If().config().type, If.IF_TYPE)
     assert_equal(If(type=If.ELSE_TYPE).config().type, If.ELSE_TYPE)
     assert_equal(If(type=If.ELSE_IF_TYPE).config().type, If.ELSE_IF_TYPE)
     assert_equal(If(type=None).config(type=If.IF_TYPE).type, If.IF_TYPE)
     assert_equal(
         If(type=None).config(type=If.ELSE_TYPE).type, If.ELSE_TYPE)
     assert_equal(
         If(type=None).config(type=If.ELSE_IF_TYPE).type, If.ELSE_IF_TYPE)
Example #7
0
 def test_string_reprs(self):
     for if_, exp_str, exp_repr in [
         (If(), 'IF    None', 'If(condition=None)'),
         (If('$x > 1'), 'IF    $x > 1', "If(condition='$x > 1')"),
         (If().orelse.config(condition='$x > 2'), 'ELSE IF    $x > 2',
          "If(condition='$x > 2')"),
         (If().orelse.config(condition=None), 'ELSE', 'If(condition=None)'),
         (If().orelse, 'None', 'If(condition=INACTIVE)'),
         (If(u'$x == "\xe4iti"'), u'IF    $x == "\xe4iti"',
          u'If(condition=%r)' % u'$x == "\xe4iti"'),
     ]:
         assert_equal(unicode(if_), exp_str)
         assert_equal(repr(if_), exp_repr)
         if PY2:
             assert_equal(str(if_), unicode(if_).encode('UTF-8'))
Example #8
0
 def test_string_reprs(self):
     for if_, exp_str, exp_repr in [
         (If(), 'IF    None', "If(condition=None, type='if')"),
         (If('$x > 1'), 'IF    $x > 1',
          "If(condition='$x > 1', type='if')"),
         (If().orelse.config(condition='$x > 2'), 'ELSE IF    $x > 2',
          "If(condition='$x > 2', type='elseif')"),
         (If().orelse.config(), 'ELSE', "If(condition=None, type='else')"),
         (If().orelse, 'None', "If(condition=None, type=None)"),
         (If(u'$x == "\xe4iti"'), u'IF    $x == "\xe4iti"',
          u"If(condition=%r, type='if')" % u'$x == "\xe4iti"'),
     ]:
         assert_equal(unicode(if_), exp_str)
         assert_equal(repr(if_), 'robot.model.' + exp_repr)
         if PY2:
             assert_equal(str(if_), unicode(if_).encode('UTF-8'))
Example #9
0
 def test_orelse(self):
     self._validate_orelse(If().orelse)
     self._validate_orelse(If().orelse.config().orelse)
     self._validate_orelse(If().orelse.config().orelse.config().orelse)
Example #10
0
 def test_type_with_nested_if(self):
     assert_equal(If().body.create_if().type, If.IF_TYPE)
     assert_equal(If().body.create_if().orelse.type, None)
     assert_equal(If().body.create_if().orelse.config().type, If.ELSE_TYPE)
Example #11
0
 def test_config_sets_type_if_its_not_set(self):
     assert_equal(If(type=None).config().type, If.ELSE_TYPE)
     assert_equal(
         If(type=None).config(condition='$x > 0').type, If.ELSE_IF_TYPE)
Example #12
0
 def test_type(self):
     assert_equal(If().type, If.IF_TYPE)
     assert_equal(If(type=If.ELSE_TYPE).type, If.ELSE_TYPE)
     assert_equal(If(type=If.ELSE_IF_TYPE).type, If.ELSE_IF_TYPE)
     assert_equal(If(type=None).type, None)
Example #13
0
 def test_branch_id_with_only_root(self):
     root = If()
     assert_equal(root.body.create_branch().id, 'k1')
     assert_equal(root.body.create_branch().id, 'k2')
Example #14
0
 def test_root_id(self):
     assert_equal(If().id, None)
     assert_equal(TestCase().body.create_if().id, None)