| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import argparse |
| 6 |
import os |
| 7 |
import pytest |
| 8 |
import time |
| 9 |
from unittest.mock import patch |
| 10 |
from scalene.scalene_profiler import Scalene, ScaleneArguments |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
@pytest.fixture |
| 15 |
def cleanup_scalene(): |
| 16 |
|
| 17 |
yield |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
if hasattr(Scalene, "_Scalene__args"): |
| 24 |
del Scalene._Scalene__args |
| 25 |
if hasattr(Scalene, "_Scalene__next_output_time"): |
| 26 |
del Scalene._Scalene__next_output_time |
| 27 |
if hasattr(Scalene, "_Scalene__output"): |
| 28 |
del Scalene._Scalene__output |
| 29 |
if hasattr(Scalene, "_Scalene__is_child"): |
| 30 |
del Scalene._Scalene__is_child |
| 31 |
if hasattr(Scalene, "_Scalene__parent_pid"): |
| 32 |
del Scalene._Scalene__parent_pid |
| 33 |
if hasattr(Scalene, "_Scalene__json"): |
| 34 |
del Scalene._Scalene__json |
| 35 |
|
| 36 |
|
| 37 |
def test_process_args(cleanup_scalene): |
| 38 |
|
| 39 |
args = argparse.Namespace( |
| 40 |
profile_interval=1, html=False, outfile="test_output.txt", pid=12345, gpu=False |
| 41 |
) |
| 42 |
|
| 43 |
|
| 44 |
with patch("time.perf_counter", return_value=100): |
| 45 |
|
| 46 |
Scalene.process_args(args) |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
assert Scalene._Scalene__next_output_time == 101 |
| 51 |
assert Scalene._Scalene__output.html == args.html |
| 52 |
assert Scalene._Scalene__output.output_file == os.path.abspath( |
| 53 |
os.path.expanduser(args.outfile) |
| 54 |
) |
| 55 |
assert Scalene._Scalene__is_child == True |
| 56 |
assert Scalene._Scalene__parent_pid == args.pid |
| 57 |
assert not Scalene._Scalene__output.gpu |
| 58 |
assert not Scalene._Scalene__json.gpu |
| 59 |
|
| 60 |
|
| 61 |
if os.path.exists(args.outfile): |
| 62 |
os.remove(args.outfile) |