-
Notifications
You must be signed in to change notification settings - Fork 890
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
Showing
11 changed files
with
301 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2024 Flower Labs GmbH. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
"""Flower Logger tests.""" | ||
|
||
|
||
import sys | ||
from queue import Queue | ||
|
||
from .logger import mirror_output_to_queue, restore_output | ||
|
||
|
||
def test_mirror_output_to_queue() -> None: | ||
"""Test that stdout and stderr are mirrored to the provided queue.""" | ||
# Prepare | ||
log_queue: Queue[str] = Queue() | ||
|
||
# Execute | ||
mirror_output_to_queue(log_queue) | ||
print("Test message") | ||
sys.stderr.write("Error message\n") | ||
|
||
# Assert | ||
assert not log_queue.empty() | ||
assert log_queue.get() == "Test message" | ||
assert log_queue.get() == "\n" | ||
assert log_queue.get() == "Error message\n" | ||
|
||
|
||
def test_restore_output() -> None: | ||
"""Test that stdout and stderr are restored after calling restore_output.""" | ||
# Prepare | ||
log_queue: Queue[str] = Queue() | ||
|
||
# Execute | ||
mirror_output_to_queue(log_queue) | ||
print("Test message before restore") | ||
restore_output() | ||
print("Test message after restore") | ||
sys.stderr.write("Error message after restore\n") | ||
|
||
# Assert | ||
assert log_queue.get() == "Test message before restore" | ||
assert log_queue.get() == "\n" | ||
assert log_queue.empty() |
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
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.