def test_assert_false(self):
     assert_false(False)
     assert_false("")
     assert_false([1, 2] == (1, 2), "my message")
     assert_raises(AE, assert_false, True)
     assert_raises(AE, assert_false, "non-empty")
     assert_raises_with_msg(AE, "message", assert_false, 0 < 1, "message")
Example #2
0
 def test_assert_true(self):
     assert_true(True)
     assert_true('non-empty string is true')
     assert_true(-1 < 0 < 1, 'my message')
     assert_raises(AE, assert_true, False)
     assert_raises(AE, assert_true, '')
     assert_raises_with_msg(AE, 'message', assert_true, 1 < 0, 'message')
Example #3
0
 def test_init(self):
     assert_true(DotDict() == DotDict({}) == DotDict([]))
     assert_true(DotDict(a=1) == DotDict({'a': 1}) == DotDict([('a', 1)]))
     assert_true(DotDict({'a': 1}, b=2) ==
                 DotDict({'a': 1, 'b': 2}) ==
                 DotDict([('a', 1), ('b', 2)]))
     assert_raises(TypeError, DotDict, None)
 def test_same_option_multiple_times_with_no_prefix(self):
     for usage in [' --foo\n --nofoo\n',
                   ' --nofoo\n --foo\n'
                   ' --nose size\n --se\n']:
         assert_raises(FrameworkError, ArgumentParser, usage)
     ap = ArgumentParser(' --foo value\n --nofoo value\n')
     self.assert_long_opts(['foo=', 'nofoo='], ap)
 def test_del(self):
     del self.dd.x
     del self.dd[2]
     self.dd.pop('z')
     assert_equal(self.dd, {})
     assert_raises(KeyError, self.dd.__delitem__, 'nonex')
     assert_raises(AttributeError, self.dd.__delattr__, 'nonex')
Example #6
0
 def test_del(self):
     del self.dd.x
     del self.dd[2]
     self.dd.pop('z')
     assert_equal(self.dd, {})
     assert_raises(KeyError, self.dd.__delitem__, 'nonex')
     assert_raises(AttributeError, self.dd.__delattr__, 'nonex')
 def _verify_passed_failed_skipped(self, item, initial_status='FAIL'):
     assert_equal(item.status, initial_status)
     assert_equal(item.passed, False)
     assert_equal(item.failed, initial_status == 'FAIL')
     assert_equal(item.skipped, False)
     item.passed = True
     assert_equal(item.passed, True)
     assert_equal(item.failed, False)
     assert_equal(item.skipped, False)
     assert_equal(item.status, 'PASS')
     item.passed = False
     assert_equal(item.passed, False)
     assert_equal(item.failed, True)
     assert_equal(item.skipped, False)
     assert_equal(item.status, 'FAIL')
     item.failed = True
     assert_equal(item.passed, False)
     assert_equal(item.failed, True)
     assert_equal(item.skipped, False)
     assert_equal(item.status, 'FAIL')
     item.failed = False
     assert_equal(item.passed, True)
     assert_equal(item.failed, False)
     assert_equal(item.skipped, False)
     assert_equal(item.status, 'PASS')
     item.skipped = True
     assert_equal(item.passed, False)
     assert_equal(item.failed, False)
     assert_equal(item.skipped, True)
     assert_equal(item.status, 'SKIP')
     assert_raises(ValueError, setattr, item, 'skipped', False)
 def test_init(self):
     assert_true(DotDict() == DotDict({}) == DotDict([]))
     assert_true(DotDict(a=1) == DotDict({'a': 1}) == DotDict([('a', 1)]))
     assert_true(DotDict({'a': 1}, b=2) ==
                 DotDict({'a': 1, 'b': 2}) ==
                 DotDict([('a', 1), ('b', 2)]))
     assert_raises(TypeError, DotDict, None)
