Skip to content

Commit

Permalink
TST: patch logger in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mj-will committed Nov 8, 2024
1 parent 2efdea5 commit 27528be
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions test/gw/detector/psd_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import os
import unittest
from unittest import mock
Expand All @@ -7,10 +6,6 @@

import bilby

import pytest

pytest.skip("Skip this test file", allow_module_level=True)


class TestPowerSpectralDensityWithoutFiles(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -200,33 +195,25 @@ def test_from_aligo(self):
self.assertTrue(np.allclose(expected.psd_array, psd.psd_array, atol=1e-60))
self.assertTrue(np.array_equal(expected.asd_array, psd.asd_array))

def test_check_file_psd_file_set_to_asd_file(self):
logger = logging.getLogger("bilby")
m = mock.MagicMock()
logger.warning = m
@mock.patch.object(bilby.gw.detector.psd.logger, "warning")
def test_check_file_psd_file_set_to_asd_file(self, mock_warning):
_ = bilby.gw.detector.PowerSpectralDensity(psd_file=self.asd_file)
self.assertEqual(4, m.call_count)
self.assertEqual(4, mock_warning.call_count)

def test_check_file_not_called_psd_file_set_to_psd_file(self):
logger = logging.getLogger("bilby")
m = mock.MagicMock()
logger.warning = m
@mock.patch.object(bilby.gw.detector.psd.logger, "warning")
def test_check_file_not_called_psd_file_set_to_psd_file(self, mock_warning):
_ = bilby.gw.detector.PowerSpectralDensity(psd_file=self.psd_file)
self.assertEqual(0, m.call_count)
self.assertEqual(0, mock_warning.call_count)

def test_check_file_asd_file_set_to_psd_file(self):
logger = logging.getLogger("bilby")
m = mock.MagicMock()
logger.warning = m
@mock.patch.object(bilby.gw.detector.psd.logger, "warning")
def test_check_file_asd_file_set_to_psd_file(self, mock_warning):
_ = bilby.gw.detector.PowerSpectralDensity(asd_file=self.psd_file)
self.assertEqual(4, m.call_count)
self.assertEqual(4, mock_warning.call_count)

def test_check_file_not_called_asd_file_set_to_asd_file(self):
logger = logging.getLogger("bilby")
m = mock.MagicMock()
logger.warning = m
@mock.patch.object(bilby.gw.detector.psd.logger, "warning")
def test_check_file_not_called_asd_file_set_to_asd_file(self, mock_warning):
_ = bilby.gw.detector.PowerSpectralDensity(asd_file=self.asd_file)
self.assertEqual(0, m.call_count)
self.assertEqual(0, mock_warning.call_count)

def test_from_frame_file(self):
expected_frequency_array = np.array([1.0, 2.0, 3.0])
Expand Down

0 comments on commit 27528be

Please sign in to comment.