|
11 | 11 | from unblob.models import UnknownChunk, ValidChunk |
12 | 12 | from unblob.processing import ( |
13 | 13 | ExtractionConfig, |
14 | | - calculate_buffer_size, |
| 14 | + calculate_block_size, |
15 | 15 | calculate_entropy, |
16 | 16 | calculate_unknown_chunks, |
17 | 17 | format_entropy_plot, |
@@ -129,41 +129,45 @@ def test_calculate_unknown_chunks( |
129 | 129 | (1000, 100, 10, 100, 10), |
130 | 130 | ], |
131 | 131 | ) |
132 | | -def test_calculate_buffer_size( |
| 132 | +def test_calculate_block_size( |
133 | 133 | file_size: int, chunk_count: int, min_limit: int, max_limit: int, expected: int |
134 | 134 | ): |
135 | | - assert expected == calculate_buffer_size( |
136 | | - file_size, chunk_count=chunk_count, min_limit=min_limit, max_limit=max_limit |
| 135 | + assert expected == calculate_block_size( |
| 136 | + file_size, |
| 137 | + chunk_count=chunk_count, |
| 138 | + min_limit=min_limit, |
| 139 | + max_limit=max_limit, |
137 | 140 | ) |
138 | 141 |
|
139 | 142 |
|
140 | 143 | def test_format_entropy_plot_error(): |
141 | 144 | with pytest.raises(TypeError): |
142 | | - format_entropy_plot(percentages=[], buffer_size=1024) |
| 145 | + format_entropy_plot(percentages=[], block_size=1024) |
143 | 146 |
|
144 | 147 |
|
145 | 148 | @pytest.mark.parametrize( |
146 | | - "percentages, buffer_size", |
| 149 | + "percentages, block_size", |
147 | 150 | [ |
148 | 151 | pytest.param([0.0] * 100, 1024, id="zero-array"), |
149 | 152 | pytest.param([99.99] * 100, 1024, id="99-array"), |
150 | 153 | pytest.param([100.0] * 100, 1024, id="100-array"), |
151 | | - pytest.param([100.0] * 100, -1, id="buffer_size-can-be-anything1"), |
152 | | - pytest.param([100.0] * 100, None, id="buffer_size-can-be-anything2"), |
153 | | - pytest.param([100.0] * 100, "None", id="buffer_size-can-be-anything3"), |
| 154 | + pytest.param([100.0] * 100, -1, id="block_size-can-be-anything1"), |
| 155 | + pytest.param([100.0] * 100, None, id="block_size-can-be-anything2"), |
| 156 | + pytest.param([100.0] * 100, "None", id="block_size-can-be-anything3"), |
154 | 157 | ], |
155 | 158 | ) |
156 | | -def test_format_entropy_plot_no_exception(percentages: List[float], buffer_size: int): |
157 | | - assert str(buffer_size) in format_entropy_plot( |
158 | | - percentages=percentages, buffer_size=buffer_size |
| 159 | +def test_format_entropy_plot_no_exception(percentages: List[float], block_size: int): |
| 160 | + assert str(block_size) in format_entropy_plot( |
| 161 | + percentages=percentages, |
| 162 | + block_size=block_size, |
159 | 163 | ) |
160 | 164 |
|
161 | 165 |
|
162 | 166 | def test_calculate_entropy_no_exception(): |
163 | 167 | report = calculate_entropy(Path(sys.executable)) |
164 | 168 | format_entropy_plot( |
165 | 169 | percentages=report.percentages, |
166 | | - buffer_size=report.buffer_size, |
| 170 | + block_size=report.block_size, |
167 | 171 | ) |
168 | 172 |
|
169 | 173 |
|
@@ -374,18 +378,17 @@ def get_all(file_name, report_type: Type[T]) -> List[T]: |
374 | 378 | # with a percentages (scaled up bits) of 64 items, for 0, 6, 8, 8, ... bits of entropies |
375 | 379 | [unknown_chunk_report] = get_all("input-file", UnknownChunkReport) |
376 | 380 | unknown_entropy = unknown_chunk_report.entropy |
377 | | - assert unknown_entropy == EntropyReport( |
378 | | - percentages=[0.0, 75.0] + [100.0] * 62, buffer_size=1024 |
379 | | - ) |
380 | 381 | assert ( |
381 | 382 | unknown_entropy is not None |
382 | | - ) # removes pyright complaints for the below 3 lines :( |
| 383 | + ) # removes pyright complaints for the below lines :( |
| 384 | + assert unknown_entropy.percentages == [0.0, 75.0] + [100.0] * 62 |
| 385 | + assert unknown_entropy.block_size == 1024 |
383 | 386 | assert round(unknown_entropy.mean, 2) == 98.05 # noqa: PLR2004 |
384 | 387 | assert unknown_entropy.highest == 100.0 # noqa: PLR2004 |
385 | 388 | assert unknown_entropy.lowest == 0.0 # noqa: PLR2004 |
386 | 389 |
|
387 | 390 | # we should have entropy calculated for files without extractions, except for empty files |
388 | 391 | assert [] == get_all("empty.txt", EntropyReport) |
389 | | - assert [EntropyReport(percentages=[100.0], buffer_size=1024)] == get_all( |
| 392 | + assert [EntropyReport(percentages=[100.0], block_size=1024, mean=100.0)] == get_all( |
390 | 393 | "0-255.bin", EntropyReport |
391 | 394 | ) |
0 commit comments