Skip to content

Commit

Permalink
Fix Flake8 linting warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Delgan committed Jan 20, 2023
1 parent 16dbf79 commit a6fc520
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions tests/test_add_option_catch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


def broken_sink(m):
raise Exception("Error!")
raise ValueError("Error!")


def test_catch_is_true(capsys):
Expand All @@ -23,7 +23,7 @@ def test_catch_is_true(capsys):

def test_catch_is_false(capsys):
logger.add(broken_sink, catch=False)
with pytest.raises(Exception):
with pytest.raises(ValueError, match="Error!"):
logger.debug("Fail")
out, err = capsys.readouterr()
assert out == err == ""
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_broken_sink_message(capsys, enqueue):
assert out == ""
assert lines[0] == "--- Logging error in Loguru Handler #0 ---"
assert re.match(r"Record was: \{.*Oops.*\}", lines[1])
assert lines[-2].startswith("Exception: Error!")
assert lines[-2].startswith("ValueError: Error!")
assert lines[-1] == "--- End of logging error ---"


Expand Down
8 changes: 4 additions & 4 deletions tests/test_filesink_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ def test_exception_during_compression_at_rotation_not_caught(freeze_time, tmp_pa
logger.add(
tmp_path / "test.log",
format="{message}",
compression=Mock(side_effect=[Exception("Compression error"), None]),
compression=Mock(side_effect=[OSError("Compression error"), None]),
rotation=0,
catch=False,
delay=delay,
)
with pytest.raises(Exception, match="Compression error"):
with pytest.raises(OSError, match="Compression error"):
logger.debug("AAA")

frozen.tick()
Expand All @@ -243,13 +243,13 @@ def test_exception_during_compression_at_remove(tmp_path, capsys, delay):
i = logger.add(
tmp_path / "test.log",
format="{message}",
compression=Mock(side_effect=[Exception("Compression error"), None]),
compression=Mock(side_effect=[OSError("Compression error"), None]),
catch=True,
delay=delay,
)
logger.debug("AAA")

with pytest.raises(Exception, match=r"Compression error"):
with pytest.raises(OSError, match=r"Compression error"):
logger.remove(i)

logger.debug("Nope")
Expand Down
8 changes: 4 additions & 4 deletions tests/test_filesink_retention.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,12 @@ def test_exception_during_retention_at_rotation_not_caught(freeze_time, tmp_path
logger.add(
tmp_path / "test.log",
format="{message}",
retention=Mock(side_effect=[Exception("Retention error"), None]),
retention=Mock(side_effect=[OSError("Retention error"), None]),
rotation=0,
catch=False,
delay=delay,
)
with pytest.raises(Exception, match=r"Retention error"):
with pytest.raises(OSError, match=r"Retention error"):
logger.debug("AAA")
frozen.tick()
logger.debug("BBB")
Expand All @@ -327,13 +327,13 @@ def test_exception_during_retention_at_remove(tmp_path, capsys, delay):
i = logger.add(
tmp_path / "test.log",
format="{message}",
retention=Mock(side_effect=[Exception("Retention error"), None]),
retention=Mock(side_effect=[OSError("Retention error"), None]),
catch=False,
delay=delay,
)
logger.debug("AAA")

with pytest.raises(Exception, match=r"Retention error"):
with pytest.raises(OSError, match=r"Retention error"):
logger.remove(i)

logger.debug("Nope")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_filesink_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,12 +900,12 @@ def test_exception_during_rotation(tmp_path, capsys):
def test_exception_during_rotation_not_caught(tmp_path, capsys):
logger.add(
tmp_path / "test.log",
rotation=Mock(side_effect=[Exception("Rotation error"), False]),
rotation=Mock(side_effect=[OSError("Rotation error"), False]),
format="{message}",
catch=False,
)

with pytest.raises(Exception, match=r"Rotation error"):
with pytest.raises(OSError, match=r"Rotation error"):
logger.info("A")

logger.info("B")
Expand Down
8 changes: 4 additions & 4 deletions tests/test_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def write(self, message):
print(message, end="")

def stop(self):
raise Exception("Stop error")
raise OSError("Stop error")


def test_remove_all(tmp_path, writer, capsys):
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_remove_enqueue_filesink(tmp_path):
def test_exception_in_stop_during_remove_one(capsys):
i = logger.add(StopSinkError(), catch=False, format="{message}")
logger.info("A")
with pytest.raises(Exception, match=r"Stop error"):
with pytest.raises(OSError, match=r"Stop error"):
logger.remove(i)
logger.info("Nope")

Expand All @@ -83,12 +83,12 @@ def test_exception_in_stop_not_caught_during_remove_all(capsys):
logger.add(StopSinkError(), catch=False, format="{message}")
logger.add(StopSinkError(), catch=False, format="{message}")

with pytest.raises(Exception, match=r"Stop error"):
with pytest.raises(OSError, match=r"Stop error"):
logger.remove()

logger.info("A")

with pytest.raises(Exception, match=r"Stop error"):
with pytest.raises(OSError, match=r"Stop error"):
logger.remove()

logger.info("Nope")
Expand Down

0 comments on commit a6fc520

Please sign in to comment.