Example #9
0
 def test_with_detached_io_buffer(self):
     with io.StringIO() as stream:
         wrapper = io.TextIOWrapper(stream, 'UTF-8')
         wrapper.detach()
         exc_type = ValueError if PYTHON else AttributeError
         assert_raises(exc_type, wrapper.isatty)
         assert_false(isatty(wrapper))
 def test_assert_true(self):
     assert_true(True)
     assert_true("non-empty string is true")
     assert_true(-1 < 0 < 1, "my message")
     assert_raises(AE, assert_true, False)
     assert_raises(AE, assert_true, "")
     assert_raises_with_msg(AE, "message", assert_true, 1 < 0, "message")
 def test_assert_false(self):
     assert_false(False)
     assert_false('')
     assert_false([1,2] == (1,2), 'my message')
     assert_raises(AE, assert_false, True)
     assert_raises(AE, assert_false, 'non-empty')
     assert_raises_with_msg(AE, 'message', assert_false, 0 < 1, 'message')
Example #12
0
 def test_with_detached_io_buffer(self):
     with io.StringIO() as stream:
         wrapper = io.TextIOWrapper(stream, 'UTF-8')
         wrapper.detach()
         exc_type = ValueError if PYTHON else AttributeError
         assert_raises(exc_type, wrapper.isatty)
         assert_false(isatty(wrapper))
 def test_assert_true(self):
     assert_true(True)
     assert_true('non-empty string is true')
     assert_true(-1 < 0 < 1, 'my message')
     assert_raises(AE, assert_true, False)
     assert_raises(AE, assert_true, '')
     assert_raises_with_msg(AE, 'message', assert_true, 1 < 0, 'message')
Example #14
0
 def test_assert_false(self):
     assert_false(False)
     assert_false('')
     assert_false([1,2] == (1,2), 'my message')
     assert_raises(AE, assert_false, True)
     assert_raises(AE, assert_false, 'non-empty')
     assert_raises_with_msg(AE, 'message', assert_false, 0 < 1, 'message')
Example #15
0
 def test_same_option_multiple_times_with_no_prefix(self):
     for usage in [' --foo\n --nofoo\n',
                   ' --nofoo\n --foo\n'
                   ' --nose size\n --se\n']:
         assert_raises(FrameworkError, ArgumentParser, usage)
     ap = ArgumentParser(' --foo value\n --nofoo value\n')
     self.assert_long_opts(['foo=', 'nofoo='], ap)
Example #16
0
 def test_keywords_deprecation(self):
     uk = UserKeyword('Name')
     with warnings.catch_warnings(record=True) as w:
         kws = uk.keywords
         assert_true('deprecated' in str(w[0].message))
     assert_raises(AttributeError, kws.append, Keyword())
     assert_raises(AttributeError, setattr, uk, 'keywords', [])
Example #17
0
 def test_rpa(self):
     for paths in [('.', ), ('pass_and_fail.robot', ),
                   ('pass_and_fail.robot', 'normal.robot')]:
         self._validate_rpa(build(*paths), False)
         self._validate_rpa(build(*paths, rpa=True), True)
     self._validate_rpa(build('../rpa/tasks1.robot'), True)
     self._validate_rpa(build('../rpa/', rpa=False), False)
     assert_raises(DataError, build, '../rpa')
Example #18
0
 def test_keywords_deprecation(self):
     self.suite.setup.config(name='S')
     with warnings.catch_warnings(record=True) as w:
         kws = self.suite.keywords
         assert_equal(len(kws), 1)
         assert_true('deprecated' in str(w[0].message))
     assert_raises(AttributeError, kws.extend, ())
     assert_raises(AttributeError, setattr, self.suite, 'keywords', [])
 def test_json_dump_mapping(self):
     output = StringIO()
     dumper = JsonDumper(output)
     mapped1 = object()
     mapped2 = "string"
     dumper.dump([mapped1, [mapped2, {mapped2: mapped1}]], mapping={mapped1: "1", mapped2: "a"})
     assert_equal(output.getvalue(), "[1,[a,{a:1}]]")
     assert_raises(ValueError, dumper.dump, [mapped1])
 def test_rpa(self):
     for paths in [('.',), ('pass_and_fail.robot',),
                   ('pass_and_fail.robot', 'normal.robot')]:
         self._validate_rpa(build(*paths), False)
         self._validate_rpa(build(*paths, rpa=True), True)
     self._validate_rpa(build('../rpa/tasks1.robot'), True)
     self._validate_rpa(build('../rpa/', rpa=False), False)
     assert_raises(DataError, build, '../rpa')
