Skip to content

Commit

Permalink
try to fix test error
Browse files Browse the repository at this point in the history
  • Loading branch information
BjornFJohansson committed Apr 22, 2024
1 parent c18015b commit 6bbfdfc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 13 deletions.
4 changes: 2 additions & 2 deletions run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def main():
"--cov-report=xml",
"--capture=no",
"--durations=10",
"--import-mode=importlib",
# "--import-mode=importlib",
"--nbval",
"--current-env",
"--doctest-modules",
Expand All @@ -44,7 +44,7 @@ def main():
"--cov-report=xml",
"--capture=no",
"--durations=10",
"--import-mode=importlib",
# "--import-mode=importlib",
"--nbval",
"--current-env",
"--doctest-modules",
Expand Down
72 changes: 61 additions & 11 deletions tests/test_module_myenzymes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,13 @@ def test_myenzymes(monkeypatch):
assert len(list(myenzymes.myenzymes)) == 628


def test_file_not_exist(monkeypatch, caplog):
monkeypatch.setenv("pydna_enzymes", "file_that_does_not_exist.txt")
from pydna import myenzymes
from importlib import reload

reload(myenzymes)
assert len(list(myenzymes.myenzymes)) == 0
record = next(iter(caplog.records))
assert len(caplog.records) == 1
assert record.levelno == logging.WARNING
assert record.message == "file_that_does_not_exist.txt not found."


def test_file_is_folder(monkeypatch, caplog):
monkeypatch.setenv("pydna_enzymes", "subfolder")
from pydna import myenzymes
from importlib import reload

reload(myenzymes)
assert len(list(myenzymes.myenzymes)) == 0
assert len(caplog.records) == 1
Expand All @@ -44,6 +33,19 @@ def test_file_is_folder(monkeypatch, caplog):
assert record.message == "subfolder is a directory."


def test_file_not_exist(monkeypatch, caplog):
monkeypatch.setenv("pydna_enzymes", "file_that_does_not_exist.txt")
from pydna import myenzymes
from importlib import reload

reload(myenzymes)
assert len(list(myenzymes.myenzymes)) == 0
record = next(iter(caplog.records))
assert len(caplog.records) == 1
assert record.levelno == logging.WARNING
assert record.message == "file_that_does_not_exist.txt not found."


def test_IOError(monkeypatch, caplog):
from io import StringIO

Expand Down Expand Up @@ -90,5 +92,53 @@ def test_Exception(monkeypatch, caplog):
assert "Exception" in record.message


# def test_IOError(monkeypatch, caplog):
# monkeypatch = pytest.MonkeyPatch()
# monkeypatch.setenv("pydna_enzymes", "my_test_enzymes.txt")
# from pydna import myenzymes
# from importlib import reload
# reload(myenzymes)
# from io import StringIO
# from unittest.mock import patch
# from unittest.mock import mock_open

# with patch("myenzymes.open") as mocked_open:
# mocked_open.side_effect = IOError()
# mocked_open.return_value = StringIO("BamHI")
# from pydna import myenzymes
# from importlib import reload
# reload(myenzymes)

# assert len(list(myenzymes.myenzymes)) == 0
# assert len(caplog.records) == 1
# record = next(iter(caplog.records))
# assert record.levelno == logging.WARNING
# assert record.message == "my_test_enzymes.txt found, but could not be read."

# def test_Exception(monkeypatch, caplog):
# monkeypatch.setenv("pydna_enzymes", "my_test_enzymes.txt")
# from pydna import myenzymes
# from importlib import reload
# reload(myenzymes)
# from io import StringIO
# from pydna import myenzymes
# from unittest.mock import patch
# from unittest.mock import mock_open

# with patch("pydna.myenzymes.open") as mocked_open:
# mocked_open.side_effect = Exception()
# mocked_open.return_value = StringIO("BamHI")
# from pydna import myenzymes
# from importlib import reload

# reload(myenzymes)

# assert len(list(myenzymes.myenzymes)) == 0
# assert len(caplog.records) == 1
# record = next(iter(caplog.records))
# assert record.levelno == logging.WARNING
# assert "Exception" in record.message


if __name__ == "__main__":
pytest.main([__file__, "-vv", "-s"])

0 comments on commit 6bbfdfc

Please sign in to comment.