| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import inspect | 5 import inspect |
| 6 import os | 6 import os |
| 7 | 7 |
| 8 from telemetry import user_story as user_story_module | 8 from telemetry import user_story as user_story_module |
| 9 from telemetry.wpr import archive_info | 9 from telemetry.wpr import archive_info |
| 10 | 10 |
| 11 | 11 |
| 12 class UserStorySet(object): | 12 class UserStorySet(object): |
| 13 """A collection of user story. | 13 """A collection of user story. |
| 14 | 14 |
| 15 A typical usage of UserStorySet would be to subclass it and then calling | 15 A typical usage of UserStorySet would be to subclass it and then calling |
| 16 AddUserStory for each UserStory.. | 16 AddUserStory for each UserStory. |
| 17 """ | 17 """ |
| 18 | 18 |
| 19 def __init__(self, archive_data_file='', cloud_storage_bucket=None, | 19 def __init__(self, archive_data_file='', cloud_storage_bucket=None, |
| 20 serving_dirs=None): | 20 serving_dirs=None): |
| 21 """Creates a new UserStorySet. | 21 """Creates a new UserStorySet. |
| 22 | 22 |
| 23 Args: | 23 Args: |
| 24 archive_data_file: The path to Web Page Replay's archive data, relative | 24 archive_data_file: The path to Web Page Replay's archive data, relative |
| 25 to self.base_dir. | 25 to self.base_dir. |
| 26 cloud_storage_bucket: The cloud storage bucket used to download | 26 cloud_storage_bucket: The cloud storage bucket used to download |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 """Lazily constructs wpr_archive_info if it's not set and returns it.""" | 63 """Lazily constructs wpr_archive_info if it's not set and returns it.""" |
| 64 if self.archive_data_file and not self._wpr_archive_info: | 64 if self.archive_data_file and not self._wpr_archive_info: |
| 65 self._wpr_archive_info = archive_info.WprArchiveInfo.FromFile( | 65 self._wpr_archive_info = archive_info.WprArchiveInfo.FromFile( |
| 66 os.path.join(self.base_dir, self.archive_data_file), self.bucket) | 66 os.path.join(self.base_dir, self.archive_data_file), self.bucket) |
| 67 return self._wpr_archive_info | 67 return self._wpr_archive_info |
| 68 | 68 |
| 69 def AddUserStory(self, user_story): | 69 def AddUserStory(self, user_story): |
| 70 assert isinstance(user_story, user_story_module.UserStory) | 70 assert isinstance(user_story, user_story_module.UserStory) |
| 71 self.user_stories.append(user_story) | 71 self.user_stories.append(user_story) |
| 72 | 72 |
| 73 def RemoveUserStory(self, user_story): |
| 74 """Removes a UserStory. |
| 75 |
| 76 Allows the user stories to be filtered. |
| 77 """ |
| 78 self.user_stories.remove(user_story) |
| 79 |
| 73 @classmethod | 80 @classmethod |
| 74 def Name(cls): | 81 def Name(cls): |
| 75 """ Returns the string name of this UserStorySet. | 82 """Returns the string name of this UserStorySet. |
| 76 Note that this should be a classmethod so benchmark_runner script can match | 83 Note that this should be a classmethod so benchmark_runner script can match |
| 77 user story class with its name specified in the run command: | 84 user story class with its name specified in the run command: |
| 78 'Run <User story test name> <User story class name>' | 85 'Run <User story test name> <User story class name>' |
| 79 """ | 86 """ |
| 80 return cls.__module__.split('.')[-1] | 87 return cls.__module__.split('.')[-1] |
| 81 | 88 |
| 82 @classmethod | 89 @classmethod |
| 83 def Description(cls): | 90 def Description(cls): |
| 84 """ Return a string explaining in human-understandable terms what this | 91 """Return a string explaining in human-understandable terms what this |
| 85 user story represents. | 92 user story represents. |
| 86 Note that this should be a classmethod so benchmark_runner script can | 93 Note that this should be a classmethod so benchmark_runner script can |
| 87 display user stories' names along their descriptions in the list commmand. | 94 display user stories' names along their descriptions in the list command. |
| 88 """ | 95 """ |
| 89 if cls.__doc__: | 96 if cls.__doc__: |
| 90 return cls.__doc__.splitlines()[0] | 97 return cls.__doc__.splitlines()[0] |
| 91 else: | 98 else: |
| 92 return '' | 99 return '' |
| 93 | 100 |
| 94 def ShuffleAndFilterUserStorySet(self, finder_options): | 101 def ShuffleAndFilterUserStorySet(self, finder_options): |
| 95 pass | 102 pass |
| 96 | 103 |
| 97 def WprFilePathForUserStory(self, story): | 104 def WprFilePathForUserStory(self, story): |
| 98 """Convenient function to retrive WPR archive file path. | 105 """Convenient function to retrieve WPR archive file path. |
| 99 | 106 |
| 100 Args: | 107 Args: |
| 101 user_story: The UserStory to lookup. | 108 user_story: The UserStory to lookup. |
| 102 | 109 |
| 103 Returns: | 110 Returns: |
| 104 The WPR archive file path for the given UserStory, if found. | 111 The WPR archive file path for the given UserStory, if found. |
| 105 Otherwise, return None. | 112 Otherwise, return None. |
| 106 """ | 113 """ |
| 107 if not self.wpr_archive_info: | 114 if not self.wpr_archive_info: |
| 108 return None | 115 return None |
| 109 return self.wpr_archive_info.WprFilePathForUserStory(story) | 116 return self.wpr_archive_info.WprFilePathForUserStory(story) |
| 110 | 117 |
| 111 def __iter__(self): | 118 def __iter__(self): |
| 112 return self.user_stories.__iter__() | 119 return self.user_stories.__iter__() |
| 113 | 120 |
| 114 def __len__(self): | 121 def __len__(self): |
| 115 return len(self.user_stories) | 122 return len(self.user_stories) |
| 116 | 123 |
| 117 def __getitem__(self, key): | 124 def __getitem__(self, key): |
| 118 return self.user_stories[key] | 125 return self.user_stories[key] |
| 119 | 126 |
| 120 def __setitem__(self, key, value): | 127 def __setitem__(self, key, value): |
| 121 self.user_stories[key] = value | 128 self.user_stories[key] = value |
| OLD | NEW |