Changeset 9802ee4 in trunk


Ignore:
Timestamp:
2019-03-07T18:30:29Z (6 years ago)
Author:
Jean-Paul Calderone <exarkun@…>
Branches:
master
Children:
5de4f40
Parents:
f4950cf
Message:

Some basic tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/test/test_eliotutil.py

    rf4950cf r9802ee4  
    2222from testtools.matchers import (
    2323    Is,
     24    IsInstance,
    2425    MatchesStructure,
    2526    Equals,
     
    2930    has_no_result,
    3031    succeeded,
     32    failed,
    3133)
    3234
     
    5658    eliot_friendly_generator_function,
    5759    inline_callbacks,
     60    log_call_deferred,
    5861    _parse_destination_description,
    5962    _EliotLogging,
     
    528531            ),
    529532        )
     533
     534class LogCallDeferredTests(TestCase):
     535    """
     536    Tests for ``log_call_deferred``.
     537    """
     538    @capture_logging(
     539        lambda self, logger:
     540        assertHasAction(self, logger, u"the-action", succeeded=True),
     541    )
     542    def test_return_value(self, logger):
     543        """
     544        The decorated function's return value is passed through.
     545        """
     546        result = object()
     547        @log_call_deferred(action_type=u"the-action")
     548        def f():
     549            return result
     550        self.assertThat(f(), succeeded(Is(result)))
     551
     552    @capture_logging(
     553        lambda self, logger:
     554        assertHasAction(self, logger, u"the-action", succeeded=False),
     555    )
     556    def test_raise_exception(self, logger):
     557        """
     558        An exception raised by the decorated function is passed through.
     559        """
     560        class Result(Exception):
     561            pass
     562        @log_call_deferred(action_type=u"the-action")
     563        def f():
     564            raise Result()
     565        self.assertThat(
     566            f(),
     567            failed(
     568                AfterPreprocessing(
     569                    lambda f: f.value,
     570                    IsInstance(Result),
     571                ),
     572            ),
     573        )
Note: See TracChangeset for help on using the changeset viewer.