Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage: include tests #39

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ install:
- pip install -e .[dev]

script:
- pytest --cov loguru/
- pytest --cov

after_success:
- codecov --flags "py${TRAVIS_PYTHON_VERSION//./}"
# Report to codecov, with different flags for tests.
- coverage xml --include 'loguru/*'
- codecov -f coverage.xml --flags loguru "py${TRAVIS_PYTHON_VERSION//./}" --disable search gcov pycov
- coverage xml --include 'tests/*'
- codecov -f coverage.xml --flags tests "py${TRAVIS_PYTHON_VERSION//./}" --disable search gcov pycov

- cd docs && make html
10 changes: 10 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
coverage:
status:
project: yes
patch: yes
changes: yes

comment:
layout: "header, diff"
behavior: default
require_changes: no
2 changes: 0 additions & 2 deletions tests/exceptions/enqueue_with_others_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

def check_tb_sink(message):
exception = message.record["exception"]
if exception is None:
return
assert exception.traceback is not None


Expand Down
7 changes: 2 additions & 5 deletions tests/exceptions/nested_wrapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ def a(x):


try:
try:
f(0)
except ZeroDivisionError:
logger.exception("")
except Exception:
f(0)
except ZeroDivisionError:
logger.exception("")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The outer exception is not covered, but tests fail with this.
I think that might indicate some missing test (i.e. you want to also test the exception being re-raised / another exception being caught in the outer block).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the whole nested try blocks could be removed. This is not testing anything useful. Previously these test cases were generated automatically through some kind of template strings. This is no longer the case, I did not realize I could remove it.

4 changes: 2 additions & 2 deletions tests/exceptions/not_enough_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

@logger.catch
def decorated(x, y, z):
pass
raise NotImplementedError


def not_decorated(x, y, z):
pass
raise NotImplementedError


decorated(1)
Expand Down
2 changes: 1 addition & 1 deletion tests/exceptions/output/enqueue_with_others_handlers.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Traceback (most recent call last):

> File "tests/exceptions/enqueue_with_others_handlers.py", line 19, in <module>
> File "tests/exceptions/enqueue_with_others_handlers.py", line 17, in <module>
1 / 0

ZeroDivisionError: division by zero
2 changes: 1 addition & 1 deletion tests/exceptions/output/nested_wrapping.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ZeroDivisionError: division by zero

Traceback (most recent call last):

> File "tests/exceptions/nested_wrapping.py", line 28, in <module>
> File "tests/exceptions/nested_wrapping.py", line 27, in <module>
f(0)
└ <function f at 0xDEADBEEF>

Expand Down
4 changes: 2 additions & 2 deletions tests/exceptions/too_many_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

@logger.catch
def decorated():
pass
raise NotImplementedError


def not_decorated():
pass
raise NotImplementedError


decorated(1)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_add_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def test_disabled_logger_in_sink(sink_with_logger):

def test_invalid_function_kwargs():
def function(message, a="Y"):
pass
raise NotImplementedError

logger.add(function, b="X", catch=False)
with pytest.raises(TypeError):
Expand All @@ -384,7 +384,7 @@ def __init__(self):
self.out = ""

def write(self, m):
pass
raise NotImplementedError

writer = Writer()
logger.add(writer, format="{message}", kw1="1", kw2="2", catch=False)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_exceptions_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def normalize(formatted_exception):
return formatted_exception


def generate(output, outpath):
def generate(output, outpath): # pragma: no cover
"""Generate new output file if exception formatting is updated"""
with open(outpath, "w") as file:
file.write(output)
Expand Down
3 changes: 1 addition & 2 deletions tests/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def __init__(self, sleep_time):
self.stopped = False

def write(self, message):
if self.stopped:
raise RuntimeError("Can't write on stopped sink")
assert not self.stopped

length = len(message)
self.written += message[:length]
Expand Down
8 changes: 8 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[coverage:run]
source = .

[coverage:report]
include = loguru/*, tests/*
exclude_lines =
\#\s*pragma: no cover
^\s*raise NotImplementedError\b