File: test_coverup_24.py

package info (click to toggle)
scalene 1.5.51-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,528 kB
  • sloc: cpp: 22,930; python: 13,403; javascript: 11,769; ansic: 817; makefile: 196; sh: 45
file content (38 lines) | stat: -rw-r--r-- 1,498 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# file scalene/scalene_profiler.py:879-893
# lines [879, 880, 883, 884, 885, 886, 888, 889, 890, 891, 893]
# branches ['883->884', '883->885', '885->886', '885->888']

import pytest
from scalene.scalene_profiler import Scalene
from scalene.scalene_arguments import ScaleneArguments

# Mock filename and line number
mock_filename = "mock_file.py"
mock_lineno = 10

# Create a test function to execute the missing lines/branches
def test_profile_this_code(monkeypatch):
    # Set up the test environment
    monkeypatch.setattr(Scalene, '_Scalene__files_to_profile', set())
    Scalene._Scalene__files_to_profile.add(mock_filename)
    # Mock the get_line_info method
    def mock_get_line_info(filename):
        if filename == mock_filename:
            return [((mock_lineno, mock_lineno + 1), mock_lineno)]
        return []
    monkeypatch.setattr(Scalene, 'get_line_info', mock_get_line_info)

    # Test when the file is in the set and the line number is within the range
    assert Scalene.profile_this_code(mock_filename, mock_lineno) == True

    # Test when the file is in the set but the line number is not within the range
    assert Scalene.profile_this_code(mock_filename, mock_lineno + 100) == False

    # Test when the file is not in the set
    assert Scalene.profile_this_code("other_file.py", mock_lineno) == False

    # No need to clean up after the test since we used monkeypatch

# Run the test
def test_scalene_profiler(monkeypatch):
    test_profile_this_code(monkeypatch)