def test_find_with_invalid_prefix(self):
     finder = ElementFinder()
     browser = mock()
     assert_raises_with_msg(ValueError, "Element locator with prefix 'something' is not supported",
                            finder.find, browser, "something=test1")
     assert_raises_with_msg(ValueError, "Element locator with prefix ' by ID ' is not supported",
                            finder.find, browser, " by ID =test1")
 def test_parse_modified_time_with_invalid_times(self):
     for value, msg in [("-100", "Epoch time must be positive (got -100)"),
                        ("YYYY-MM-DD hh:mm:ss",
                         "Invalid time format 'YYYY-MM-DD hh:mm:ss'"),
                        ("now + foo", "Invalid time string 'foo'"),
                        ("now +    2a ", "Invalid time string '2a'")]:
         assert_raises_with_msg(ValueError, msg, parse_time, value)
Esempio n. 3
0
 def test_check_variable_number_of_args(self):
     ap = ArgumentParser('usage:  robot.py [options] args', arg_limits=(1,))
     ap.parse_args(['one_is_ok'])
     ap.parse_args(['two', 'ok'])
     ap.parse_args(['this', 'should', 'also', 'work', '!'])
     assert_raises_with_msg(DataError, "Expected at least 1 argument, got 0.",
                            ap.parse_args, [])
 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")
 def test_zero_argument_is_never_accepted(self):
     class Stubbed(TidyCommandLine):
         def _report_error(self, message, **args):
             raise DataError(message)
     for args in [], ['--inplace'], ['--recursive']:
         assert_raises_with_msg(DataError, 'Expected at least 1 argument, got 0.',
                                Stubbed().execute_cli, args)
Esempio n. 6
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')
 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")
Esempio n. 8
0
 def test_customized_message(self):
     tout = KeywordTimeout('1s', 'My message', VariableMock())
     tout.start()
     tout.run(passing)
     tout.secs = 0.001
     assert_raises_with_msg(TimeoutError, 'My message',
                            tout.run, sleeping, (10,))
Esempio n. 9
0
 def test_assert_almost_equal(self):
     assert_almost_equal(1.0, 1.00000001)
     assert_almost_equal(10, 10.01, 1)
     assert_raises_with_msg(AE, 'hello: 1 != 2 within 3 places',
                            assert_almost_equal, 1, 2, 3, 'hello')
     assert_raises_with_msg(AE, 'hello',
                            assert_almost_equal, 1, 2, 3, 'hello', False)
Esempio n. 10
0
 def test_assert_not_almost_equal(self):
     assert_not_almost_equal(1.0, 1.00000001, 10)
     assert_not_almost_equal(10, 11, 1, 'hello')
     assert_raises_with_msg(AE, 'hello: 1 == 1 within 7 places',
                            assert_not_almost_equal, 1, 1, msg='hello')
     assert_raises_with_msg(AE, 'hi',
                            assert_not_almost_equal, 1, 1.1, 0, 'hi', False)
Esempio n. 11
0
    def test_releasing_lock_fails_when_content_have_been_changed(self):
        self.lock.create_lock(MockDialog(True))
        self.lock.content = "Another user stole the lock."
        msg = """Could not remove lock file. Data edited while you were saving it.
Use "Save As" to save results to some other file
and resolve the conflicts manually."""
        assert_raises_with_msg(LockException, msg, self.lock.release_lock)
Esempio n. 12
0
 def test_with_suites_no_matches(self):
     suite = _get_suite()
     err =  "Suite 'Root' contains no test suites named '%s'."
     assert_raises_with_msg(DataError, err % ('nonex'),
                            suite.filter_by_names, ['nonex'], [])
     assert_raises_with_msg(DataError, err % ('b1.Sub'),
                            suite.filter_by_names, ['b1.Sub'], [])
Esempio n. 13
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')
Esempio n. 14
0
 def test_no_matching_tests_with_one_selector_each(self):
     configurer = SuiteConfigurer(include_tags='i', exclude_tags='e',
                                  include_suites='s', include_tests='t')
     assert_raises_with_msg(DataError,
                            "Suite 'root' contains no tests with tag 'i', "
                            "without tag 'e' and named 't' in suite 's'.",
                            configurer.configure, self.suite)
