def test_invalid_line(self):
     self.tmpfile.write('justkey\n')
     self.tmpfile.flush()
     assert_raises(
             errors.ConfigurationError,
             loader.PropertiesConfiguration,
             self.tmpfile.name)
 def test_read_config_failed(self):
     self.namespace.get.return_value = proxy.UndefToken
     assert_raises(
             errors.ConfigurationError,
             readers._read_config,
             'some_key',
             self.namespace,
             None)
 def test_xml_configuration_safe_value_tag(self):
     content = """
         <config>
             <sometag value="snazz">E</sometag>
         </config>
     """
     self.write_content_to_file(content)
     assert_raises(errors.ConfigurationError, loader.XMLConfiguration, self.tmpfile.name, safe=True)
Beispiel #4
0
 def test_callable_is_called_with_all_arguments(self):
     class GoodArguments(Exception): pass
     arg1, arg2, kwarg = object(), object(), object()
     def check_arguments(*args, **kwargs):
         assert_equal((arg1, arg2), args)
         assert_equal({'kwarg': kwarg}, kwargs)
         raise GoodArguments
     assertions.assert_raises(GoodArguments, check_arguments, arg1, arg2, kwarg=kwarg)
Beispiel #5
0
 def test_fails_when_exception_is_not_raised(self):
     raises_nothing = lambda: None
     try:
         assertions.assert_raises(ValueError, raises_nothing)
     except AssertionError:
         pass
     else:
         assert_not_reached('AssertionError should have been raised')
Beispiel #6
0
 def test_fails_when_exception_is_not_raised(self):
     raises_nothing = lambda: None
     try:
         assertions.assert_raises(ValueError, raises_nothing)
     except AssertionError:
         pass
     else:
         assert_not_reached('AssertionError should have been raised')
    def test_build_loader_optional(self):
        err_msg = "Failed to do"
        loader_func = mock.Mock()
        loader_func.side_effect = ValueError(err_msg)
        config_loader = loader.build_loader(loader_func)

        config_loader(optional=True)
        assert_raises(ValueError, config_loader)
    def test_build_loader_optional(self):
        err_msg = "Failed to do"
        loader_func = mock.Mock()
        loader_func.side_effect = ValueError(err_msg)
        config_loader = loader.build_loader(loader_func)

        config_loader(optional=True)
        assert_raises(ValueError, config_loader)
Beispiel #9
0
 def test_fails_when_wrong_exception_is_raised(self):
     def raises_value_error():
         raise ValueError
     try:
         assertions.assert_raises(MyException, raises_value_error)
     except ValueError:
         pass
     else:
         assert_not_reached('ValueError should have been raised')
 def test_xml_configuration_safe_override(self):
     content = """
         <config>
             <sometag foo="bar">
                 <foo>E</foo>
             </sometag>
         </config>
     """
     self.write_content_to_file(content)
     assert_raises(errors.ConfigurationError, loader.XMLConfiguration, self.tmpfile.name, safe=True)
Beispiel #11
0
    def test_fails_when_wrong_exception_is_raised(self):
        def raises_value_error():
            raise ValueError

        try:
            assertions.assert_raises(MyException, raises_value_error)
        except ValueError:
            pass
        else:
            assert_not_reached('ValueError should have been raised')
 def test_xml_configuration_safe_value_tag(self):
     content = """
         <config>
             <sometag value="snazz">E</sometag>
         </config>
     """
     self.write_content_to_file(content)
     assert_raises(errors.ConfigurationError,
                   loader.XMLConfiguration,
                   self.tmpfile.name,
                   safe=True)
 def test_xml_configuration_safe_override(self):
     content = """
         <config>
             <sometag foo="bar">
                 <foo>E</foo>
             </sometag>
         </config>
     """
     self.write_content_to_file(content)
     assert_raises(errors.ConfigurationError,
                   loader.XMLConfiguration,
                   self.tmpfile.name,
                   safe=True)
Beispiel #14
0
    def test_no_vars(self):
        """
        To allocate a .__dict__ attribute of this object means that we're
        allocating a second, mutable dictionary as part of our frozendict.
        This would be a waste of memory as well as yielding pretty nonsensical
        semantics wrt immutability.
        """
        fd = fdict(a=1)
        with T.assert_raises(TypeError):
            vars(fd)

        with T.assert_raises(AttributeError):
            fd.__dict__
