-
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.
Merge pull request #20 from erayerdin/development
v0.1.1a1
- Loading branch information
Showing
25 changed files
with
350 additions
and
261 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
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
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 |
---|---|---|
@@ -1 +1,9 @@ | ||
pytest_plugins = ("tests.fixtures",) | ||
pytest_plugins = ( | ||
# Generic | ||
"tests.fixtures.internal", | ||
"tests.fixtures.logging", | ||
"tests.fixtures.resource", | ||
# | ||
"tests.test_request.fixtures", # request fixtures | ||
"tests.test_formatter.fixtures", # formatter fixtures | ||
) |
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
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,29 @@ | ||
import logging | ||
import re | ||
|
||
import pytest | ||
|
||
import tglogger.formatter | ||
import tglogger.handler | ||
import tglogger.request | ||
|
||
|
||
@pytest.fixture | ||
def telegram_formatter() -> tglogger.formatter.TelegramFormatter: | ||
return tglogger.formatter.TelegramFormatter() | ||
|
||
|
||
@pytest.fixture | ||
def telegram_handler(telegram_formatter) -> tglogger.handler.TelegramHandler: | ||
handler = tglogger.handler.TelegramHandler( | ||
bot_token="1", receiver="2", bypass_auth=True | ||
) | ||
handler.setFormatter(telegram_formatter) | ||
return handler | ||
|
||
|
||
@pytest.fixture | ||
def telegram_logger(telegram_handler, telegram_formatter) -> logging.Logger: | ||
logger = logging.getLogger("test logger") | ||
logger.addHandler(telegram_handler) | ||
return logger |
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
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,11 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def read_test_resource(request): | ||
def factory(file_name: str, mode="r"): | ||
file = open("tests/resources/{}".format(file_name), mode) | ||
request.addfinalizer(lambda: file.close()) | ||
return file | ||
|
||
return factory |
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,9 @@ | ||
{ | ||
"ok": true, | ||
"result": { | ||
"first_name": "Foo", | ||
"id": 1, | ||
"is_bot": true, | ||
"username": "foobot" | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def formatter_message(log_record_factory, telegram_formatter): | ||
log_record = log_record_factory() | ||
return telegram_formatter.format(log_record) |
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,13 @@ | ||
from tglogger import formatter | ||
|
||
|
||
def test_reformat_markdown_safe_underscore(): | ||
example = "foo_bar_baz" | ||
reformatted = formatter.reformat_markdown_safe(example) | ||
assert reformatted == "foo\_bar\_baz" | ||
|
||
|
||
def test_reformat_markdown_safe_asterisk(): | ||
example = "foo*bar*baz" | ||
reformatted = formatter.reformat_markdown_safe(example) | ||
assert reformatted == "foo\*bar\*baz" |
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,45 @@ | ||
import re | ||
|
||
|
||
def test_message_banner_hashtag(formatter_message): | ||
assert "#tglogger" in formatter_message | ||
|
||
|
||
def test_message_uuid(formatter_message): | ||
assert re.search("#[a-z0-9]{32}\n", formatter_message) | ||
|
||
|
||
def test_message_logger_name(formatter_message): | ||
assert "*Logger Name:* example.logger" in formatter_message | ||
|
||
|
||
def test_message_system_date(formatter_message): | ||
assert re.search(r"\*System Date:\* .*\n", formatter_message) | ||
|
||
|
||
def test_message_level(formatter_message): | ||
assert "*Level:* #error" in formatter_message | ||
|
||
|
||
def test_message_path_and_line(formatter_message): | ||
assert "*Path and Line:* _/foo/bar/baz.py_:1" in formatter_message | ||
|
||
|
||
def test_message_function_or_method(formatter_message): | ||
assert "*Function/Method:* _foo\_bar\_baz_" in formatter_message | ||
|
||
|
||
def test_message_thread(formatter_message): | ||
assert re.search( | ||
"\*Thread ID and Name:\* \\\[[0-9]+\] .*\n", formatter_message | ||
) | ||
|
||
|
||
def test_message_process(formatter_message): | ||
assert re.search( | ||
"\*Process ID and Name:\* \\\[[0-9]+\] .*\n", formatter_message | ||
) | ||
|
||
|
||
def test_message_message(formatter_message): | ||
assert "*Message*\n" in formatter_message |
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
Oops, something went wrong.