| 1 | # file scalene/scalene_profiler.py:380-384 |
| 2 | # lines [380, 381, 383, 384] |
| 3 | # branches [] |
| 4 | |
| 5 | import pytest |
| 6 | from scalene.scalene_profiler import Scalene |
| 7 | |
| 8 | |
| 9 | # Test function to improve coverage for Scalene.remove_child_pid |
| 10 | def test_remove_child_pid(): |
| 11 | # Setup: Add a pid to the child_pids set |
| 12 | test_pid = 12345 |
| 13 | Scalene.child_pids.add(test_pid) |
| 14 | assert test_pid in Scalene.child_pids # Precondition check |
| 15 | |
| 16 | # Exercise: Remove the pid |
| 17 | Scalene.remove_child_pid(test_pid) |
| 18 | |
| 19 | # Verify: Check that the pid was removed |
| 20 | assert test_pid not in Scalene.child_pids |
| 21 | |
| 22 | # Cleanup: No cleanup needed as the pid was already removed |
| 23 | |
| 24 | |
| 25 | # Test function to cover the case where the pid does not exist |
| 26 | def test_remove_nonexistent_child_pid(): |
| 27 | # Setup: Ensure the pid is not in the child_pids set |
| 28 | test_pid = 54321 |
| 29 | Scalene.child_pids.discard(test_pid) # Ensure pid is not present |
| 30 | assert test_pid not in Scalene.child_pids # Precondition check |
| 31 | |
| 32 | # Exercise: Attempt to remove a non-existent pid |
| 33 | Scalene.remove_child_pid(test_pid) # Should not raise an exception |
| 34 | |
| 35 | # Verify: Check that the pid is still not in the set |
| 36 | assert test_pid not in Scalene.child_pids |
| 37 | |
| 38 | # Cleanup: No cleanup needed as the pid was not in the set to begin with |