Beispiel #15
0
 def test_parse_test_runner_command_line_args_no_test_path(self):
     """Make sure that if no options and no arguments are passed,
     parse_test_runner_command_line_args DOES complain about a missing test
     path.
     """
     with assert_raises(OptionParserErrorException):
         test_program.parse_test_runner_command_line_args([], [])
Beispiel #16
0
    def perform_exception_test(self, exc_class):
        self.expected_reference_counts = self.get_reference_counts()
        for _ in xrange(self.num_stress_test_iterations + 1):
            # there's a fun wrinkle here. we have to make sure the raised exception
            # is completely out of scope and destroyed before we check the reference
            # counts again; otherwise it may hold incidental references to objects,
            # which will appear to the reference count checks here as though it were
            # a memory leak. not that this, you know, actually happened to me or anything.
            assert_raises(exc_class, self.run_templating)
            assert_equal(self.get_reference_counts(), self.expected_reference_counts)

        try:
            self.run_templating()
        except exc_class, e:
            # now that we're done counting references, save the exception for examination:
            self.exception = e
Beispiel #17
0
 def test_fails_when_exception_test_fails(self):
     """Tests that when an exception of the right type that fails the
     passed in exception test is raised, the assertion fails."""
     has_two_args = lambda e: assertions.assert_length(e.args, 2)
     with assertions.assert_raises(AssertionError):
         with assertions.assert_raises_such_that(Exception, has_two_args):
             raise Exception("only one argument")
Beispiel #18
0
 def test_fails_when_no_exception_is_raised(self):
     """Tests that the assertion fails when no exception is raised."""
     def exists(e):
         return True
     with assertions.assert_raises(AssertionError):
         with assertions.assert_raises_such_that(Exception, exists):
             pass
Beispiel #19
0
 def test_parse_test_runner_command_line_args_no_test_path(self):
     """Make sure that if no options and no arguments are passed,
     parse_test_runner_command_line_args DOES complain about a missing test
     path.
     """
     with assert_raises(OptionParserErrorException):
         test_program.parse_test_runner_command_line_args([], [])
Beispiel #20
0
    def test_unexpected_exception_passes_through(self):
        class DifferentException(Exception):
            pass

        with assertions.assert_raises(DifferentException):
            with assertions.assert_raises_exactly(self.MyException, "first", "second"):
                raise DifferentException("first", "second")
Beispiel #21
0
    def test_callable_is_called_with_all_arguments(self):
        class GoodArguments(Exception):
            pass

        arg1, arg2, kwarg = object(), object(), object()

        def check_arguments(*args, **kwargs):
            assert_equal((arg1, arg2), args)
            assert_equal({'kwarg': kwarg}, kwargs)
            raise GoodArguments

        assertions.assert_raises(GoodArguments,
                                 check_arguments,
                                 arg1,
                                 arg2,
                                 kwarg=kwarg)
Beispiel #22
0
 def test_fails_when_exception_test_fails(self):
     """Tests that when an exception of the right type that fails the
     passed in exception test is raised, the assertion fails."""
     has_two_args = lambda e: assertions.assert_length(e.args, 2)
     with assertions.assert_raises(AssertionError):
         with assertions.assert_raises_such_that(Exception, has_two_args):
             raise Exception("only one argument")
Beispiel #23
0
 def test_fails_when_incorrect_warning_with_callable(self):
     """
     Test that assert_warns fails when we pass a specific warning and
     a different warning class is thrown.
     """
     with assertions.assert_raises(AssertionError):
         assertions.assert_warns(DeprecationWarning, self._create_user_warning)
Beispiel #24
0
    def test_fails_with_different_class(self):
        class SpecialException(self.MyException):
            pass

        with assertions.assert_raises(AssertionError):
            with assertions.assert_raises_exactly(self.MyException, "first", "second"):
                raise SpecialException("first", "second")
Beispiel #25
0
 def test_fails_when_incorrect_warning_with_callable(self):
     """
     Test that assert_warns fails when we pass a specific warning and
     a different warning class is thrown.
     """
     with assertions.assert_raises(AssertionError):
         assertions.assert_warns(DeprecationWarning,
                                 self._create_user_warning)