Esempio n. 15
0
    def test_setting_non_setup_keyword_to_setup_is_not_supported(self):

        kws = Keywords(keywords=[Keyword(type='setup'), Keyword(), Keyword()])
        orig = list(kws)
        assert_raises_with_msg(TypeError,
                               "Setup keyword type must be 'setup', got 'kw'.",
                               setattr, kws, 'setup', Keyword())
        assert_equal(list(kws), orig)
Esempio n. 16
0
 def test_non_absolute(self):
     path = os.listdir('.')[0]
     assert_raises_with_msg(DataError,
         "Importing '%s' failed: Import path must be absolute." % path,
         Importer().import_class_or_module_by_path, path)
     assert_raises_with_msg(DataError,
         "Importing file '%s' failed: Import path must be absolute." % path,
         Importer('file').import_class_or_module_by_path, path)
Esempio n. 17
0
 def test_invalid_format(self):
     path = join(CURDIR, '..', '..', 'README.txt')
     assert_raises_with_msg(DataError,
         "Importing '%s' failed: Not a valid file or directory to import." % path,
         Importer().import_class_or_module_by_path, path)
     assert_raises_with_msg(DataError,
         "Importing xxx '%s' failed: Not a valid file or directory to import." % path,
         Importer('xxx').import_class_or_module_by_path, path)
 def test_setitem_slice(self):
     tests = self.tests[:]
     tests[-1:] = [TestCase(name='b'), TestCase(name='a')]
     assert_equal([t.name for t in tests], ['a', 'b', 'b', 'a'])
     assert_true(all(t.parent is self.suite for t in tests))
     assert_raises_with_msg(TypeError,
                            'Only TestCase objects accepted, got TestSuite.',
                            tests.__setitem__, slice(0), [self.suite])
Esempio n. 19
0
 def test_releasing_lock_fails(self):
     try:
         orig_os_path_exists = lock_module.os.path.exists
         lock_module.os.path.exists = lambda x: True
         msg = """Could not remove lock file. Could not read lock: [Errno 2] No such file or directory: '%s'""" % self.lock_path
         assert_raises_with_msg(LockException, msg, self.lock.release_lock)
     finally:
         lock_module.os.path.exists = orig_os_path_exists
Esempio n. 20
0
 def test_with_suites_and_tests_no_matches(self):
     suite = _get_suite()
     for suites, tests in [ (['Root'], ['nonex']),
                            (['Nonex'], ['T1.1']),
                            (['Sub2'], ['T1.1']), ]:
         msg = ("Suite 'Root' contains no test cases %s in suites %s."
                % (utils.seq2str(tests, lastsep=' or '),
                   utils.seq2str(suites, lastsep=' or ')))
         assert_raises_with_msg(DataError, msg, suite.filter_by_names, suites, tests)
 def _validate(self, inplace=False, recursive=False, format=None,
               spacecount=None, args=['a_file.txt'], error=None):
     opts = {'inplace': inplace, 'recursive': recursive,
             'format': format, 'spacecount': spacecount}
     validate = lambda: TidyCommandLine().validate(opts, args)
     if error:
         assert_raises_with_msg(DataError, error, validate)
     else:
         validate()
Esempio n. 22
0
 def test_reading_lock_fails(self):
     try:
         orig_os_path_exists = lock_module.os.path.exists
         lock_module.os.path.exists = lambda x: True
         msg = "Could not read lock: [Errno 2] No such file or directory: '%s'" % (self.lock_path)
         assert_raises_with_msg(LockException, msg, 
                                self.lock._get_lock_file)
     finally:
         lock_module.os.path.exists = orig_os_path_exists
Esempio n. 23
0
 def test_setting_non_teardown_keyword_to_teardown_is_not_supported(self):
     kws = Keywords(keywords=[Keyword(), Keyword(type='teardown')])
     orig = list(kws)
     assert_raises_with_msg(
         TypeError,
         "Teardown keyword type must be 'teardown', got 'setup'.",
         setattr, kws, 'teardown', Keyword(type='setup')
     )
     assert_equal(list(kws), orig)
Esempio n. 24
0
 def test_import_non_existing_item_from_existing_module(self):
     assert_raises_with_msg(DataError,
                            "Importing 'pythonmodule.NonExisting' failed: "
                            "Module 'pythonmodule' does not contain 'NonExisting'.",
                            self._import, 'pythonmodule.NonExisting')
     assert_raises_with_msg(DataError,
                            "Importing test library 'pythonmodule.none' failed: "
                            "Module 'pythonmodule' does not contain 'none'.",
                            self._import, 'pythonmodule.none', 'test library')
