-
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.
- Loading branch information
Chsudeepta
authored and
Chsudeepta
committed
Oct 15, 2024
1 parent
9c1f6c9
commit b378003
Showing
1 changed file
with
13 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,32 @@ | ||
import os, sys | ||
import logging | ||
from ibex_bluesky_core.logger import logger | ||
|
||
LOG_FOLDER = os.path.join("C:\\", "instrument", "var", "logs", "bluesky") | ||
LOG_MESSAGE = "Logging something to test" | ||
LOG_MESSAGE = "Logging something to " | ||
LOG_ENV_PATH = "BLUESKY_LOGS" | ||
LOG_FILE_NAME = "blueskylogs.log" | ||
|
||
def test_GIVEN_logging_is_requested_THEN_the_log_folder_exists(): | ||
def test_GIVEN_logging_is_requested_THEN_handler_is_added(): | ||
this_function_name = sys._getframe( ).f_code.co_name | ||
message = LOG_MESSAGE + this_function_name | ||
# Log invocation. | ||
logger.blueskylogger.info(message); | ||
|
||
if (os.environ.__contains__(LOG_ENV_PATH)): | ||
assert os.path.exists(os.environ[LOG_ENV_PATH]) == False | ||
|
||
if (not os.environ.__contains__(LOG_ENV_PATH)): | ||
assert os.path.exists(LOG_FOLDER) == True | ||
logHandler = None | ||
for handler in logger.blueskylogger.handlers: | ||
if isinstance(handler, logging.handlers.TimedRotatingFileHandler): | ||
logHandler = handler | ||
|
||
def test_GIVEN_logging_is_requested_THEN_the_log_file_exists(): | ||
log_path = LOG_FOLDER | ||
if (os.environ.__contains__(LOG_ENV_PATH)): | ||
log_path = os.environ[LOG_ENV_PATH] | ||
assert handler is not None | ||
assert handler.name == 'timedRotatingFileHandler' | ||
assert handler.when.lower() == 'midnight' | ||
assert handler.baseFilename.endswith(LOG_FILE_NAME) == True | ||
|
||
|
||
|
||
# Log invocation. | ||
this_function_name = sys._getframe( ).f_code.co_name | ||
message = LOG_MESSAGE + this_function_name | ||
logger.blueskylogger.info(message); | ||
|
||
qualified_log_filename = os.path.join(log_path, LOG_FILE_NAME) | ||
assert os.path.exists(qualified_log_filename) == True | ||
|
||
def test_GIVEN_logging_is_requested_THEN_the_log_file_contains_the_message(): | ||
log_path = LOG_FOLDER | ||
if (os.environ.__contains__(LOG_ENV_PATH)): | ||
log_path = os.environ[LOG_ENV_PATH] | ||
|
||
# Log invocation. | ||
this_function_name = sys._getframe( ).f_code.co_name | ||
message = LOG_MESSAGE + this_function_name | ||
logger.blueskylogger.info(message); | ||
|
||
qualified_log_filename = os.path.join(log_path, LOG_FILE_NAME) | ||
assert os.path.exists(qualified_log_filename) == True | ||
# Open the log file and read its content. | ||
with open(qualified_log_filename, 'r') as f: | ||
content = f.read() | ||
assert content.__contains__(message); | ||
|