def test_parent(self): # The parent can be retrieved from a child context. parent = TagContext() parent.change_tags({'foo'}, set()) child = TagContext(parent) child.change_tags(set(), {'foo'}) self.assertEqual(parent, child.parent)
def test_child_context(self): # A TagContext can have a parent. If so, its tags are the tags of the # parent at the moment of construction. parent = TagContext() parent.change_tags(set(['foo']), set()) child = TagContext(parent) self.assertEqual(parent.get_current_tags(), child.get_current_tags())
def test_add_to_child(self): # Adding a tag to the child context doesn't affect the parent. parent = TagContext() parent.change_tags({'foo'}, set()) child = TagContext(parent) child.change_tags({'bar'}, set()) self.assertEqual({'foo', 'bar'}, child.get_current_tags()) self.assertEqual({'foo'}, parent.get_current_tags())
def test_remove_in_child(self): # A tag that was in the parent context can be removed from the child # context without affect the parent. parent = TagContext() parent.change_tags({'foo'}, set()) child = TagContext(parent) child.change_tags(set(), {'foo'}) self.assertEqual(set(), child.get_current_tags()) self.assertEqual({'foo'}, parent.get_current_tags())
def test_add_tag_twice(self): # Calling change_tags twice to add tags adds both tags to the current # tags. tag_context = TagContext() tag_context.change_tags(set(['foo']), set()) tag_context.change_tags(set(['bar']), set()) self.assertEqual(set(['foo', 'bar']), tag_context.get_current_tags())
def startTestRun(self): """Called before a test run starts. New in Python 2.7. The testtools version resets the result to a pristine condition ready for use in another test run. Note that this is different from Python 2.7's startTestRun, which does nothing. """ # failfast is reset by the super __init__, so stash it. failfast = self.failfast super(TestResult, self).__init__() self.skip_reasons = {} self.__now = None self._tags = TagContext() # -- Start: As per python 2.7 -- self.expectedFailures = [] self.unexpectedSuccesses = [] self.failfast = failfast
def test_remove_tag(self): # change_tags can remove tags from the context. tag_context = TagContext() tag_context.change_tags({'foo'}, set()) tag_context.change_tags(set(), {'foo'}) self.assertEqual(set(), tag_context.get_current_tags())
def test_change_tags_returns_tags(self): # change_tags returns the current tags. This is a convenience. tag_context = TagContext() tags = tag_context.change_tags({'foo'}, set()) self.assertEqual({'foo'}, tags)
def test_add_tag(self): # A tag added with change_tags appears in get_current_tags. tag_context = TagContext() tag_context.change_tags({'foo'}, set()) self.assertEqual({'foo'}, tag_context.get_current_tags())
def __init__(self, decorated): self.decorated = decorated self._tags = TagContext() # Only used for old TestResults that do not have failfast. self._failfast = False
def startTest(self, test): super(ExtendedTestResult, self).startTest(test) self._tags = TagContext(self._tags)
def __init__(self, event_log=None): super().__init__(event_log) self._tags = TagContext()
def startTest(self, test): super().startTest(test) self._tags = TagContext(self._tags)
def startTestRun(self): super().startTestRun() self._was_successful = True self._tags = TagContext()
def startTestRun(self): self._tags = TagContext() try: return self.decorated.startTestRun() except AttributeError: return
def startTest(self, test): self._tags = TagContext(self._tags) return self.decorated.startTest(test)
def startTestRun(self): super(ExtendedTestResult, self).startTestRun() self._was_successful = True self._tags = TagContext()
def __init__(self): super(ExtendedTestResult, self).__init__() self._tags = TagContext()
def __init__(self, event_log=None): super(ExtendedTestResult, self).__init__(event_log) self._tags = TagContext()
def test_no_tags(self): # A tag context has no tags initially. tag_context = TagContext() self.assertEqual(set(), tag_context.get_current_tags())