Esempio n. 1
0
 def test_that_a_missing_layout_line_raises_an_error(
         self, configs_dir, general_section):
     path = configs_dir / 'no-layout.conf'
     with path.open('w') as tmp:
         tmp.write(general_section)
         tmp.write('[some scenario]\n' 'file1 = 1024\n' 'frags file1 = 2\n')
     with pytest.raises(ImageConfigError):
         Image.from_config(pathlib.Path(tmp.name))
     path.unlink()
Esempio n. 2
0
 def test_that_file_cannot_be_used_without_number_of_frags(
         self, configs_dir, general_section):
     path = configs_dir / 'file-without-frags.conf'
     with path.open('w') as tmp:
         tmp.write(general_section)
         tmp.write('[some scenario]\n' 'file1 = 1024\n' 'frags file2 = 2\n')
         tmp.write('layout = 1-1, 2.1, 1-2')
     with pytest.raises(ImageConfigError):
         Image.from_config(pathlib.Path(tmp.name))
     path.unlink()
Esempio n. 3
0
def test_two_consecutive_image_creations(config_path):
    image_path = pathlib.Path('/tmp/reproduce-me.dd')
    config = config_path / 'three-scenarios.conf'
    image = Image.from_config(config)
    image.write(image_path)
    image_digest = hashlib.sha256(image_path.open('rb').read()).hexdigest()

    image = Image.from_config(config)
    image.write(pathlib.Path('/tmp/reproduce-me.dd'))

    assert image_digest == hashlib.sha256(image_path.open('rb').read()).hexdigest()
Esempio n. 4
0
 def test_that_an_invalid_file_fragment_separator_raises_an_error(
         self, sep, general_section, configs_dir):
     if sep == '-' or sep == '.':
         return
     path = configs_dir / 'invalid-sep.conf'
     with path.open('w') as tmp:
         tmp.write(general_section)
         tmp.write('[some scenario]\nfrags file1 = 2\nfrags_file2 = 2\n')
         tmp.write('layout = 1-1, 2.1, 1')
         tmp.write(sep)
         tmp.write('2\n')
     with pytest.raises(ImageConfigError):
         Image.from_config(pathlib.Path(tmp.name))
     path.unlink()
Esempio n. 5
0
 def test_that_the_intertwine_layout_works(self, config):
     image = Image.from_config(config['path'])
     scenario = image.metadata['scenarios'][0]
     expected = config['expected']
     assert len(scenario['files']) == expected['num_files']
     for file in scenario['files']:
         assert expected['min_frags'] <= len(
             file['fragments']) <= expected['max_frags']
Esempio n. 6
0
 def test_that_the_fillers_have_the_correct_size(self, config):
     image = Image.from_config(config['config'])
     block_size = image.metadata['block_size']
     scenario = image.metadata['scenarios'][0]
     expected = config['expected_results']
     for file in scenario['files']:
         if file['original']['type'] == 'filler':
             assert len(file['fragments']) == 1
             assert file['fragments'][0]['size'] % block_size == 0
             assert expected['min'] <= file['fragments'][0][
                 'size'] / block_size <= expected['max']
Esempio n. 7
0
 def test_that_fillers_can_be_added(self, config):
     image = Image.from_config(config)
     scenario = image.metadata['scenarios'][0]
     assert len(scenario['files']) == 3
     assert sum(1 for f in scenario['files']
                if f['original']['type'] == 'filler') == 2
Esempio n. 8
0
 def test_that_the_correct_number_of_files_per_scenario_is_present(
         self, config, num_expected_files):
     image = Image.from_config(config)
     files_per_scenario = tuple(
         len(s['files']) for s in image.metadata['scenarios'])
     assert files_per_scenario == num_expected_files
Esempio n. 9
0
 def test_that_the_correct_number_of_scenarios_is_present(
         self, config, num_expected_scenarios):
     image = Image.from_config(config)
     assert len(image.metadata['scenarios']) == num_expected_scenarios
Esempio n. 10
0
 def test_that_the_seed_is_set(self, minimal_config):
     Image.from_config(minimal_config)
     assert woodblock.random.get_seed() == 123
Esempio n. 11
0
 def test_that_a_missing_corpus_option_raises_an_error(self, path):
     with pytest.raises(ImageConfigError):
         Image.from_config(path)
Esempio n. 12
0
 def test_that_invalid_intertwine_scenarios_raise_an_error(self, config):
     with pytest.raises(ImageConfigError):
         Image.from_config(config)
Esempio n. 13
0
 def test_that_an_invalid_path_raises_an_error(self):
     with pytest.raises(FileNotFoundError):
         Image.from_config(pathlib.Path('/some/path'))
Esempio n. 14
0
 def test_that_invalid_min_max_blocks_raise_an_error(self, config):
     with pytest.raises(ImageConfigError):
         Image.from_config(config)
Esempio n. 15
0
    def test_config(self, config_path):
        config = config_path / 'three-scenarios.conf'
        image = Image.from_config(config)
        image.write(pathlib.Path('/tmp/a.dd'))
        meta = image.metadata
        fragment_order = _get_fragment_order_from_metadata(image.metadata)
        file_ids = dict()

        assert meta['block_size'] == 512
        assert meta['seed'] == 123
        assert len(meta['scenarios']) == 3

        s1 = meta['scenarios'][0]
        assert s1['name'] == 'first scenario'
        assert len(s1['files']) == 3
        file_ids['s1'] = {
            1: fragment_order[0][0],
            2: fragment_order[3][0],
            3: fragment_order[1][0]
        }

        s2 = meta['scenarios'][1]
        assert s2['name'] == 'second scenario'
        assert len(s2['files']) == 2
        file_ids['s2'] = {1: fragment_order[5][0], 2: fragment_order[6][0]}
        file_1 = _get_file_with_id(s2, file_ids['s2'][1])
        file_2 = _get_file_with_id(s2, file_ids['s2'][2])
        assert file_1['original']['path'] == '2000'
        assert file_2['original']['path'] == '1024'

        s3 = meta['scenarios'][2]
        assert s3['name'] == 'third scenario'
        assert len(s3['files']) == 3
        file_ids['s3'] = {
            2: fragment_order[8][0],
            3: fragment_order[9][0],
            4: fragment_order[11][0]
        }
        file_1 = _get_file_with_id(s3, file_ids['s3'][2])
        file_3 = _get_file_with_id(s3, file_ids['s3'][3])
        file_4 = _get_file_with_id(s3, file_ids['s3'][4])
        assert file_1['original']['path'] == '4096'
        assert file_3['original']['path'] == 'letters/ascii_letters'
        assert file_4['original']['path'].startswith('letters/')

        expected_fragment_order = ((file_ids['s1'][1],
                                    1), (file_ids['s1'][3],
                                         1), (file_ids['s1'][1],
                                              2), (file_ids['s1'][2],
                                                   1), (file_ids['s1'][1], 3),
                                   (file_ids['s2'][1],
                                    1), (file_ids['s2'][2],
                                         1), (file_ids['s2'][1],
                                              3), (file_ids['s3'][2],
                                                   1), (file_ids['s3'][3], 1),
                                   (file_ids['s3'][2],
                                    2), (file_ids['s3'][4],
                                         2), (file_ids['s3'][3],
                                              2), (file_ids['s3'][4], 1),
                                   (file_ids['s3'][2], 4), (file_ids['s3'][2],
                                                            3))

        assert fragment_order == expected_fragment_order