Example #21
0
 def test_keywords_deprecation(self):
     self.test.body = [Keyword(), Keyword(), Keyword()]
     with warnings.catch_warnings(record=True) as w:
         kws = self.test.keywords
         assert_equal(len(kws), 3)
         assert_true('deprecated' in str(w[0].message))
     assert_raises(AttributeError, kws.append, Keyword())
     assert_raises(AttributeError, setattr, self.test, 'keywords', [])
Example #22
0
 def test_pop(self):
     items = ItemList(str, items='abcde')
     assert_equal(items.pop(), 'e')
     assert_equal(items.pop(0), 'a')
     assert_equal(items.pop(-2), 'c')
     assert_equal(list(items), ['b', 'd'])
     assert_raises(IndexError, items.pop, 7)
     assert_equal(list(items), ['b', 'd'])
     assert_raises(IndexError, ItemList(int).pop)
 def test_json_dump_mapping(self):
     output = StringIO()
     dumper = JsonDumper(output)
     mapped1 = object()
     mapped2 = 'string'
     dumper.dump([mapped1, [mapped2, {mapped2: mapped1}]],
                 mapping={mapped1: '1', mapped2: 'a'})
     assert_equals(output.getvalue(), '[1,[a,{a:1}]]')
     assert_raises(ValueError, dumper.dump, [mapped1])
Example #24
0
 def test_json_dump_mapping(self):
     output = StringIO()
     dumper = JsonDumper(output)
     mapped1 = object()
     mapped2 = 'string'
     dumper.dump([mapped1, [mapped2, {mapped2: mapped1}]],
                 mapping={mapped1: '1', mapped2: 'a'})
     assert_equals(output.getvalue(), '[1,[a,{a:1}]]')
     assert_raises(ValueError, dumper.dump, [mapped1])
Example #25
0
 def test_same_option_multiple_times(self):
     for usage in [
             ' --foo\n --foo\n', ' --foo\n -f --Foo\n',
             ' -x --foo xxx\n -y --Foo yyy\n', ' -f --foo\n -f --bar\n'
     ]:
         assert_raises(FrameworkError, ArgumentParser, usage)
     ap = ArgumentParser(' -f --foo\n -F --bar\n')
     self.assert_short_opts('fF', ap)
     self.assert_long_opts(['foo', 'bar'], ap)
 def test_pop(self):
     items = ItemList(str, items='abcde')
     assert_equal(items.pop(), 'e')
     assert_equal(items.pop(0), 'a')
     assert_equal(items.pop(-2), 'c')
     assert_equal(list(items), ['b', 'd'])
     assert_raises(IndexError, items.pop, 7)
     assert_equal(list(items), ['b', 'd'])
     assert_raises(IndexError, ItemList(int).pop)
 def test_same_option_multiple_times(self):
     for my_usage in [' --foo\n --foo\n',
                      ' --foo\n -f --Foo\n',
                      ' -x --foo xxx\n -y --Foo yyy\n',
                      ' -f --foo\n -f --bar\n']:
         assert_raises(FrameworkError, ArgumentParser, my_usage)
     ap = ArgumentParser(' -f --foo\n -F --bar\n')
     assert_equals(ap._short_opts, 'fF')
     assert_equals(ap._long_opts, ['foo','bar'])
 def test_same_option_multiple_times(self):
     for usage in [' --foo\n --foo\n',
                   ' --foo\n -f --Foo\n',
                   ' -x --foo xxx\n -y --Foo yyy\n',
                   ' -f --foo\n -f --bar\n']:
         assert_raises(FrameworkError, ArgumentParser, usage)
     ap = ArgumentParser(' -f --foo\n -F --bar\n')
     self.assert_short_opts('fF', ap)
     self.assert_long_opts(['foo', 'bar'], ap)
Example #29
0
 def test_keywords_deprecation(self):
     uk = UserKeyword('Name')
     uk.body.create_keyword()
     uk.teardown.config(name='T')
     with warnings.catch_warnings(record=True) as w:
         kws = uk.keywords
         assert_equal(len(kws), 2)
         assert_true('deprecated' in str(w[0].message))
     assert_raises(AttributeError, kws.append, Keyword())
     assert_raises(AttributeError, setattr, uk, 'keywords', [])