Esempio n. 25
0
 def test_invalid_item_from_existing_module(self):
     assert_raises_with_msg(DataError,
                            "Importing 'pythonmodule.some_string' failed: "
                            "Expected class or module, got <str>.",
                            self._import, 'pythonmodule.some_string')
     assert_raises_with_msg(DataError,
                            "Importing xxx 'pythonmodule.submodule.attribute' failed: "
                            "Expected class or module, got <int>.",
                            self._import, 'pythonmodule.submodule.attribute', 'xxx')
Esempio n. 26
0
 def test_non_existing(self):
     path = 'non-existing.py'
     assert_raises_with_msg(DataError,
         "Importing '%s' failed: File or directory does not exist." % path,
         Importer().import_class_or_module_by_path, path)
     path = abspath(path)
     assert_raises_with_msg(DataError,
         "Importing test file '%s' failed: File or directory does not exist." % path,
         Importer('test file').import_class_or_module_by_path, path)
 def test_assert_equal_with_custom_formatter(self):
     assert_equal(u'hyv\xe4', u'hyv\xe4', formatter=repr)
     assert_raises_with_msg(
         AE, "u'hyv\\xe4' != 'paha'" if PY2 else "'hyv\xe4' != 'paha'",
         assert_equal, u'hyv\xe4', 'paha', formatter=repr
     )
     if PY3:
         assert_raises_with_msg(AE, "'hyv\\xe4' != 'paha'",
                                assert_equal, 'hyv\xe4', 'paha',
                                formatter=ascii)
Esempio n. 28
0
 def test_no_matching_tests_with_multiple_selectors(self):
     configurer = SuiteConfigurer(include_tags=['i1', 'i2'],
                                  exclude_tags=['e1', 'e2'],
                                  include_suites=['s1', 's2', 's3'],
                                  include_tests=['t1', 't2'])
     assert_raises_with_msg(DataError,
                            "Suite 'root' contains no tests with tags 'i1' or 'i2', "
                            "without tags 'e1' or 'e2' and named 't1' or 't2' "
                            "in suites 's1', 's2' or 's3'.",
                            configurer.configure, self.suite)
 def _validate(self, inplace=False, recursive=False, format=None,
               spacecount=None, lineseparator=None, args=[__file__],
               error=None):
     opts = {'inplace': inplace, 'recursive': recursive, 'format': format,
             'spacecount': spacecount, 'lineseparator': lineseparator}
     validate = lambda: TidyCommandLine().validate(opts, args)
     if error:
         assert_raises_with_msg(DataError, error, validate)
     else:
         return validate()
 def test_configure_only_works_with_root_suite(self):
     for Suite in TestSuite, RunningTestSuite, ResultTestSuite:
         root = Suite()
         child = root.suites.create()
         child.tests.create()
         root.configure(name='Configured')
         assert_equal(root.name, 'Configured')
         assert_raises_with_msg(
             ValueError, "'TestSuite.configure()' can only be used with "
             "the root test suite.", child.configure, name='Bang'
         )
Esempio n. 31
0
 def _verify_error(self, in_args, exp_error):
     assert_raises_with_msg(DataError,
                            'Invalid argument specification: ' + exp_error,
                            self._parse, in_args)
Esempio n. 32
0
 def test_using_namespace_when_robot_not_running(self):
     assert_raises_with_msg(RobotNotRunningError,
                            'Cannot access execution context',
                            BuiltIn().get_variables)
Esempio n. 33
0
 def test_unclosed_item(self):
     for inp in ['${x}[0', '${x}[0][key', r'${x}[0\]']:
         msg = "Variable item '%s' was not closed properly." % inp
         assert_raises_with_msg(DataError, msg, search_variable, inp)
         self._test(inp, ignore_errors=True)
     self._test('[${var}[i]][', '${var}', start=1, items='i')
Esempio n. 34
0
 def test_using_namespace_when_robot_not_running_backwards_compatibility(
         self):
     assert_raises_with_msg(AttributeError,
                            'Cannot access execution context',
                            BuiltIn().get_variables)