0

Move user_story.shared_user_story_state to story.shared_state

BUG=465594

Review URL: https://codereview.chromium.org/1108993004

Cr-Commit-Position: refs/heads/master@{#327596}
This commit is contained in:
aiolos
2015-04-29 15:06:51 -07:00
committed by Commit bot
parent 33e9207baf
commit 6d62551b30
14 changed files with 80 additions and 80 deletions

@ -10,9 +10,9 @@ from telemetry.core import browser_options
from telemetry import page
from telemetry.page import page_test
from telemetry.page import shared_page_state
from telemetry.story import shared_state
from telemetry import user_story
from telemetry.user_story import android
from telemetry.user_story import shared_user_story_state
from telemetry.user_story import user_story_runner
from telemetry.user_story import user_story_set as user_story_set_module
from telemetry.web_perf import timeline_based_measurement
@ -40,14 +40,14 @@ class BenchmarkTest(unittest.TestCase):
def testPageTestWithIncompatibleUserStory(self):
b = TestBenchmark(user_story.UserStory(
shared_user_story_state_class=shared_page_state.SharedPageState))
shared_state_class=shared_page_state.SharedPageState))
with self.assertRaisesRegexp(
Exception, 'containing only telemetry.page.Page user stories'):
b.Run(browser_options.BrowserFinderOptions())
state_class = shared_user_story_state.SharedUserStoryState
state_class = shared_state.SharedState
b = TestBenchmark(user_story.UserStory(
shared_user_story_state_class=state_class))
shared_state_class=state_class))
with self.assertRaisesRegexp(
Exception, 'containing only telemetry.page.Page user stories'):
b.Run(browser_options.BrowserFinderOptions())

@ -14,7 +14,7 @@ from telemetry.core import util
from telemetry.core import wpr_modes
from telemetry import decorators
from telemetry.page import page_test
from telemetry.user_story import shared_user_story_state
from telemetry.story import shared_state
from telemetry.util import exception_formatter
from telemetry.util import file_handle
from telemetry.value import skip
@ -32,7 +32,7 @@ def _PrepareFinderOptions(finder_options, test, device_type):
profiler_class.CustomizeBrowserOptions(browser_options.browser_type,
finder_options)
class SharedPageState(shared_user_story_state.SharedUserStoryState):
class SharedPageState(shared_state.SharedState):
_device_type = None

@ -76,7 +76,7 @@ class SharedPageStateTests(unittest.TestCase):
test = DummyTest()
uss = user_story_set.UserStorySet()
uss.AddUserStory(us)
us.shared_user_story_state_class(test, self.options, uss)
us.shared_state_class(test, self.options, uss)
browser_options = self.options.browser_options
actual_user_agent = browser_options.browser_user_agent_type
self.assertEqual(expected_user_agent, actual_user_agent)

@ -5,8 +5,8 @@
import unittest
from telemetry.results import user_story_run
from telemetry.story import shared_state
from telemetry import user_story as user_story_module
from telemetry.user_story import shared_user_story_state
from telemetry.user_story import user_story_set
from telemetry.value import failure
from telemetry.value import scalar
@ -14,13 +14,13 @@ from telemetry.value import skip
# pylint: disable=abstract-method
class SharedUserStoryStateBar(shared_user_story_state.SharedUserStoryState):
class SharedStateBar(shared_state.SharedState):
pass
class UserStoryFoo(user_story_module.UserStory):
def __init__(self, name='', labels=None):
super(UserStoryFoo, self).__init__(
SharedUserStoryStateBar, name, labels)
SharedStateBar, name, labels)
class UserStoryRunTest(unittest.TestCase):
def setUp(self):