Example #30
0
 def test_keywords_deprecation(self):
     kw = Keyword()
     kw.body = [Keyword(), Message(), Keyword(), Keyword(), Message()]
     kw.teardown.config(kwname='T')
     with warnings.catch_warnings(record=True) as w:
         kws = kw.keywords
         assert_equal(list(kws), [kw.body[0], kw.body[2], kw.body[3], kw.teardown])
         assert_true('deprecated' in str(w[0].message))
     assert_raises(AttributeError, kws.append, Keyword())
     assert_raises(AttributeError, setattr, kw, 'keywords', [])
 def test_delitem(self):
     items = ItemList(str, items='abcde')
     del items[0]
     assert_equal(list(items), list('bcde'))
     del items[1]
     assert_equal(list(items), list('bde'))
     del items[-1]
     assert_equal(list(items), list('bd'))
     assert_raises(IndexError, items.__delitem__, 10)
     assert_equal(list(items), list('bd'))
 def test_remove(self):
     items = ItemList(str, items='abcba')
     items.remove('c')
     assert_equal(list(items), list('abba'))
     items.remove('a')
     assert_equal(list(items), list('bba'))
     items.remove('b')
     items.remove('a')
     items.remove('b')
     assert_equal(list(items), list(''))
     assert_raises(ValueError, items.remove, 'nonex')
Example #33
0
 def test_some_methods_implemented(self):
     class MyListener(object):
         ROBOT_LISTENER_API_VERSION = 2
         def end_suite(self, suite):
             pass
     libs = LibraryListeners()
     libs.new_suite_scope()
     libs.register([MyListener()], None)
     for listeners in [Listeners([MyListener()]), libs]:
         listeners.start_suite(None)
         assert_raises(AttributeError, listeners.end_suite, None)
 def test_bytes(self):
     if IRONPYTHON:
         return
     elif PY2:
         assert Matcher(b'foo').match(b'foo')
         assert Matcher(b'f*').match(b'foo')
         assert Matcher('f*').match(b'foo')
         assert Matcher(b'f*').match('foo')
         assert Matcher(b'f.*', regexp=True).match(b'foo')
     else:
         assert_raises(TypeError, Matcher, b'foo')
         assert_raises(TypeError, Matcher('foo').match, b'foo')
Example #35
0
 def test_bytes(self):
     if IRONPYTHON:
         return
     elif PY2:
         assert Matcher(b'foo').match(b'foo')
         assert Matcher(b'f*').match(b'foo')
         assert Matcher('f*').match(b'foo')
         assert Matcher(b'f*').match('foo')
         assert Matcher(b'f.*', regexp=True).match(b'foo')
     else:
         assert_raises(TypeError, Matcher, b'foo')
         assert_raises(TypeError, Matcher('foo').match, b'foo')
Example #36
0
 def _should_raise_error(self,
                         inplace=False,
                         recursive=False,
                         format=None,
                         spacecount=None,
                         args=['a_file.txt']):
     opts = {
         'inplace': inplace,
         'recursive': recursive,
         'format': format,
         'spacecount': spacecount
     }
     assert_raises(DataError, TidyCommandLine().validate, opts, args)
Example #37
0
 def test_isatty_with_detached_io_buffer(self):
     # make sure that isatty() checks for detached io stream buffers
     # (otherwise it would raise an Exception)
     with io.StringIO() as stream:
         wrapper = io.TextIOWrapper(stream)
         if sys.version_info >= (2, 7):
             wrapper.detach() #==> wrapper.buffer is None
             # Jython 2.7 behaves like CPython 2.6 in that case
             exc_type = ValueError if not JYTHON else AttributeError
         else: # no .detach and different behaviour if .buffer is None
             wrapper.buffer = None
             exc_type = AttributeError
         assert_raises(exc_type, wrapper.isatty)
         assert_false(isatty(wrapper))
 def test_caseless_and_spaceless(self):
     nd1 = NormalizedDict({"F o o BAR": "value"})
     nd2 = NormalizedDict({"F o o BAR": "value"}, caseless=False, spaceless=False)
     assert_equals(nd1["F o o BAR"], "value")
     assert_equals(nd2["F o o BAR"], "value")
     nd1["FooBAR"] = "value 2"
     nd2["FooBAR"] = "value 2"
     assert_equals(nd1["F o o BAR"], "value 2")
     assert_equals(nd2["F o o BAR"], "value")
     assert_equals(nd1["FooBAR"], "value 2")
     assert_equals(nd2["FooBAR"], "value 2")
     for key in ["foobar", "f o o b ar", "Foo BAR"]:
         assert_equals(nd1[key], "value 2")
         assert_raises(KeyError, nd2.__getitem__, key)
         assert_true(key not in nd2)
