Skip to content

Commit

Permalink
Break a test
Browse files Browse the repository at this point in the history
  • Loading branch information
pblowey committed Aug 13, 2024
1 parent 01ec830 commit 6a3e474
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tests/test_internals.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
from unittest.mock import mock_open, patch

from pymca_zocalo.internals import find_cut_off_energy
import tempfile
from pytest import raises
from unittest.mock import patch, mock_open


@patch("pymca_zocalo.internals.open")
def test_GIVEN_input_file_not_found_WHEN_find_cut_off_energy_called_THEN_raises_exception(mock_open):
def test_GIVEN_input_file_not_found_WHEN_find_cut_off_energy_called_THEN_raises_exception(
mock_open,
):
mock_open.side_effect = FileNotFoundError()
with raises(FileNotFoundError):
find_cut_off_energy("test_file_name", 0)


@patch("pymca_zocalo.internals.open", new_callable=mock_open, read_data="1 0")
def test_GIVEN_energy_of_1_and_cutoff_of_0_WHEN_find_cut_off_energy_called_THEN_returns_1(mock_file):
def test_GIVEN_energy_of_1_and_cutoff_of_0_WHEN_find_cut_off_energy_called_THEN_returns_1(
mock_file,
):
line_of_greater_energy = find_cut_off_energy("test_file_name", 0)
assert line_of_greater_energy == 0
assert line_of_greater_energy == 1


@patch("pymca_zocalo.internals.open")
def test_different_energies(mock_file):
Expand All @@ -31,9 +36,10 @@ def test_file_has_non_floats_different_energies(mock_file):
line_of_greater_energy = find_cut_off_energy("test_file_name", 2)
assert line_of_greater_energy == 1


@patch("pymca_zocalo.internals.open")
def test_file_nothing_in_then_gives_none(mock_file):
test_data = ""
mock_open(mock_file, read_data=test_data)
line_of_greater_energy = find_cut_off_energy("test_file_name", 2)
assert line_of_greater_energy == None
assert line_of_greater_energy is None

0 comments on commit 6a3e474

Please sign in to comment.