Beispiel #26
0
 def test_fails_when_warnings_test_raises_exception(self):
     """
     Test that assert_warns_such_that (used as a context manager)
     fails when the warnings_test method raises an exception.
     """
     with assertions.assert_raises(RuntimeError):
         with assertions.assert_warns_such_that(self._raise_exception):
             self._create_user_warning()
Beispiel #27
0
 def test_fails_when_warnings_test_raises_exception_with_callable(self):
     """
     Test that assert_warns_such_that (when given a callable object)
     fails when the warnings_test method raises an exception.
     """
     with assertions.assert_raises(RuntimeError):
         assertions.assert_warns_such_that(self._raise_exception,
                                           self._create_user_warning)
Beispiel #28
0
 def test_fails_when_warnings_test_raises_exception(self):
     """
     Test that assert_warns_such_that (used as a context manager)
     fails when the warnings_test method raises an exception.
     """
     with assertions.assert_raises(RuntimeError):
         with assertions.assert_warns_such_that(self._raise_exception):
             self._create_user_warning()
Beispiel #29
0
    def test_unexpected_exception_passes_through(self):
        class DifferentException(Exception):
            pass

        with assertions.assert_raises(DifferentException):
            with assertions.assert_raises_exactly(self.MyException, "first",
                                                  "second"):
                raise DifferentException("first", "second")
Beispiel #30
0
    def test_fails_with_different_class(self):
        class SpecialException(self.MyException):
            pass

        with assertions.assert_raises(AssertionError):
            with assertions.assert_raises_exactly(self.MyException, "first",
                                                  "second"):
                raise SpecialException("first", "second")
Beispiel #31
0
    def test_fails_when_no_warning_with_callable(self):
        """Test that assert_warns fails when there is no warning thrown."""
        with assertions.assert_raises(AssertionError):

            def do_nothing():
                pass

            assertions.assert_warns(UserWarning, do_nothing)
Beispiel #32
0
    def test_fails_on_unyielding_generator(self):
        """Test that assert_not_empty fails on an 'empty' generator."""
        def yield_nothing():
            if False:
                yield 0

        with assertions.assert_raises(AssertionError):
            assertions.assert_not_empty(yield_nothing())
Beispiel #33
0
    def test_fails_on_infinite_generator(self):
        """Tests that assert_empty fails on an infinite generator."""
        def yes():
            while True:
                yield 'y'

        with assertions.assert_raises(AssertionError):
            assertions.assert_empty(yes())
Beispiel #34
0
    def test_fails_when_no_exception_is_raised(self):
        """Tests that the assertion fails when no exception is raised."""
        def exists(e):
            return True

        with assertions.assert_raises(AssertionError):
            with assertions.assert_raises_such_that(Exception, exists):
                pass
Beispiel #35
0
    def test_fails_on_unyielding_generator(self):
        """Test that assert_not_empty fails on an 'empty' generator."""
        def yield_nothing():
            if False:
                yield 0

        with assertions.assert_raises(AssertionError):
            assertions.assert_not_empty(yield_nothing())
Beispiel #36
0
    def test_fails_on_infinite_generator(self):
        """Tests that assert_empty fails on an infinite generator."""
        def yes():
            while True:
                yield 'y'

        with assertions.assert_raises(AssertionError):
            assertions.assert_empty(yes())
Beispiel #37
0
 def test_fails_when_warnings_test_raises_exception_with_callable(self):
     """
     Test that assert_warns_such_that (when given a callable object)
     fails when the warnings_test method raises an exception.
     """
     with assertions.assert_raises(RuntimeError):
         assertions.assert_warns_such_that(self._raise_exception,
                                           self._create_user_warning)
Beispiel #38
0
 def test_fails_when_wrong_exception_is_raised(self):
     """Tests that when an unexpected exception is raised, that it is
     passed through and the assertion fails."""
     exists = lambda e: True
     # note: in assert_raises*, if the exception raised is not of the
     # expected type, that exception just falls through
     with assertions.assert_raises(Exception):
         with assertions.assert_raises_such_that(AssertionError, exists):
             raise Exception("the wrong exception")
