-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #299 from AstarVienna/dev_master
Release 0.7.1
- Loading branch information
Showing
78 changed files
with
1,419 additions
and
1,277 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
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
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
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 |
---|---|---|
@@ -1,24 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Global configurations for ScopeSim.""" | ||
|
||
from pathlib import Path | ||
import yaml | ||
|
||
from .system_dict import SystemDict | ||
from copy import deepcopy | ||
|
||
from .system_dict import SystemDict, UniqueList | ||
|
||
__pkg_dir__ = Path(__file__).parent | ||
|
||
with open(__pkg_dir__/"defaults.yaml") as f: | ||
dicts = list(yaml.full_load_all(f)) | ||
with (__pkg_dir__ / "defaults.yaml").open(encoding="utf-8") as file: | ||
dicts = list(yaml.full_load_all(file)) | ||
|
||
user_rc_path = Path("~/.scopesim_rc.yaml").expanduser() | ||
if user_rc_path.exists(): | ||
with open(user_rc_path) as f: | ||
dicts.extend(list(yaml.full_load_all(f))) | ||
|
||
__config__ = SystemDict(dicts) | ||
__currsys__ = __config__ | ||
try: | ||
with (Path.home() / ".scopesim_rc.yaml").open(encoding="utf-8") as file: | ||
dicts.extend(list(yaml.full_load_all(file))) | ||
except FileNotFoundError: | ||
pass | ||
|
||
__search_path__ = [__config__["!SIM.file.local_packages_path"], | ||
__pkg_dir__] + __config__["!SIM.file.search_path"] | ||
|
||
# if os.environ.get("READTHEDOCS") == "True" or "F:" in os.getcwd(): | ||
# extra_paths = ["../", "../../", "../../../", "../../../../"] | ||
# __search_path__ = extra_paths + __search_path__ | ||
__config__ = SystemDict(dicts) | ||
__currsys__ = deepcopy(__config__) | ||
|
||
# Order matters! | ||
__search_path__ = UniqueList([ | ||
Path(__config__["!SIM.file.local_packages_path"]).absolute(), | ||
Path(__pkg_dir__).absolute(), | ||
*[Path(pth).absolute() for pth in __config__["!SIM.file.search_path"]], | ||
]) |
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,85 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Global fixtures for pytest.""" | ||
|
||
from pathlib import Path | ||
|
||
import pytest | ||
from unittest.mock import patch | ||
|
||
import scopesim as sim | ||
from scopesim.system_dict import UniqueList | ||
|
||
|
||
MOCK_DIR = Path(__file__).parent / "mocks" | ||
|
||
sim.rc.__currsys__["!SIM.file.error_on_missing_file"] = True | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def mock_dir(): | ||
"""Path to mock directory.""" | ||
return MOCK_DIR | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def mock_path(): | ||
"""Path to mock files.""" | ||
return MOCK_DIR / "files" | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def patch_mock_path(mock_path): | ||
"""Patch __search_path__ with test files mock path. | ||
Use only when needed internally, refer to filenames in tests using full | ||
absolute path (with the help of the mock_path fixture). | ||
""" | ||
with patch("scopesim.rc.__search_path__", [mock_path]): | ||
yield | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def patch_all_mock_paths(mock_dir): | ||
with patch("scopesim.rc.__search_path__", UniqueList([mock_dir])): | ||
patched = {"!SIM.file.local_packages_path": str(mock_dir)} | ||
with patch.dict("scopesim.rc.__config__", patched): | ||
with patch.dict("scopesim.rc.__currsys__", patched): | ||
yield | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def mock_path_yamls(): | ||
"""Path to mock yaml files.""" | ||
return MOCK_DIR / "yamls" | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def mock_path_micado(): | ||
"""Path to MICADO mock files.""" | ||
return MOCK_DIR / "MICADO_SCAO_WIDE" | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def patch_mock_path_micado(mock_path_micado): | ||
"""Patch __search_path__ with MICADO mock path. | ||
Use only when needed internally, refer to filenames in tests using full | ||
absolute path (with the help of the mock_path_micado fixture). | ||
""" | ||
with patch("scopesim.rc.__search_path__", [mock_path_micado]): | ||
yield | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def no_file_error(): | ||
"""Patch currsys to avoid missing file error.""" | ||
patched = {"!SIM.file.error_on_missing_file": False} | ||
with patch.dict("scopesim.rc.__currsys__", patched): | ||
yield | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def protect_currsys(): | ||
"""Prevent modification of global currsys.""" | ||
with patch("scopesim.rc.__currsys__"): | ||
yield |
Oops, something went wrong.