@ -3,7 +3,7 @@
# found in the LICENSE file.
class SharedUserStoryState(object):
class SharedState(object):
"""A class that manages the test state across multiple user stories.
It's styled on unittest.TestCase for handling test setup & teardown logic.

@ -114,14 +114,14 @@ class PageSetSmokeTest(unittest.TestCase):
def CheckSharedStates(self, page_set):
if not page_set.allow_mixed_story_states:
shared_user_story_state_class = (
page_set.user_stories[0].shared_user_story_state_class)
shared_state_class = (
page_set.user_stories[0].shared_state_class)
for p in page_set:
self.assertIs(
shared_user_story_state_class,
p.shared_user_story_state_class,
msg='page %s\'s shared_user_story_state_class field is different '
'from other pages\'s shared_user_story_state_class whereas '
shared_state_class,
p.shared_state_class,
msg='page %s\'s shared_state_class field is different '
'from other pages\'s shared_state_class whereas '
'page set %s disallow having mixed states' %
(p, page_set))

@ -3,7 +3,7 @@
# found in the LICENSE file.
import re
from telemetry.user_story import shared_user_story_state
from telemetry.story import shared_state
_next_user_story_id = 0
@ -13,12 +13,12 @@ class UserStory(object):
Test should override Run to maybe start the application and perform actions
onto it. To share state between different tests, one can define a
shared_user_story_state which contains hooks that will be called before &
shared_state which contains hooks that will be called before &
after mutiple user stories run and in between runs.
Args:
shared_user_story_state_class: subclass of
telemetry.user_story.shared_user_story_state.SharedUserStoryState.
shared_state_class: subclass of
telemetry.user_story.shared_state.SharedState.
name: string name of this user story that can be used for identifying user
story in results output.
labels: A list or set of string labels that are used for filtering. See
@ -26,7 +26,7 @@ class UserStory(object):
is_local: If true, the user story does not require network.
"""
def __init__(self, shared_user_story_state_class, name='', labels=None,
def __init__(self, shared_state_class, name='', labels=None,
is_local=False, make_javascript_deterministic=True):
"""
Args:
@ -38,9 +38,9 @@ class UserStory(object):
not text/html. See also: _InjectScripts method in
third_party/webpagereplay/httpclient.py.
"""
assert issubclass(shared_user_story_state_class,
shared_user_story_state.SharedUserStoryState)
self._shared_user_story_state_class = shared_user_story_state_class
assert issubclass(shared_state_class,
shared_state.SharedState)
self._shared_state_class = shared_state_class
self._name = name
global _next_user_story_id
self._id = _next_user_story_id
@ -60,8 +60,8 @@ class UserStory(object):
return self._labels
@property
def shared_user_story_state_class(self):
return self._shared_user_story_state_class
def shared_state_class(self):
return self._shared_state_class
@property
def id(self):

@ -23,6 +23,6 @@ class AppStory(user_story.UserStory):
self.start_intent = start_intent
self.is_app_ready_predicate = is_app_ready_predicate
def Run(self, shared_user_story_state):
def Run(self, shared_state):
"""Execute the interactions with the applications."""
raise NotImplementedError

@ -4,11 +4,11 @@
from telemetry.core import platform
from telemetry.core.platform import android_device
from telemetry.core.platform import android_platform
from telemetry.user_story import shared_user_story_state
from telemetry.story import shared_state
from telemetry.web_perf import timeline_based_measurement
class SharedAppState(shared_user_story_state.SharedUserStoryState):
class SharedAppState(shared_state.SharedState):
"""Manage test state/transitions across multiple android.UserStory's.
WARNING: the class is not ready for public consumption.

@ -112,27 +112,27 @@ def _RunUserStoryAndProcessErrorIfNeeded(expectations, user_story, results,
msg='Exception from DidRunUserStory: ')
class UserStoryGroup(object):
def __init__(self, shared_user_story_state_class):
self._shared_user_story_state_class = shared_user_story_state_class
def __init__(self, shared_state_class):
self._shared_state_class = shared_state_class
self._user_stories = []
@property
def shared_user_story_state_class(self):
return self._shared_user_story_state_class
def shared_state_class(self):
return self._shared_state_class
@property
def user_stories(self):
return self._user_stories
def AddUserStory(self, user_story):
assert (user_story.shared_user_story_state_class is
self._shared_user_story_state_class)
assert (user_story.shared_state_class is
self._shared_state_class)
self._user_stories.append(user_story)
def StoriesGroupedByStateClass(user_story_set, allow_multiple_groups):
""" Returns a list of user story groups which each contains user stories with
the same shared_user_story_state_class.
the same shared_state_class.
Example:
Assume A1, A2, A3 are user stories with same shared user story class, and
@ -148,20 +148,20 @@ def StoriesGroupedByStateClass(user_story_set, allow_multiple_groups):
"""
user_story_groups = []
user_story_groups.append(
UserStoryGroup(user_story_set[0].shared_user_story_state_class))
UserStoryGroup(user_story_set[0].shared_state_class))
for user_story in user_story_set:
if (user_story.shared_user_story_state_class is not
user_story_groups[-1].shared_user_story_state_class):
if (user_story.shared_state_class is not
user_story_groups[-1].shared_state_class):
if not allow_multiple_groups:
raise ValueError('This UserStorySet is only allowed to have one '
'SharedUserStoryState but contains the following '
'SharedUserStoryState classes: %s, %s.\n Either '
'remove the extra SharedUserStoryStates or override '
'SharedState but contains the following '
'SharedState classes: %s, %s.\n Either '
'remove the extra SharedStates or override '
'allow_mixed_story_states.' % (
user_story_groups[-1].shared_user_story_state_class,
user_story.shared_user_story_state_class))
user_story_groups[-1].shared_state_class,
user_story.shared_state_class))
user_story_groups.append(
UserStoryGroup(user_story.shared_user_story_state_class))
UserStoryGroup(user_story.shared_state_class))
user_story_groups[-1].AddUserStory(user_story)
return user_story_groups
@ -208,7 +208,7 @@ def Run(test, user_story_set, expectations, finder_options, results,
for user_story in group.user_stories:
for _ in xrange(finder_options.page_repeat):
if not state:
state = group.shared_user_story_state_class(
state = group.shared_state_class(
test, finder_options, user_story_set)
results.WillRunPage(user_story)
try:

@ -12,10 +12,10 @@ from telemetry.page import page as page_module
from telemetry.page import page_test
from telemetry.page import test_expectations
from telemetry.results import results_options
from telemetry.story import shared_state
from telemetry.unittest_util import options_for_unittests
from telemetry.unittest_util import system_stub
from telemetry import user_story
from telemetry.user_story import shared_user_story_state
from telemetry.user_story import user_story_runner
from telemetry.user_story import user_story_set
from telemetry.util import cloud_storage
@ -33,7 +33,7 @@ class FakePlatform(object):
return False
class TestSharedUserStoryState(shared_user_story_state.SharedUserStoryState):
class TestSharedState(shared_state.SharedState):
_platform = FakePlatform()
@ -42,7 +42,7 @@ class TestSharedUserStoryState(shared_user_story_state.SharedUserStoryState):
cls._platform = platform
def __init__(self, test, options, user_story_setz):
super(TestSharedUserStoryState, self).__init__(
super(TestSharedState, self).__init__(
test, options, user_story_setz)
self._test = test
self._current_user_story = None
@ -67,7 +67,7 @@ class TestSharedUserStoryState(shared_user_story_state.SharedUserStoryState):
pass
class TestSharedPageState(TestSharedUserStoryState):
class TestSharedPageState(TestSharedState):
def RunUserStory(self, results):
self._test.RunPage(self._current_user_story, None, results)
@ -94,9 +94,9 @@ class EmptyMetadataForTest(benchmark.BenchmarkMetadata):
class DummyLocalUserStory(user_story.UserStory):
def __init__(self, shared_user_story_state_class, name=''):
def __init__(self, shared_state_class, name=''):
super(DummyLocalUserStory, self).__init__(
shared_user_story_state_class, name=name)
shared_state_class, name=name)
@property
def is_local(self):
@ -171,7 +171,7 @@ class UserStoryRunnerTest(unittest.TestCase):
FooUserStoryState, FooUserStoryState]
mixed_states = [FooUserStoryState, FooUserStoryState, FooUserStoryState,
BarUserStoryState, FooUserStoryState]
# UserStorySet's are only allowed to have one SharedUserStoryState.
# UserStorySet's are only allowed to have one SharedState.
us = SetupUserStorySet(False, foo_states)
story_groups = (
user_story_runner.StoriesGroupedByStateClass(
@ -182,17 +182,17 @@ class UserStoryRunnerTest(unittest.TestCase):
ValueError,
user_story_runner.StoriesGroupedByStateClass,
us, False)
# BaseUserStorySets are allowed to have multiple SharedUserStoryStates.
# BaseUserStorySets are allowed to have multiple SharedStates.
bus = SetupUserStorySet(True, mixed_states)
story_groups = (
user_story_runner.StoriesGroupedByStateClass(
bus, True))
self.assertEqual(len(story_groups), 3)
self.assertEqual(story_groups[0].shared_user_story_state_class,
self.assertEqual(story_groups[0].shared_state_class,
FooUserStoryState)
self.assertEqual(story_groups[1].shared_user_story_state_class,
self.assertEqual(story_groups[1].shared_state_class,
BarUserStoryState)
self.assertEqual(story_groups[2].shared_user_story_state_class,
self.assertEqual(story_groups[2].shared_state_class,
FooUserStoryState)
def RunUserStoryTest(self, us, expected_successes):
@ -223,7 +223,7 @@ class UserStoryRunnerTest(unittest.TestCase):
Any PageTest related calls or attributes need to only be called
for PageTest tests.
"""
class TestSharedTbmState(TestSharedUserStoryState):
class TestSharedTbmState(TestSharedState):
def RunUserStory(self, results):
pass
@ -366,7 +366,7 @@ class UserStoryRunnerTest(unittest.TestCase):
class DidRunTestError(Exception):
pass
class TestTearDownSharedUserStoryState(TestSharedPageState):
class TestTearDownSharedState(TestSharedPageState):
def TearDownState(self, results):
self._test.DidRunTest('app', results)
@ -390,8 +390,8 @@ class UserStoryRunnerTest(unittest.TestCase):
self._unit_test_events.append('did-run-test')
raise DidRunTestError
us.AddUserStory(DummyLocalUserStory(TestTearDownSharedUserStoryState))
us.AddUserStory(DummyLocalUserStory(TestTearDownSharedUserStoryState))
us.AddUserStory(DummyLocalUserStory(TestTearDownSharedState))
us.AddUserStory(DummyLocalUserStory(TestTearDownSharedState))
test = Test()
with self.assertRaises(DidRunTestError):
@ -491,8 +491,8 @@ class UserStoryRunnerTest(unittest.TestCase):
def _testMaxFailuresOptionIsRespectedAndOverridable(
self, num_failing_user_stories, runner_max_failures, options_max_failures,
expected_num_failures):
class SimpleSharedUserStoryState(
shared_user_story_state.SharedUserStoryState):
class SimpleSharedState(
shared_state.SharedState):
_fake_platform = FakePlatform()
_current_user_story = None
@ -518,7 +518,7 @@ class UserStoryRunnerTest(unittest.TestCase):
class FailingUserStory(user_story.UserStory):
def __init__(self):
super(FailingUserStory, self).__init__(
shared_user_story_state_class=SimpleSharedUserStoryState,
shared_state_class=SimpleSharedState,
is_local=True)
self.was_run = False

@ -55,12 +55,12 @@ class UserStorySet(object):
def allow_mixed_story_states(self):
"""True iff UserStories are allowed to have different StoryState classes.
There are no checks in place for determining if SharedUserStoryStates are
There are no checks in place for determining if SharedStates are
being assigned correctly to all UserStorys in a given UserStorySet. The
majority of test cases should not need the ability to have multiple
ShareduserStoryStates, and usually implies you should be writing multiple
benchmarks instead. We provide errors to avoid accidentally assigning
or defaulting to the wrong SharedUserStoryState.
or defaulting to the wrong SharedState.
Override at your own risk. Here be dragons.
"""
return False

@ -5,21 +5,21 @@
import os
import unittest
from telemetry.story import shared_state
from telemetry import user_story
from telemetry.user_story import shared_user_story_state
from telemetry.user_story import user_story_set
from telemetry.util import cloud_storage
# pylint: disable=abstract-method
class SharedUserStoryStateBar(shared_user_story_state.SharedUserStoryState):
class SharedStateBar(shared_state.SharedState):
pass
class UserStoryFoo(user_story.UserStory):
def __init__(self, name='', labels=None):
super(UserStoryFoo, self).__init__(
SharedUserStoryStateBar, name, labels)
SharedStateBar, name, labels)
class UserStorySetFoo(user_story_set.UserStorySet):