Beispiel #39
0
 def test_fails_when_wrong_exception_is_raised(self):
     """Tests that when an unexpected exception is raised, that it is
     passed through and the assertion fails."""
     exists = lambda e: True
     # note: in assert_raises*, if the exception raised is not of the
     # expected type, that exception just falls through
     with assertions.assert_raises(Exception):
         with assertions.assert_raises_such_that(AssertionError, exists):
             raise Exception("the wrong exception")
 def test_validate_all_fails(self):
     name = 'yan'
     _ = staticconf.get_string('foo', namespace=name)
     assert_raises(errors.ConfigurationError,
                   config.validate,
                   all_names=True)
 def test_validate_keys_unknown_raise(self):
     assert_raises(errors.ConfigurationError, self.namespace.validate_keys,
                   self.config_data, True)
 def test_validate_single_fails(self):
     _ = staticconf.get_int('one.two')
     assert_raises(errors.ConfigurationError, config.validate)
Beispiel #43
0
 def test_fails_on_empty_list(self):
     """Test that assert_not_empty fails on an empty list."""
     with assertions.assert_raises(AssertionError):
         assertions.assert_not_empty([])
Beispiel #44
0
 def assert_raises_an_exception_and_raise_another():
     with assertions.assert_raises(MyException):
         raise ValueError
Beispiel #45
0
 def test_run_testify_with_failure(self):
     assert_raises(
         subprocess.CalledProcessError, test_call, ["python", "testing_suite/example_test.py", "DoesNotExist"]
     )
Beispiel #46
0
 def test(self):
     assert_raises(KeyError, self.run_templating)
Beispiel #47
0
 def test_failure_on_interrupt(self):
     with assert_raises(subprocess.CalledProcessError):
         test_call([
             sys.executable, '-m', 'testify.test_program',
             'test.failing_test_interrupt'
         ])
 def test_has_duplicate_keys_raises(self):
     config_data = dict(fear=123)
     assert_raises(errors.ConfigurationError, config.has_duplicate_keys,
                   config_data, self.base_conf, True)
Beispiel #49
0
 def test_passes_when_exception_is_raised(self):
     def raises_value_error():
         raise ValueError
     assertions.assert_raises(ValueError, raises_value_error)
Beispiel #50
0
 def test__getattr__missing_attribute(self):
     assert_raises(AttributeError,
         self.action_run.__getattr__, 'is_not_a_real_state')
Beispiel #51
0
    def test_passes_when_exception_is_raised(self):
        def raises_value_error():
            raise ValueError

        assertions.assert_raises(ValueError, raises_value_error)
Beispiel #52
0
 def test_run_testify_with_failure(self):
     assert_raises(
         subprocess.CalledProcessError, test_call,
         [sys.executable, 'testing_suite/example_test.py', 'DoesNotExist'])
 def test_get_value_fails_validation(self):
     validator = mock.Mock()
     validator.side_effect = validation.ValidationError()
     value_proxy = proxy.ValueProxy(validator, self.value_cache, 'something.broken')
     assert_raises(errors.ConfigurationError, lambda: value_proxy + 1)
Beispiel #54
0
    def test_fails_with_wrong_value(self):
        superset = {'one': 1, 'two': 2, 'three': 3}
        subset = {'one': 2}

        assertions.assert_raises(AssertionError, assert_dict_subset, superset,
                                 subset)
Beispiel #55
0
 def test_failure_on_interrupt(self):
     with assert_raises(subprocess.CalledProcessError):
         test_call([sys.executable, "-m", "testify.test_program", "test.failing_test_interrupt"])
 def test_get_value_unset(self):
     validator = mock.Mock()
     value_proxy = proxy.ValueProxy(validator, self.value_cache, 'something.missing')
     assert_raises(errors.ConfigurationError, lambda: value_proxy + 1)
Beispiel #57
0
 def exception_should_be_raised():
     with assertions.assert_raises(MyException):
         raise MyException
Beispiel #58
0
 def test_run_testify_with_failure(self):
     assert_raises(
             subprocess.CalledProcessError,
             test_call,
             ['python', 'testing_suite/example_test.py', 'DoesNotExist'])
Beispiel #59
0
 def assert_raises_an_exception_and_raise_another():
     with assertions.assert_raises(MyException):
         raise ValueError