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.story import story as story_module | 8 from telemetry.story import story as story_module |
9 from telemetry.wpr import archive_info | 9 from telemetry.wpr import archive_info |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
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 |
27 Web Page Replay's archive data. Valid values are: None, | 27 Web Page Replay's archive data. Valid values are: None, |
28 story.PUBLIC_BUCKET, story.PARTNER_BUCKET, or story.INTERNAL_BUCKET | 28 story.PUBLIC_BUCKET, story.PARTNER_BUCKET, or story.INTERNAL_BUCKET |
29 (defined in telemetry.util.cloud_storage). | 29 (defined in telemetry.util.cloud_storage). |
30 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 |
31 containing hash files for non-wpr archive data stored in cloud | 31 containing hash files for non-wpr archive data stored in cloud |
32 storage. | 32 storage. |
33 """ | 33 """ |
34 self.stories = [] | 34 self._stories = [] |
| 35 self._story_names_and_grouping_keys = set() |
35 self._archive_data_file = archive_data_file | 36 self._archive_data_file = archive_data_file |
36 self._wpr_archive_info = None | 37 self._wpr_archive_info = None |
37 archive_info.AssertValidCloudStorageBucket(cloud_storage_bucket) | 38 archive_info.AssertValidCloudStorageBucket(cloud_storage_bucket) |
38 self._cloud_storage_bucket = cloud_storage_bucket | 39 self._cloud_storage_bucket = cloud_storage_bucket |
39 if base_dir: | 40 if base_dir: |
40 if not os.path.isdir(base_dir): | 41 if not os.path.isdir(base_dir): |
41 raise ValueError('Invalid directory path of base_dir: %s' % base_dir) | 42 raise ValueError('Invalid directory path of base_dir: %s' % base_dir) |
42 self._base_dir = base_dir | 43 self._base_dir = base_dir |
43 else: | 44 else: |
44 self._base_dir = os.path.dirname(inspect.getfile(self.__class__)) | 45 self._base_dir = os.path.dirname(inspect.getfile(self.__class__)) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 return self._cloud_storage_bucket | 90 return self._cloud_storage_bucket |
90 | 91 |
91 @property | 92 @property |
92 def wpr_archive_info(self): | 93 def wpr_archive_info(self): |
93 """Lazily constructs wpr_archive_info if it's not set and returns it.""" | 94 """Lazily constructs wpr_archive_info if it's not set and returns it.""" |
94 if self.archive_data_file and not self._wpr_archive_info: | 95 if self.archive_data_file and not self._wpr_archive_info: |
95 self._wpr_archive_info = archive_info.WprArchiveInfo.FromFile( | 96 self._wpr_archive_info = archive_info.WprArchiveInfo.FromFile( |
96 os.path.join(self.base_dir, self.archive_data_file), self.bucket) | 97 os.path.join(self.base_dir, self.archive_data_file), self.bucket) |
97 return self._wpr_archive_info | 98 return self._wpr_archive_info |
98 | 99 |
| 100 @property |
| 101 def stories(self): |
| 102 return self._stories |
| 103 |
99 def AddStory(self, story): | 104 def AddStory(self, story): |
100 assert isinstance(story, story_module.Story) | 105 assert isinstance(story, story_module.Story) |
101 self.stories.append(story) | 106 assert self._IsUnique(story), ('Tried to add story with duplicate display ' |
| 107 'name %s. Story display names should be ' |
| 108 'unique.' % story.display_name) |
| 109 self._stories.append(story) |
| 110 self._story_names_and_grouping_keys.add( |
| 111 story.display_name_and_grouping_key_tuple) |
| 112 |
| 113 def _IsUnique(self, story): |
| 114 return (story.display_name_and_grouping_key_tuple not in |
| 115 self._story_names_and_grouping_keys) |
102 | 116 |
103 def RemoveStory(self, story): | 117 def RemoveStory(self, story): |
104 """Removes a Story. | 118 """Removes a Story. |
105 | 119 |
106 Allows the stories to be filtered. | 120 Allows the stories to be filtered. |
107 """ | 121 """ |
108 self.stories.remove(story) | 122 self._stories.remove(story) |
| 123 self._story_names_and_grouping_keys.remove( |
| 124 story.display_name_and_grouping_key_tuple) |
109 | 125 |
110 @classmethod | 126 @classmethod |
111 def Name(cls): | 127 def Name(cls): |
112 """Returns the string name of this StorySet. | 128 """Returns the string name of this StorySet. |
113 Note that this should be a classmethod so the benchmark_runner script can | 129 Note that this should be a classmethod so the benchmark_runner script can |
114 match the story class with its name specified in the run command: | 130 match the story class with its name specified in the run command: |
115 'Run <User story test name> <User story class name>' | 131 'Run <User story test name> <User story class name>' |
116 """ | 132 """ |
117 return cls.__module__.split('.')[-1] | 133 return cls.__module__.split('.')[-1] |
118 | 134 |
(...skipping 26 matching lines...) Expand all Loading... |
145 def __iter__(self): | 161 def __iter__(self): |
146 return self.stories.__iter__() | 162 return self.stories.__iter__() |
147 | 163 |
148 def __len__(self): | 164 def __len__(self): |
149 return len(self.stories) | 165 return len(self.stories) |
150 | 166 |
151 def __getitem__(self, key): | 167 def __getitem__(self, key): |
152 return self.stories[key] | 168 return self.stories[key] |
153 | 169 |
154 def __setitem__(self, key, value): | 170 def __setitem__(self, key, value): |
155 self.stories[key] = value | 171 self._stories[key] = value |
OLD | NEW |