-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf470d3
commit 8ea3517
Showing
2 changed files
with
62 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import importlib | ||
from unittest.mock import mock_open, patch | ||
|
||
import pytest | ||
|
||
|
||
def test_version_loading(): | ||
mock_toml_content = """ | ||
[project] | ||
version = "1.0.0" | ||
""" | ||
|
||
with patch("pathlib.Path.open", mock_open(read_data=mock_toml_content)): | ||
with patch("tomllib.load") as mock_load: | ||
mock_load.return_value = {"project": {"version": "1.0.0"}} | ||
|
||
import djpress | ||
|
||
importlib.reload(djpress) # Reload the module to apply the mock | ||
|
||
assert djpress.__version__ == "1.0.0" | ||
|
||
|
||
def test_version_loading_error(): | ||
with patch("pathlib.Path.open", mock_open()) as mock_file: | ||
mock_file.side_effect = FileNotFoundError() | ||
|
||
with pytest.raises(FileNotFoundError): | ||
import djpress | ||
|
||
importlib.reload(djpress) # Reload the module to apply the mock | ||
|
||
|
||
def test_tomllib_import_error(): | ||
mock_toml_content = """ | ||
[project] | ||
version = "1.0.0" | ||
""" | ||
|
||
with patch.dict("sys.modules", {"tomllib": None}): | ||
with patch("pathlib.Path.open", mock_open(read_data=mock_toml_content)): | ||
with patch("tomli.load") as mock_load: | ||
mock_load.return_value = {"project": {"version": "1.0.0"}} | ||
|
||
import djpress | ||
|
||
importlib.reload(djpress) # Reload the module to apply the mock | ||
|
||
assert djpress.__version__ == "1.0.0" |