A suite of related images used for testing, comprised of a list of TestImage instances. TestImages are discovered by reading images from a directory in the filesystem. Attributes: name: The name of the test set. tests: The list of TestImages forming the set.
| 214 | |
| 215 | |
| 216 | class TestSet: |
| 217 | ''' |
| 218 | A suite of related images used for testing, comprised of a list of |
| 219 | TestImage instances. TestImages are discovered by reading images from a |
| 220 | directory in the filesystem. |
| 221 | |
| 222 | Attributes: |
| 223 | name: The name of the test set. |
| 224 | tests: The list of TestImages forming the set. |
| 225 | ''' |
| 226 | |
| 227 | def __init__(self, name: str, set_dir: Path, profiles: list[str], |
| 228 | formats: list[str], target_image: Optional[str] = None): |
| 229 | ''' |
| 230 | Create a new TestSet using file-system discovery to find the images. |
| 231 | |
| 232 | Args: |
| 233 | name: The name of the test set. |
| 234 | set_dir: The root directory of the test set. |
| 235 | profiles: The compressor profiles to allow. |
| 236 | formats: The image formats to allow. |
| 237 | target_image: The name of the image to keep (for bug repo). |
| 238 | |
| 239 | Raise: |
| 240 | TestSetException: The test set could not be loaded. |
| 241 | ''' |
| 242 | self.name = name |
| 243 | |
| 244 | if not set_dir.exists() or not set_dir.is_dir(): |
| 245 | raise TestSetException(f'Bad test set directory ({set_dir})') |
| 246 | |
| 247 | self.tests = [] |
| 248 | |
| 249 | for (dir_path, _, file_names) in set_dir.walk(): |
| 250 | for file_name in file_names: |
| 251 | file_path = dir_path / file_name |
| 252 | |
| 253 | # Only select image files |
| 254 | ext = file_path.suffix |
| 255 | if ext not in TestImage.TEST_EXTS: |
| 256 | continue |
| 257 | |
| 258 | # Create the TestImage for each file on disk |
| 259 | image = TestImage(file_path) |
| 260 | |
| 261 | # Filter out the images we don't want to keep |
| 262 | if image.color_profile not in profiles: |
| 263 | continue |
| 264 | |
| 265 | if image.color_format not in formats: |
| 266 | continue |
| 267 | |
| 268 | if target_image and image.file_name != target_image: |
| 269 | continue |
| 270 | |
| 271 | self.tests.append(image) |
| 272 | |
| 273 | # Sort the images so they are in a stable order |