• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2014 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5from py_trace_event import trace_event
6
7
8class SharedState(object):
9  """A class that manages the test state across multiple stories.
10  It's styled on unittest.TestCase for handling test setup & teardown logic.
11
12  """
13
14  __metaclass__ = trace_event.TracedMetaClass
15
16  def __init__(self, test, options, story_set):
17    """ This method is styled on unittest.TestCase.setUpClass.
18    Override to do any action before running stories that
19    share this same state.
20    Args:
21      test: a legacy_page_test.LegacyPageTest or story_test.StoryTest instance.
22      options: a BrowserFinderOptions instance that contains command line
23        options.
24      story_set: a story.StorySet instance.
25    """
26    pass
27
28  @property
29  def platform(self):
30    """ Override to return the platform which stories that share this same
31    state will be run on.
32    """
33    raise NotImplementedError()
34
35  def WillRunStory(self, story):
36    """ Override to do any action before running each one of all stories
37    that share this same state.
38    This method is styled on unittest.TestCase.setUp.
39    """
40    raise NotImplementedError()
41
42  def DidRunStory(self, results):
43    """ Override to do any action after running each of all stories that
44    share this same state.
45    This method is styled on unittest.TestCase.tearDown.
46    """
47    raise NotImplementedError()
48
49  def CanRunStory(self, story):
50    """Indicate whether the story can be run in the current configuration.
51    This is called after WillRunStory and before RunStory. Return True
52    if the story should be run, and False if it should be skipped.
53    Most subclasses will probably want to override this to always
54    return True.
55    Args:
56      story: a story.Story instance.
57    """
58    raise NotImplementedError()
59
60  def RunStory(self, results):
61    """ Override to do any action before running each one of all stories
62    that share this same state.
63    This method is styled on unittest.TestCase.run.
64    """
65    raise NotImplementedError()
66
67  def TearDownState(self):
68    """ Override to do any action after running multiple stories that
69    share this same state.
70    This method is styled on unittest.TestCase.tearDownClass.
71    """
72    raise NotImplementedError()
73
74  def DumpStateUponFailure(self, story, results):
75    """ Dump the state upon failure.
76    This method tries to dump as much information about the application under
77    test as possible (output, log, screenshot, etc.) to simplify triaging the
78    failure.
79    """
80    raise NotImplementedError()
81