| 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.util import cloud_storage | |
| 10 from telemetry.wpr import archive_info | 9 from telemetry.wpr import archive_info |
| 11 | 10 |
| 12 PUBLIC_BUCKET = cloud_storage.PUBLIC_BUCKET | |
| 13 PARTNER_BUCKET = cloud_storage.PARTNER_BUCKET | |
| 14 INTERNAL_BUCKET = cloud_storage.INTERNAL_BUCKET | |
| 15 | 11 |
| 16 | 12 class StorySet(object): |
| 17 class UserStorySet(object): | |
| 18 """A collection of user story. | 13 """A collection of user story. |
| 19 | 14 |
| 20 A typical usage of UserStorySet would be to subclass it and then calling | 15 A typical usage of StorySet would be to subclass it and then calling |
| 21 AddUserStory for each UserStory. | 16 AddUserStory for each UserStory. |
| 22 """ | 17 """ |
| 23 | 18 |
| 24 def __init__(self, archive_data_file='', cloud_storage_bucket=None, | 19 def __init__(self, archive_data_file='', cloud_storage_bucket=None, |
| 25 base_dir=None, serving_dirs=None): | 20 base_dir=None, serving_dirs=None): |
| 26 """Creates a new UserStorySet. | 21 """Creates a new StorySet. |
| 27 | 22 |
| 28 Args: | 23 Args: |
| 29 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 |
| 30 to self.base_dir. | 25 to self.base_dir. |
| 31 cloud_storage_bucket: The cloud storage bucket used to download | 26 cloud_storage_bucket: The cloud storage bucket used to download |
| 32 Web Page Replay's archive data. Valid values are: None, | 27 Web Page Replay's archive data. Valid values are: None, |
| 33 PUBLIC_BUCKET, PARTNER_BUCKET, or INTERNAL_BUCKET (defined | 28 story.PUBLIC_BUCKET, story.PARTNER_BUCKET, or story.INTERNAL_BUCKET |
| 34 in telemetry.util.cloud_storage). | 29 (defined in telemetry.util.cloud_storage). |
| 35 serving_dirs: A set of paths, relative to self.base_dir, to directories | 30 serving_dirs: A set of paths, relative to self.base_dir, to directories |
| 36 containing hash files for non-wpr archive data stored in cloud | 31 containing hash files for non-wpr archive data stored in cloud |
| 37 storage. | 32 storage. |
| 38 """ | 33 """ |
| 39 self.user_stories = [] | 34 self.user_stories = [] |
| 40 self._archive_data_file = archive_data_file | 35 self._archive_data_file = archive_data_file |
| 41 self._wpr_archive_info = None | 36 self._wpr_archive_info = None |
| 42 archive_info.AssertValidCloudStorageBucket(cloud_storage_bucket) | 37 archive_info.AssertValidCloudStorageBucket(cloud_storage_bucket) |
| 43 self._cloud_storage_bucket = cloud_storage_bucket | 38 self._cloud_storage_bucket = cloud_storage_bucket |
| 44 if base_dir: | 39 if base_dir: |
| 45 if not os.path.isdir(base_dir): | 40 if not os.path.isdir(base_dir): |
| 46 raise ValueError('Must provide valid directory path for base_dir.') | 41 raise ValueError('Must provide valid directory path for base_dir.') |
| 47 self._base_dir = base_dir | 42 self._base_dir = base_dir |
| 48 else: | 43 else: |
| 49 self._base_dir = os.path.dirname(inspect.getfile(self.__class__)) | 44 self._base_dir = os.path.dirname(inspect.getfile(self.__class__)) |
| 50 # Convert any relative serving_dirs to absolute paths. | 45 # Convert any relative serving_dirs to absolute paths. |
| 51 self._serving_dirs = set(os.path.realpath(os.path.join(self.base_dir, d)) | 46 self._serving_dirs = set(os.path.realpath(os.path.join(self.base_dir, d)) |
| 52 for d in serving_dirs or []) | 47 for d in serving_dirs or []) |
| 53 | 48 |
| 54 @property | 49 @property |
| 55 def allow_mixed_story_states(self): | 50 def allow_mixed_story_states(self): |
| 56 """True iff UserStories are allowed to have different StoryState classes. | 51 """True iff UserStories are allowed to have different StoryState classes. |
| 57 | 52 |
| 58 There are no checks in place for determining if SharedStates are | 53 There are no checks in place for determining if SharedStates are |
| 59 being assigned correctly to all UserStorys in a given UserStorySet. The | 54 being assigned correctly to all UserStorys in a given StorySet. The |
| 60 majority of test cases should not need the ability to have multiple | 55 majority of test cases should not need the ability to have multiple |
| 61 ShareduserStoryStates, and usually implies you should be writing multiple | 56 ShareduserStoryStates, and usually implies you should be writing multiple |
| 62 benchmarks instead. We provide errors to avoid accidentally assigning | 57 benchmarks instead. We provide errors to avoid accidentally assigning |
| 63 or defaulting to the wrong SharedState. | 58 or defaulting to the wrong SharedState. |
| 64 Override at your own risk. Here be dragons. | 59 Override at your own risk. Here be dragons. |
| 65 """ | 60 """ |
| 66 return False | 61 return False |
| 67 | 62 |
| 68 @property | 63 @property |
| 69 def file_path(self): | 64 def file_path(self): |
| 70 return inspect.getfile(self.__class__).replace('.pyc', '.py') | 65 return inspect.getfile(self.__class__).replace('.pyc', '.py') |
| 71 | 66 |
| 72 @property | 67 @property |
| 73 def base_dir(self): | 68 def base_dir(self): |
| 74 """The base directory to resolve archive_data_file. | 69 """The base directory to resolve archive_data_file. |
| 75 | 70 |
| 76 This defaults to the directory containing the UserStorySet instance's class. | 71 This defaults to the directory containing the StorySet instance's class. |
| 77 """ | 72 """ |
| 78 return self._base_dir | 73 return self._base_dir |
| 79 | 74 |
| 80 @property | 75 @property |
| 81 def serving_dirs(self): | 76 def serving_dirs(self): |
| 82 all_serving_dirs = self._serving_dirs.copy() | 77 all_serving_dirs = self._serving_dirs.copy() |
| 83 for user_story in self.user_stories: | 78 for user_story in self.user_stories: |
| 84 if user_story.serving_dir: | 79 if user_story.serving_dir: |
| 85 all_serving_dirs.add(user_story.serving_dir) | 80 all_serving_dirs.add(user_story.serving_dir) |
| 86 return all_serving_dirs | 81 return all_serving_dirs |
| (...skipping 20 matching lines...) Expand all Loading... |
| 107 | 102 |
| 108 def RemoveUserStory(self, user_story): | 103 def RemoveUserStory(self, user_story): |
| 109 """Removes a UserStory. | 104 """Removes a UserStory. |
| 110 | 105 |
| 111 Allows the user stories to be filtered. | 106 Allows the user stories to be filtered. |
| 112 """ | 107 """ |
| 113 self.user_stories.remove(user_story) | 108 self.user_stories.remove(user_story) |
| 114 | 109 |
| 115 @classmethod | 110 @classmethod |
| 116 def Name(cls): | 111 def Name(cls): |
| 117 """Returns the string name of this UserStorySet. | 112 """Returns the string name of this StorySet. |
| 118 Note that this should be a classmethod so benchmark_runner script can match | 113 Note that this should be a classmethod so benchmark_runner script can match |
| 119 user story class with its name specified in the run command: | 114 user story class with its name specified in the run command: |
| 120 'Run <User story test name> <User story class name>' | 115 'Run <User story test name> <User story class name>' |
| 121 """ | 116 """ |
| 122 return cls.__module__.split('.')[-1] | 117 return cls.__module__.split('.')[-1] |
| 123 | 118 |
| 124 @classmethod | 119 @classmethod |
| 125 def Description(cls): | 120 def Description(cls): |
| 126 """Return a string explaining in human-understandable terms what this | 121 """Return a string explaining in human-understandable terms what this |
| 127 user story represents. | 122 user story represents. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 151 return self.user_stories.__iter__() | 146 return self.user_stories.__iter__() |
| 152 | 147 |
| 153 def __len__(self): | 148 def __len__(self): |
| 154 return len(self.user_stories) | 149 return len(self.user_stories) |
| 155 | 150 |
| 156 def __getitem__(self, key): | 151 def __getitem__(self, key): |
| 157 return self.user_stories[key] | 152 return self.user_stories[key] |
| 158 | 153 |
| 159 def __setitem__(self, key, value): | 154 def __setitem__(self, key, value): |
| 160 self.user_stories[key] = value | 155 self.user_stories[key] = value |
| OLD | NEW |