From 1b8420b59b95e6432140667d4ac332c0960ee53a Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 20 Jan 2019 15:21:57 +0100 Subject: [PATCH 1/9] coverage: include tests --- .travis.yml | 2 +- tox.ini | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tox.ini diff --git a/.travis.yml b/.travis.yml index 5e63fb7e..532fa689 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ install: - pip install -e .[dev] script: - - pytest --cov loguru/ + - pytest --cov after_success: - codecov --flags "py${TRAVIS_PYTHON_VERSION//./}" diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..cc5dbe8e --- /dev/null +++ b/tox.ini @@ -0,0 +1,6 @@ +[coverage:run] +source = . + +[coverage:report] +include = loguru/*, tests/* + From f6d866b8620cd3706d2b186be457a1f1c14050a1 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 17 Feb 2019 23:48:14 +0100 Subject: [PATCH 2/9] improve test coverage --- tests/test_add_options.py | 4 ++-- tests/test_threading.py | 3 +-- tox.ini | 4 +++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_add_options.py b/tests/test_add_options.py index 35051d7c..21e779f8 100644 --- a/tests/test_add_options.py +++ b/tests/test_add_options.py @@ -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): @@ -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) diff --git a/tests/test_threading.py b/tests/test_threading.py index 82f00517..49b5eec0 100644 --- a/tests/test_threading.py +++ b/tests/test_threading.py @@ -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] diff --git a/tox.ini b/tox.ini index cc5dbe8e..5358a29f 100644 --- a/tox.ini +++ b/tox.ini @@ -3,4 +3,6 @@ source = . [coverage:report] include = loguru/*, tests/* - +exclude_lines = + \#\s*pragma: no cover + ^\s*raise NotImplementedError\b From bf75085513628eb9b9b56f9b8c8a804fe462c944 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 18 Feb 2019 00:30:56 +0100 Subject: [PATCH 3/9] re-raise for full coverage --- tests/exceptions/nested_wrapping.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/exceptions/nested_wrapping.py b/tests/exceptions/nested_wrapping.py index f97b7001..eab1f859 100644 --- a/tests/exceptions/nested_wrapping.py +++ b/tests/exceptions/nested_wrapping.py @@ -28,5 +28,6 @@ def a(x): f(0) except ZeroDivisionError: logger.exception("") + raise except Exception: logger.exception("") From ffa586b5c40cf6149d4d3044bf74df1a074ec368 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 18 Feb 2019 00:32:42 +0100 Subject: [PATCH 4/9] fixup! improve test coverage --- tests/exceptions/enqueue_with_others_handlers.py | 2 -- tests/exceptions/not_enough_arguments.py | 4 ++-- tests/exceptions/too_many_arguments.py | 4 ++-- tests/test_exceptions_formatting.py | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/exceptions/enqueue_with_others_handlers.py b/tests/exceptions/enqueue_with_others_handlers.py index d28ac9f0..81db1918 100644 --- a/tests/exceptions/enqueue_with_others_handlers.py +++ b/tests/exceptions/enqueue_with_others_handlers.py @@ -4,8 +4,6 @@ def check_tb_sink(message): exception = message.record["exception"] - if exception is None: - return assert exception.traceback is not None diff --git a/tests/exceptions/not_enough_arguments.py b/tests/exceptions/not_enough_arguments.py index 007e39d5..77db4a2b 100644 --- a/tests/exceptions/not_enough_arguments.py +++ b/tests/exceptions/not_enough_arguments.py @@ -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) diff --git a/tests/exceptions/too_many_arguments.py b/tests/exceptions/too_many_arguments.py index 93d90828..14689b6b 100644 --- a/tests/exceptions/too_many_arguments.py +++ b/tests/exceptions/too_many_arguments.py @@ -7,11 +7,11 @@ @logger.catch def decorated(): - pass + raise NotImplementedError def not_decorated(): - pass + raise NotImplementedError decorated(1) diff --git a/tests/test_exceptions_formatting.py b/tests/test_exceptions_formatting.py index 0f19f379..012276a6 100644 --- a/tests/test_exceptions_formatting.py +++ b/tests/test_exceptions_formatting.py @@ -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) From 2e6512e02633f623dd92231466e6040f5e594cde Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 18 Feb 2019 00:34:36 +0100 Subject: [PATCH 5/9] Revert "re-raise for full coverage" This reverts commit bf75085513628eb9b9b56f9b8c8a804fe462c944. --- tests/exceptions/nested_wrapping.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/exceptions/nested_wrapping.py b/tests/exceptions/nested_wrapping.py index eab1f859..f97b7001 100644 --- a/tests/exceptions/nested_wrapping.py +++ b/tests/exceptions/nested_wrapping.py @@ -28,6 +28,5 @@ def a(x): f(0) except ZeroDivisionError: logger.exception("") - raise except Exception: logger.exception("") From 87854669325269b65153973306cde98eeb863728 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 18 Feb 2019 00:39:52 +0100 Subject: [PATCH 6/9] fixup! fixup! improve test coverage --- tests/exceptions/output/enqueue_with_others_handlers.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/exceptions/output/enqueue_with_others_handlers.txt b/tests/exceptions/output/enqueue_with_others_handlers.txt index 0a9854d1..8d69512f 100644 --- a/tests/exceptions/output/enqueue_with_others_handlers.txt +++ b/tests/exceptions/output/enqueue_with_others_handlers.txt @@ -1,7 +1,7 @@ Traceback (most recent call last): -> File "tests/exceptions/enqueue_with_others_handlers.py", line 19, in +> File "tests/exceptions/enqueue_with_others_handlers.py", line 17, in 1 / 0 ZeroDivisionError: division by zero From 9cd4e5790f41e57cb48c7685ff2e189c6cfa3515 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 18 Feb 2019 22:29:46 +0100 Subject: [PATCH 7/9] tests/exceptions/nested_wrapping.py --- tests/exceptions/nested_wrapping.py | 7 ++----- tests/exceptions/output/nested_wrapping.txt | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/exceptions/nested_wrapping.py b/tests/exceptions/nested_wrapping.py index f97b7001..3f634474 100644 --- a/tests/exceptions/nested_wrapping.py +++ b/tests/exceptions/nested_wrapping.py @@ -24,9 +24,6 @@ def a(x): try: - try: - f(0) - except ZeroDivisionError: - logger.exception("") -except Exception: + f(0) +except ZeroDivisionError: logger.exception("") diff --git a/tests/exceptions/output/nested_wrapping.txt b/tests/exceptions/output/nested_wrapping.txt index 137c0a9d..05decf41 100644 --- a/tests/exceptions/output/nested_wrapping.txt +++ b/tests/exceptions/output/nested_wrapping.txt @@ -30,7 +30,7 @@ ZeroDivisionError: division by zero Traceback (most recent call last): -> File "tests/exceptions/nested_wrapping.py", line 28, in +> File "tests/exceptions/nested_wrapping.py", line 27, in f(0) └ From 1da9021f12654a2c80adced5d1f368fd608139a5 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 21 Feb 2019 02:20:11 +0100 Subject: [PATCH 8/9] Report to codecov, with different flags for tests. --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 532fa689..efe4e1c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,5 +16,10 @@ script: - 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 From 820e180bafd1d252f1fb66d10eaa5600e478ee76 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 4 Mar 2019 10:51:57 +0100 Subject: [PATCH 9/9] Add config for codecov This could also go into .codecov.yml, or be configured through their UI. Ref: https://docs.codecov.io/docs/codecov-yaml Ref: https://docs.codecov.io/docs/coverage-configuration Ref: https://docs.codecov.io/docs/pull-request-comments --- codecov.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 codecov.yml diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000..8c4ad746 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,10 @@ +coverage: + status: + project: yes + patch: yes + changes: yes + +comment: + layout: "header, diff" + behavior: default + require_changes: no