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
5
6class SharedState(object):
7  """A class that manages the test state across multiple stories.
8  It's styled on unittest.TestCase for handling test setup & teardown logic.
9
10  """
11
12  def __init__(self, test, options, story_set):
13    """ This method is styled on unittest.TestCase.setUpClass.
14    Override to do any action before running stories that
15    share this same state.
16    Args:
17      test: a page_test.PageTest or story_test.StoryTest instance.
18      options: a BrowserFinderOptions instance that contains command line
19        options.
20      story_set: a story.StorySet instance.
21    """
22    pass
23
24  @property
25  def platform(self):
26    """ Override to return the platform which stories that share this same
27    state will be run on.
28    """
29    raise NotImplementedError()
30
31  def WillRunStory(self, story):
32    """ Override to do any action before running each one of all stories
33    that share this same state.
34    This method is styled on unittest.TestCase.setUp.
35    """
36    raise NotImplementedError()
37
38  def DidRunStory(self, results):
39    """ Override to do any action after running each of all stories that
40    share this same state.
41    This method is styled on unittest.TestCase.tearDown.
42    """
43    raise NotImplementedError()
44
45  def CanRunStory(self, story):
46    """Indicate whether the story can be run in the current configuration.
47    This is called after WillRunStory and before RunStory. Return True
48    if the story should be run, and False if it should be skipped.
49    Most subclasses will probably want to override this to always
50    return True.
51    Args:
52      story: a story.Story instance.
53    """
54    raise NotImplementedError()
55
56  def RunStory(self, results):
57    """ Override to do any action before running each one of all stories
58    that share this same state.
59    This method is styled on unittest.TestCase.run.
60    """
61    raise NotImplementedError()
62
63  def TearDownState(self):
64    """ Override to do any action after running multiple stories that
65    share this same state.
66    This method is styled on unittest.TestCase.tearDownClass.
67    """
68    raise NotImplementedError()
69