Datasets:
Download scripts/test_image_identity.py from CrossSWE/CrossSWE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/scripts/test_image_identity.py
- Command line
-
hf download hf://datasets/CrossSWE/CrossSWE-Bench/scripts/test_image_identity.py
-
curl -L -o test_image_identity.py https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/scripts/test_image_identity.py
1.61 kB
| import unittest | |
| from reusable_support.image_identity import validate_image | |
| class IdentityTests(unittest.TestCase): | |
| def setUp(self): | |
| self.expected = {'config_digest': 'sha256:' + '1'*64, 'registry_digest': 'sha256:' + '2'*64, | |
| 'amd64_manifest_digest': 'sha256:' + '3'*64} | |
| def test_classic_config_identity(self): | |
| self.assertTrue(validate_image({'Id': self.expected['config_digest'], 'Os':'linux', 'Architecture':'amd64'}, self.expected)) | |
| def test_containerd_manifest_identity(self): | |
| info={'Id':self.expected['registry_digest'], 'Os':'linux', 'Architecture':'amd64', | |
| 'Descriptor':{'digest':self.expected['registry_digest'], 'annotations':{'config.digest':self.expected['config_digest']}}} | |
| self.assertTrue(validate_image(info,self.expected)) | |
| def test_wrong_config_annotation_rejected(self): | |
| info={'Id':self.expected['registry_digest'], 'Os':'linux', 'Architecture':'amd64', | |
| 'Descriptor':{'digest':self.expected['registry_digest'], 'annotations':{'config.digest':'sha256:'+'4'*64}}} | |
| with self.assertRaises(ValueError): validate_image(info,self.expected) | |
| def test_other_image_rejected(self): | |
| with self.assertRaises(ValueError): | |
| validate_image({'Id':'sha256:'+'4'*64,'Os':'linux','Architecture':'amd64'},self.expected) | |
| def test_wrong_platform_rejected(self): | |
| with self.assertRaises(ValueError): | |
| validate_image({'Id':self.expected['config_digest'],'Os':'linux','Architecture':'arm64'},self.expected) | |
| if __name__=='__main__':unittest.main() | |