Example #39
0
 def test_import_non_existing_module(self):
     msg = ("Importing library '{libname}' failed: "
            "ModuleNotFoundError: No module named '{modname}'")
     for name in 'nonexisting', 'nonexi.sting':
         error = assert_raises(DataError, TestLibrary, name)
         expected = msg.format(libname=name, modname=name.split('.')[0])
         assert_equal(str(error).splitlines()[0], expected)
Example #40
0
 def test_caseless_and_spaceless(self):
     nd1 = NormalizedDict({'F o o BAR': 'value'})
     nd2 = NormalizedDict({'F o o BAR': 'value'}, caseless=False,
                          spaceless=False)
     assert_equal(nd1['F o o BAR'], 'value')
     assert_equal(nd2['F o o BAR'], 'value')
     nd1['FooBAR'] = 'value 2'
     nd2['FooBAR'] = 'value 2'
     assert_equal(nd1['F o o BAR'], 'value 2')
     assert_equal(nd2['F o o BAR'], 'value')
     assert_equal(nd1['FooBAR'], 'value 2')
     assert_equal(nd2['FooBAR'], 'value 2')
     for key in ['foobar', 'f o o b ar', 'Foo BAR']:
         assert_equal(nd1[key], 'value 2')
         assert_raises(KeyError, nd2.__getitem__, key)
         assert_true(key not in nd2)
 def test_caseless_and_spaceless(self):
     nd1 = NormalizedDict({'F o o BAR': 'value'})
     nd2 = NormalizedDict({'F o o BAR': 'value'}, caseless=False,
                          spaceless=False)
     assert_equal(nd1['F o o BAR'], 'value')
     assert_equal(nd2['F o o BAR'], 'value')
     nd1['FooBAR'] = 'value 2'
     nd2['FooBAR'] = 'value 2'
     assert_equal(nd1['F o o BAR'], 'value 2')
     assert_equal(nd2['F o o BAR'], 'value')
     assert_equal(nd1['FooBAR'], 'value 2')
     assert_equal(nd2['FooBAR'], 'value 2')
     for key in ['foobar', 'f o o b ar', 'Foo BAR']:
         assert_equal(nd1[key], 'value 2')
         assert_raises(KeyError, nd2.__getitem__, key)
         assert_true(key not in nd2)
Example #42
0
 def test_invalid_python_file(self):
     path = create_temp_file('test.py', extra_content='invalid content')
     error = assert_raises(DataError,
                           self._import_and_verify,
                           path,
                           remove='test')
     assert_prefix(error, "Importing '%s' failed: SyntaxError:" % path)
Example #43
0
 def test_instantiate_failure(self):
     err = assert_raises(DataError,
                         Importer().import_class_or_module,
                         'ExampleLibrary', ['accepts', 'no', 'args'])
     assert_true(
         unicode(err).startswith("Importing 'ExampleLibrary' failed: "
                                 "Creating instance failed: TypeError:"))
