"""Tests for the logging helper functions.""" from unittest.mock import patch from abacus_common_logic.utils.log import log @patch('abacus_common_logic.utils.log.g') def test_log(mock_g): """Test logging when `g.log` is available.""" log('info', 'test', resources={'test': 'test'}) mock_g.log.info.assert_called_once_with('test', resources={'test': 'test'}) @patch('abacus_common_logic.utils.log.g') def test_log_unavailable(mock_g): """Test logging when `g.log` is not available.""" del mock_g.log try: log('info', 'test', resources={'test': 'test'}) except AttributeError: # If the code would attempt to access the non-exsiting `g.log` object # it would trigger an `AttributeError`, in that case we want the test to fail assert False @patch('abacus_common_logic.utils.log.g') def test_log_invalid_level(mock_g): """Test logging when an invalid level is passed.""" del mock_g.log.invalid try: log('invalid', 'test') except AttributeError: # If the code would attempt to access the non-exsiting `g.log.invalid` method # it would trigger an `AttributeError`, in that case we want the test to fail assert False