Skip to content

Commit

Permalink
Revert "point to the correct file and function"
Browse files Browse the repository at this point in the history
This reverts commit 5714949.
  • Loading branch information
niketagrawal committed Aug 19, 2024
1 parent 5714949 commit 6e448a3
Showing 1 changed file with 26 additions and 42 deletions.
68 changes: 26 additions & 42 deletions aeolis/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
To run an specific test, use:
- If in a group:
pytest aeolis/tests/test_utils.py::<TestClass>::<test-method>
- If not in any group:
pytest aeolis/tests/test_utils.py::<test-function>
"""

import logging
import pytest
import numpy as np
from aeolis.model import (
StreamFormatter,
ModelState,
AeoLiSRunner,
)
from aeolis.model import (StreamFormatter,
ModelState,
AeoLiSRunner,
)


class TestStreamFormatter:
Expand All @@ -35,32 +34,20 @@ def test_stream_formatter_parent(self):
"""Test if the stream formatter inherits from the logging.Formatter class"""
stream_formatter = StreamFormatter()
assert isinstance(stream_formatter, logging.Formatter)

def test_stream_formatter_info_level(self):
"""Test if stream formatter change the formatting of log records based on
their level name."""
"""Test if stream formatter change the formatting of log records based on
their level name."""
logger = logging.getLogger("Test")

info_record = logger.makeRecord(
"Test",
logging.INFO,
"Test",
1,
"This is a message for INFO level",
None,
None,
)

warning_record = logger.makeRecord(
"Test warning",
logging.WARNING,
"Test",
2,
"This is a message for WARNING level",
None,
None,
)

info_record = logger.makeRecord("Test", logging.INFO,
"Test", 1, "This is a message for INFO level",
None, None)

warning_record = logger.makeRecord("Test warning", logging.WARNING,
"Test", 2, "This is a message for WARNING level",
None, None)

stream_formatter = StreamFormatter()
info_message = stream_formatter.format(info_record)
warning_message = stream_formatter.format(warning_record)
Expand All @@ -79,7 +66,7 @@ def test_model_initialization(self):
assert isinstance(state, ModelState)

def test_set_variable_and_value(self):
"""Test if the model state class can set a variable and value, and
"""Test if the model state class can set a variable and value, and
it is added to the set of mutable variables
"""
state = ModelState(args=None, kwargs=None)
Expand All @@ -90,43 +77,40 @@ def test_set_variable_and_value(self):

def test_variable_is_set_as_mutable(self):
"""Test if a variable in the model stated is added to
the mutable set
"""
the mutable set
"""
state = ModelState(args=None, kwargs=None)
state.__setitem__("variable1", 2)

state.set_mutable("variable2")
assert "variable2" in state.ismutable

def test_variable_is_set_as_immutable(self):
"""Test if a variable in the model stated is removed from
the mutable set
"""
"""
state = ModelState(args=None, kwargs=None)
state.__setitem__("variable1", 3)

state.set_immutable("variable2")
assert "variable2" not in state.ismutable


class TestAeoLiSRunner:
"""Test AeoLiSRunner class"""

def test_parse_callback_from_module(self):
"""Test if the callback function can be loaded from a file"""
runner = AeoLiSRunner("aeolis/tests/aeolis.txt")
callback = runner.parse_callback(
"aeolis/tests/callback_example.py:mock_callback"
)
runner = AeoLiSRunner("aeolis.txt")
callback = runner.parse_callback("callback_example.py:mock_callback")
assert callable(callback)
assert callback.__name__ == "mock_callback"
assert callback() == True


def test_parse_callback_invalid_callback(self):
"""Test if the parser raises error when path to callback file does not exist"""
runner = AeoLiSRunner("aeolis/tests/aeolis.txt")
with pytest.raises(IOError) as excinfo:
callback = runner.parse_callback(
"aeolis/tests/invalid_file.py:mock_callback"
)
callback = runner.parse_callback("aeolis/tests/invalid_file.py:mock_callback")
assert "Check definition in input file" in str(excinfo.value)

0 comments on commit 6e448a3

Please sign in to comment.