예제 #1
0
def test_actual_emails(eml: Path, monkeypatch: pytest.MonkeyPatch) -> None:
    with eml.open("rb") as fp:
        msg = email.message_from_binary_file(fp, policy=policy.default)
    monkeypatch.syspath_prepend(EMAIL_DIR)
    module: Any = import_module(eml.stem)
    assert email2dict(msg) == module.data
    assert email2dict(msg, include_all=True) == module.data_all
예제 #2
0
def test_actual_mboxes(mbox: Path, monkeypatch: pytest.MonkeyPatch) -> None:
    box = mailbox.mbox(mbox)
    box.lock()
    (msg, ) = box
    box.close()
    monkeypatch.syspath_prepend(MBOX_DIR)
    module: Any = import_module(mbox.stem)
    assert email2dict(msg) == module.data
    assert email2dict(msg, include_all=True) == module.data_all
예제 #3
0
 def test_set_app_module_custom(
     self,
     app_module_tmp_path: Path,
     module: str,
     mocker: MockerFixture,
     monkeypatch: pytest.MonkeyPatch,
 ) -> None:
     """Test `start.set_app_module` with custom module path."""
     logger = mocker.patch.object(start.logging, "root", autospec=True)
     monkeypatch.syspath_prepend(app_module_tmp_path)
     monkeypatch.setenv("APP_MODULE", f"tmp_app.main_{module}:app")
     start.set_app_module(logger=logger)
     assert mocker.call(f"App module set to tmp_app.main_{module}:app.")
예제 #4
0
def test_get_template_path_file_in_syspath(tmp_path: Path,
                                           monkeypatch: MonkeyPatch) -> None:
    """Verify get_template_path with a file in sys.path.

    This ensures templates are able to be retrieved from remote packages.

    """
    template_path = tmp_path / "cfn_template.json"
    template_path.touch()

    monkeypatch.syspath_prepend(tmp_path)
    result = get_template_path(Path(template_path.name))
    assert template_path.samefile(cast(Path, result))
예제 #5
0
 def test_configure_logging_tmp_module(
     self,
     logging_conf_tmp_file_path: Path,
     mocker: MockerFixture,
     monkeypatch: pytest.MonkeyPatch,
 ) -> None:
     """Test logging configuration with temporary logging config path."""
     logger = mocker.patch.object(logging_conf.logging,
                                  "root",
                                  autospec=True)
     monkeypatch.syspath_prepend(logging_conf_tmp_file_path)
     monkeypatch.setenv("LOGGING_CONF", "tmp_log")
     assert os.getenv("LOGGING_CONF") == "tmp_log"
     logging_conf.configure_logging(logger=logger, logging_conf="tmp_log")
     logger.debug.assert_called_once_with(
         "Logging dict config loaded from tmp_log.")
예제 #6
0
 def test_configure_logging_tmp_module_no_dict(
     self,
     logging_conf_tmp_path_no_dict: Path,
     mocker: MockerFixture,
     monkeypatch: pytest.MonkeyPatch,
 ) -> None:
     """Test logging configuration with temporary logging config path.
     - Correct module name
     - No `LOGGING_CONFIG` object
     """
     logger = mocker.patch.object(logging_conf.logging,
                                  "root",
                                  autospec=True)
     monkeypatch.syspath_prepend(logging_conf_tmp_path_no_dict)
     monkeypatch.setenv("LOGGING_CONF", "no_dict")
     logger_error_msg = "Error when setting logging module"
     attribute_error_msg = "No LOGGING_CONFIG in no_dict"
     assert os.getenv("LOGGING_CONF") == "no_dict"
     with pytest.raises(AttributeError):
         logging_conf.configure_logging(logger=logger,
                                        logging_conf="no_dict")
     logger.error.assert_called_once_with(
         f"{logger_error_msg}: AttributeError {attribute_error_msg}.")
예제 #7
0
 def test_configure_logging_tmp_module_incorrect_type(
     self,
     logging_conf_tmp_path_incorrect_type: Path,
     mocker: MockerFixture,
     monkeypatch: pytest.MonkeyPatch,
 ) -> None:
     """Test logging configuration with temporary logging config path.
     - Correct module name
     - `LOGGING_CONFIG` object with incorrect type
     """
     logger = mocker.patch.object(logging_conf.logging,
                                  "root",
                                  autospec=True)
     monkeypatch.syspath_prepend(logging_conf_tmp_path_incorrect_type)
     monkeypatch.setenv("LOGGING_CONF", "incorrect_type")
     logger_error_msg = "Error when setting logging module"
     type_error_msg = "LOGGING_CONFIG is not a dictionary instance"
     assert os.getenv("LOGGING_CONF") == "incorrect_type"
     with pytest.raises(TypeError):
         logging_conf.configure_logging(logger=logger,
                                        logging_conf="incorrect_type")
     logger.error.assert_called_once_with(
         f"{logger_error_msg}: TypeError {type_error_msg}.")