def test_can_load_u_boot_version(self): self.options['install-condition-pattern-type'] = 'u-boot' self.options['filename'] = create_u_boot_file() obj = Object(self.options) metadata = obj.to_metadata() self.assertEqual(metadata['install-if-different']['version'], '13.08.1988')
def test_updating_filename_cleans_compression(self): uncompressed_fn = os.path.join(self.fixtures_dir, 'base.txt') compressed_fn = os.path.join(self.fixtures_dir, 'base.txt.gz') self.options['filename'] = uncompressed_fn obj = Object(self.options) metadata = obj.to_metadata() self.assertIsNone(metadata.get('compressed')) obj.update('filename', compressed_fn) metadata = obj.to_metadata() self.assertEqual(metadata['compressed'], True) obj.update('filename', uncompressed_fn) metadata = obj.to_metadata() self.assertIsNone(metadata.get('compressed'))
def test_can_generate_metadata(self): content = b'spam' fn = self.create_file(content) obj = Object({ 'filename': fn, 'mode': 'raw', 'target-type': 'device', 'target': '/dev/sda', 'chunk-size': 1, 'count': 2, 'seek': 3, 'skip': 4, 'truncate': True, }) expected = { 'mode': 'raw', 'filename': fn, 'target-type': 'device', 'target': '/dev/sda', 'chunk-size': 1, 'count': 2, 'seek': 3, 'skip': 4, 'truncate': True, 'size': len(content), 'sha256sum': hashlib.sha256(content).hexdigest(), } self.assertEqual(obj.to_metadata(), expected)
def test_can_represent_compressed_object_of_symlink_as_metadata(self): self.options['filename'] = os.path.join(self.fixtures_dir, 'symbolic.gz') obj = Object(self.options) metadata = obj.to_metadata() self.assertTrue(metadata['compressed']) self.assertEqual(metadata['required-uncompressed-size'], self.size)
def test_can_represent_compressed_object_as_metadata(self): self.options['filename'] = os.path.join(self.fixtures_dir, 'base.txt.lzo') obj = Object(self.options) metadata = obj.to_metadata() self.assertEqual(metadata['compressed'], True) self.assertEqual(metadata['required-uncompressed-size'], self.size)
def test_can_get_tar_uncompressed_size(self): self.options['filename'] = os.path.join(self.fixtures_dir, 'archive.tar.gz') obj = Object(self.options) expected = os.path.getsize( os.path.join(self.fixtures_dir, 'archive.tar')) observed = obj.to_metadata().get('required-uncompressed-size') self.assertEqual(observed, expected)
def test_can_load_linux_kernel_versions(self): for image, version in self.images: self.options['install-condition-pattern-type'] = 'linux-kernel' self.options['install-condition'] = 'version-diverges' self.options['filename'] = image obj = Object(self.options) metadata = obj.to_metadata() self.assertEqual(metadata['install-if-different']['version'], version)
def test_cannot_overwrite_compression_properties_on_metadata(self): self.options['filename'] = os.path.join(self.fixtures_dir, 'base.txt.bz2') obj = Object(self.options) obj._compressed = True # it's a compressed file, but not supported obj.compressor = 'gzip' # and it is a bz2, not a gzip. metadata = obj.to_metadata() # luckily metadata will ignore all this self.assertIsNone(metadata.get('compressed')) self.assertIsNone(metadata.get('required-uncompressed-size'))
def test_can_create_manager_from_dump(self, sets): dump = {ObjectsManager.metadata: [[self.options] for _ in range(sets)]} manager = ObjectsManager(dump=dump) self.assertEqual(len(manager), sets) self.assertEqual(len(manager.all()), sets) for objs in manager.objects: self.assertEqual(len(objs), sets) base_object = Object(self.options) for obj in manager.all(): self.assertEqual(base_object.to_metadata(), obj.to_metadata())
def test_can_represent_u_boot_object_as_metadata(self): fn = create_u_boot_file() self.options['filename'] = fn self.options['install-condition-pattern-type'] = 'u-boot' self.metadata['install-if-different']['pattern'] = 'u-boot' self.metadata['install-if-different']['version'] = '13.08.1988' self.metadata['filename'] = fn self.metadata['size'] = os.path.getsize(fn) with open(fn, 'rb') as fp: sha256sum = hashlib.sha256(fp.read()).hexdigest() self.metadata['sha256sum'] = sha256sum obj = Object(self.options) self.assertEqual(obj.to_metadata(), self.metadata)
def test_can_represent_linux_kernel_object_as_metadata(self): self.metadata['install-if-different']['pattern'] = 'linux-kernel' for image, version in self.images: self.options['filename'] = image self.options['install-condition'] = 'version-diverges' self.options['install-condition-pattern-type'] = 'linux-kernel' self.metadata['install-if-different']['version'] = version self.metadata['filename'] = image self.metadata['size'] = os.path.getsize(image) with open(image, 'rb') as fp: sha256sum = hashlib.sha256(fp.read()).hexdigest() self.metadata['sha256sum'] = sha256sum obj = Object(self.options) self.assertEqual(obj.to_metadata(), self.metadata)
def test_can_represent_as_metadata(self): obj = Object(self.options) expected = { 'filename': self.fn, 'mode': 'raw', 'chunk-size': 131072, 'count': -1, 'seek': 0, 'skip': 0, 'target-type': 'device', 'target': '/dev/sda', 'truncate': False, 'size': 4, 'sha256sum': hashlib.sha256(b'spam').hexdigest(), } observed = obj.to_metadata() self.assertEqual(observed, expected)
def test_full_metadata(self): obj = Object(self.full_options) metadata = obj.to_metadata() self.assertEqual(self.full_metadata, metadata) self.assertIsNone(validate_schema(self.mode_schema, metadata))
def test_can_work_with_symbolic_links(self): self.options['filename'] = os.path.join(self.fixtures_dir, 'symbolic.gz') obj = Object(self.options) observed = obj.to_metadata().get('required-uncompressed-size') self.assertEqual(observed, self.size)
def test_uncompressed_size_of_uncompressed_object_is_None(self): self.options['filename'] = os.path.join(self.fixtures_dir, 'archive.tar') obj = Object(self.options) observed = obj.to_metadata().get('required-uncompressed-size') self.assertIsNone(observed)
def test_can_load_custom_object_version(self): obj = Object(self.options) metadata = obj.to_metadata() self.assertEqual(metadata['install-if-different']['version'], '1.0')
def test_can_represent_as_metadata(self): obj = Object(self.options) self.assertEqual(obj.to_metadata(), self.metadata)
def test_can_get_lzo_uncompressed_size(self): self.options['filename'] = os.path.join(self.fixtures_dir, 'base.txt.lzo') obj = Object(self.options) observed = obj.to_metadata().get('required-uncompressed-size') self.assertEqual(observed, self.size)