| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import os |
| 6 |
import pytest |
| 7 |
import sys |
| 8 |
from scalene.scalene_profiler import Scalene |
| 9 |
from scalene.scalene_arguments import ScaleneArguments |
| 10 |
from unittest.mock import patch |
| 11 |
|
| 12 |
|
| 13 |
@pytest.fixture |
| 14 |
def cleanup(): |
| 15 |
|
| 16 |
yield |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
@patch("scalene.scalene_profiler.ScaleneMapFile") |
| 21 |
def test_scalene_cpu_count(mock_mapfile, cleanup): |
| 22 |
|
| 23 |
if hasattr(os, "sched_getaffinity"): |
| 24 |
expected_cpus = len(os.sched_getaffinity(0)) |
| 25 |
else: |
| 26 |
expected_cpus = os.cpu_count() if os.cpu_count() else 1 |
| 27 |
|
| 28 |
|
| 29 |
args = ScaleneArguments() |
| 30 |
scalene_profiler = Scalene(args) |
| 31 |
assert scalene_profiler._Scalene__availableCPUs == expected_cpus |