@ -4,25 +4,25 @@
import unittest
from telemetry.story import shared_state
from telemetry import user_story
from telemetry.user_story import shared_user_story_state
# pylint: disable=abstract-method
class SharedUserStoryStateBar(shared_user_story_state.SharedUserStoryState):
class SharedStateBar(shared_state.SharedState):
pass
class UserStoryFoo(user_story.UserStory):
def __init__(self, name='', labels=None):
super(UserStoryFoo, self).__init__(
SharedUserStoryStateBar, name, labels)
SharedStateBar, name, labels)
class UserStoryTest(unittest.TestCase):
def testUserStoriesHaveDifferentIds(self):
u0 = user_story.UserStory(SharedUserStoryStateBar, 'foo')
u1 = user_story.UserStory(SharedUserStoryStateBar, 'bar')
u0 = user_story.UserStory(SharedStateBar, 'foo')
u1 = user_story.UserStory(SharedStateBar, 'bar')
self.assertNotEqual(u0.id, u1.id)
def testNamelessUserStoryDisplayName(self):
@ -38,25 +38,25 @@ class UserStoryTest(unittest.TestCase):
self.assertEquals('Foo_Bar_Baz_0', u.file_safe_name)
def testNamelessUserStoryAsDict(self):
u = user_story.UserStory(SharedUserStoryStateBar)
u = user_story.UserStory(SharedStateBar)
u_dict = u.AsDict()
self.assertEquals(u_dict['id'], u.id)
self.assertNotIn('name', u_dict)
def testNamedUserStoryAsDict(self):
u = user_story.UserStory(SharedUserStoryStateBar, 'Foo')
u = user_story.UserStory(SharedStateBar, 'Foo')
u_dict = u.AsDict()
self.assertEquals(u_dict['id'], u.id)
self.assertEquals('Foo', u_dict['name'])
def testMakeJavaScriptDeterministic(self):
u = user_story.UserStory(SharedUserStoryStateBar)
u = user_story.UserStory(SharedStateBar)
self.assertTrue(u.make_javascript_deterministic)
u = user_story.UserStory(
SharedUserStoryStateBar, make_javascript_deterministic=False)
SharedStateBar, make_javascript_deterministic=False)
self.assertFalse(u.make_javascript_deterministic)
u = user_story.UserStory(
SharedUserStoryStateBar, make_javascript_deterministic=True)
SharedStateBar, make_javascript_deterministic=True)
self.assertTrue(u.make_javascript_deterministic)