| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import pytest |
| 6 |
from collections import OrderedDict |
| 7 |
from typing import Any, List |
| 8 |
from scalene.scalene_statistics import ScaleneStatistics |
| 9 |
from scalene.scalene_leak_analysis import ScaleneLeakAnalysis |
| 10 |
|
| 11 |
|
| 12 |
class Filename(str): |
| 13 |
pass |
| 14 |
|
| 15 |
|
| 16 |
class LineNumber(int): |
| 17 |
pass |
| 18 |
|
| 19 |
|
| 20 |
@pytest.fixture |
| 21 |
def scalene_statistics(): |
| 22 |
stats = ScaleneStatistics() |
| 23 |
fname = Filename("test_file.py") |
| 24 |
line_number = LineNumber(1) |
| 25 |
stats.memory_stats.leak_score[fname][line_number] = (100, 1) |
| 26 |
return stats |
| 27 |
|
| 28 |
|
| 29 |
def test_compute_leaks(scalene_statistics): |
| 30 |
stats = scalene_statistics |
| 31 |
fname = Filename("test_file.py") |
| 32 |
avg_mallocs = OrderedDict({LineNumber(1): 50.0}) |
| 33 |
growth_rate = 2.0 |
| 34 |
|
| 35 |
leaks = ScaleneLeakAnalysis.compute_leaks(growth_rate, stats, avg_mallocs, fname) |
| 36 |
|
| 37 |
assert len(leaks) == 1 |
| 38 |
assert leaks[0][0] == LineNumber(1) |
| 39 |
assert leaks[0][1] == 1.0 - (1 + 1) / (100 - 1 + 2) |
| 40 |
assert leaks[0][2] == 50.0 |
| 41 |
|
| 42 |
|