Attempt to bypass getcwd errors in CI with patch

This commit is contained in:
Micah Jerome Ellison 2023-05-01 16:34:54 -07:00
parent e0288bd6b2
commit 39e7dc91ee

View file

@ -12,15 +12,17 @@ from jrnl.editor import read_template_file
from jrnl.exception import JrnlException
@patch("os.getcwd", side_effect="/") # prevent failures in CI if current directory has been deleted
@patch("builtins.open", side_effect=FileNotFoundError())
def test_read_template_file_with_no_file_raises_exception(mock_open):
def test_read_template_file_with_no_file_raises_exception(mock_open, mock_getcwd):
with pytest.raises(JrnlException) as ex:
read_template_file("invalid_file.txt")
assert isinstance(ex.value, JrnlException)
@patch("os.getcwd", side_effect="/") # prevent failures in CI if current directory has been deleted
@patch("builtins.open", new_callable=mock_open, read_data="template text")
def test_read_template_file_with_valid_file_returns_text(mock_file):
def test_read_template_file_with_valid_file_returns_text(mock_file, mock_getcwd):
assert read_template_file("valid_file.txt") == "template text"