-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Giuseppe Lumia
committed
Nov 18, 2021
1 parent
3e130d8
commit 52615e7
Showing
6 changed files
with
520 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Functions used in integration tests. | ||
Be careful in adding stuff here as some tests rely on code appearing at certain line | ||
numbers. | ||
""" | ||
|
||
import time | ||
|
||
# reserved for future imports | ||
# reserved for future imports | ||
# reserved for future imports | ||
# reserved for future imports | ||
# reserved for future imports | ||
# reserved for future imports | ||
# reserved for future imports | ||
# reserved for future imports | ||
# reserved for future imports | ||
# reserved for future imports | ||
# reserved for future imports | ||
# reserved for future imports | ||
# reserved for future imports | ||
# reserved for future imports | ||
# reserved for future imports | ||
# reserved for future imports | ||
|
||
|
||
def sleepy(t): | ||
time.sleep(t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import re | ||
|
||
import boto3 | ||
import pytest | ||
from moto import mock_s3 | ||
|
||
from pylaprof import FS, S3, Profiler | ||
|
||
from .sleepy import sleepy | ||
|
||
|
||
def test_profiler_with_fs_storer(tmpcwd): | ||
"""Check profiler with FS storer. | ||
We set a period of 0.01s and run `sleepy` for 0.105s, so we should get a report with | ||
10 hits of this function. | ||
""" | ||
with Profiler(period=0.01, storer=FS(path=lambda: "report.txt")): | ||
sleepy(0.105) | ||
|
||
regex = re.compile(r".*;sleepy \(\/[^)]+\/sleepy\.py:28\) 10") | ||
with open("report.txt", "r") as fp: | ||
report = fp.read() | ||
for line in report.split("\n"): | ||
if regex.match(line): | ||
return # Ok! | ||
else: | ||
pytest.fail("something is wrong with the report:\n" + report) | ||
|
||
|
||
@mock_s3 | ||
def test_profiler_with_s3_storer(): | ||
"""Check profiler with S3 storer. | ||
We set a period of 0.01s and run `sleepy` for 0.105s, so we should get a report with | ||
10 hits of this function. | ||
""" | ||
boto3.resource("s3").Bucket("pylaprof").create() | ||
|
||
with Profiler(period=0.01, storer=S3(key=lambda: "report.txt")): | ||
sleepy(0.105) | ||
|
||
regex = re.compile(r".*;sleepy \(\/[^)]+\/sleepy\.py:28\) 10") | ||
report = ( | ||
boto3.resource("s3") | ||
.Object("pylaprof", "report.txt") | ||
.get()["Body"] | ||
.read() | ||
.decode("utf-8") | ||
) | ||
for line in report.split("\n"): | ||
if regex.match(line): | ||
return # Ok! | ||
else: | ||
pytest.fail("something is wrong with the report:\n" + report) |