Skip to content

Commit

Permalink
Unit test for log creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
astronomerritt committed May 10, 2024
1 parent 060e67b commit 112b498
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/adler/utilities/test_adler_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import glob
import os
import pytest
import tempfile


def test_setup_adler_logging():
from adler.utilities.adler_logging import setup_adler_logging

with tempfile.TemporaryDirectory() as dir_name:
logger = setup_adler_logging(dir_name)

# Check that the files get created.
errlog = glob.glob(os.path.join(dir_name, "*-adler.err"))
datalog = glob.glob(os.path.join(dir_name, "*-adler.log"))

assert os.path.exists(errlog[0])
assert os.path.exists(datalog[0])

# Log some information.
logger.info("Test1")
logger.info("Test2")
logger.error("Error1")
logger.info("Test3")

# Check that all five lines exist in the INFO file.
with open(datalog[0], "r") as f_info:
log_data = f_info.read()
assert "Test1" in log_data
assert "Test2" in log_data
assert "Error1" in log_data
assert "Test3" in log_data

# Check that only error and critical lines exist in the ERROR file.
with open(errlog[0], "r") as f_err:
log_data = f_err.read()
assert "Test1" not in log_data
assert "Test2" not in log_data
assert "Error1" in log_data
assert "Test3" not in log_data

0 comments on commit 112b498

Please sign in to comment.