Example #44
0
 def test_math_with_internal_vars_does_not_work_if_first_var_is_float(self):
     assert_raises(VariableError, self.varz.replace_scalar,
                   '${${1.1}+${2}}')
     assert_raises(VariableError, self.varz.replace_scalar,
                   '${${1.1} - ${2}}')
     assert_raises(VariableError, self.varz.replace_scalar,
                   '${${1.1} * ${2}}')
     assert_raises(VariableError, self.varz.replace_scalar,
                   '${${1.1}/${2}}')
 def test_assert_equal(self):
     assert_equal("str", "str")
     assert_equal(42, 42, "hello", True)
     assert_equal(MyEqual("hello"), MyEqual("hello"))
     assert_equal(None, None)
     assert_raises(AE, assert_equal, "str", "STR")
     assert_raises(AE, assert_equal, 42, 43)
     assert_raises(AE, assert_equal, MyEqual("hello"), MyEqual("world"))
     assert_raises(AE, assert_equal, None, True)
 def test_assert_equal(self):
     assert_equal('str', 'str')
     assert_equal(42, 42, 'hello', True)
     assert_equal(MyEqual('hello'), MyEqual('hello'))
     assert_equal(None, None)
     assert_raises(AE, assert_equal, 'str', 'STR')
     assert_raises(AE, assert_equal, 42, 43)
     assert_raises(AE, assert_equal, MyEqual('hello'), MyEqual('world'))
     assert_raises(AE, assert_equal, None, True)
Example #47
0
 def test_assert_equal(self):
     assert_equal('str', 'str')
     assert_equal(42, 42, 'hello', True)
     assert_equal(MyEqual('hello'), MyEqual('hello'))
     assert_equal(None, None)
     assert_raises(AE, assert_equal, 'str', 'STR')
     assert_raises(AE, assert_equal, 42, 43)
     assert_raises(AE, assert_equal, MyEqual('hello'), MyEqual('world'))
     assert_raises(AE, assert_equal, None, True)
 def test_sequence_subscript(self):
     sequences = (
         [42, 'my', 'name'],
         (42, ['foo', 'bar'], 'name'),
         'abcDEF123#@$',
         b'abcDEF123#@$',
         bytearray(b'abcDEF123#@$'),
     )
     for var in sequences:
         self.varz['${var}'] = var
         assert_equal(self.varz.replace_scalar('${var}[0]'), var[0])
         assert_equal(self.varz.replace_scalar('${var}[-2]'), var[-2])
         assert_equal(self.varz.replace_scalar('${var}[::2]'), var[::2])
         assert_equal(self.varz.replace_scalar('${var}[1::2]'), var[1::2])
         assert_equal(self.varz.replace_scalar('${var}[1:-3:2]'),
                      var[1:-3:2])
         assert_raises(VariableError, self.varz.replace_scalar,
                       '${var}[0][1]')
 def test_invalid_file_by_path(self):
     path = join(TEMPDIR, 'robot_import_invalid_test_file.py')
     try:
         with open(path, 'w') as file:
             file.write('invalid content')
         error = assert_raises(DataError, self._import, path)
         assert_prefix(error, "Importing '%s' failed: SyntaxError:" % path)
     finally:
         os.remove(path)
 def test_creating_with_invalid_format_fails(self):
     assert_raises(DataError, WritingContext, datafile=None, format='inv')
Example #51
0
 def test_fail(self):
     assert_raises(AE, fail)
     assert_raises_with_msg(AE, 'hello', fail, 'hello')
Example #52
0
 def test_assert_raises(self):
     assert_raises(ValueError, int, 'not int')
     self.assertRaises(ValueError, assert_raises, MyExc, int, 'not int')
     self.assertRaises(AssertionError, assert_raises, ValueError, int, '1')
 def test_import_non_existing(self):
     error = assert_raises(DataError, self._import, 'NonExisting')
     assert_prefix(error, "Importing 'NonExisting' failed: ImportError:")
 def test_item_from_non_existing_module(self):
     error = assert_raises(DataError, self._import, 'nonex.item')
     assert_prefix(error, "Importing 'nonex.item' failed: ImportError:")
Example #55
0
 def test_slots(self):
     assert_raises(AttributeError, setattr, self.suite, 'attr', 'value')
Example #56
0
 def test_index(self):
     items = ItemList(str, items=('first', 'second'))
     assert_equal(items.index('first'), 0)
     assert_equal(items.index('second'), 1)
     assert_raises(ValueError, items.index, 'nonex')
 def _failing_import(self, name):
     importer = Importer().import_class_or_module
     return assert_raises(DataError, importer, name)
 def test_instantiate_failure(self):
     err = assert_raises(DataError, Importer().import_class_or_module,
                         'ExampleLibrary', ['accepts', 'no', 'args'])
     assert_true(unicode(err).startswith("Importing 'ExampleLibrary' failed: "
                                         "Creating instance failed: TypeError:"))