Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull changes from LUMC GitLab (custom dir for Analysis objects) #68

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ ZOS-API can also be added in patch releases.

### Changed

- Custom `__dir__` method for `zospy.analyses.base.Analysis`.
`dir` now shows both the wrapper members and the OpticStudio analysis members (!56)

### Deprecated

### Removed
Expand Down
23 changes: 23 additions & 0 deletions tests/analyses/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pandas as pd
import pytest

import zospy.api.constants as constants
from zospy.analyses.base import (
AnalysisMessage,
AnalysisMetadata,
Expand All @@ -12,6 +13,7 @@
OnComplete,
_AnalysisResultJSONDecoder,
_AnalysisResultJSONEncoder,
new_analysis,
)


Expand Down Expand Up @@ -110,3 +112,24 @@ def test_restore_datetime(self):

assert isinstance(restored_datetime, datetime)
assert restored_datetime == test_datetime


def test_analysis_wrapper_dir(oss):
opticstudio_analysis_attributes = [
"GetSettings",
"GetResults",
"IsRunning",
"Apply",
"ApplyAndWaitForCompletion",
"Terminate",
"WaitForCompletion",
"Close",
"Release",
"ToFile",
]

analysis = new_analysis(oss, analysis_type=constants.Analysis.AnalysisIDM.RayFan)

# Assert for each attribute separately, but in a single test so `oss` does not need to be recreated for every case.
for attribute in opticstudio_analysis_attributes:
assert attribute in dir(analysis)
3 changes: 3 additions & 0 deletions zospy/analyses/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,9 @@ def set_surface(self, value: int | str):
def __getattr__(self, item):
return getattr(self._analysis, item)

def __dir__(self):
return sorted(set(super().__dir__()).union(dir(self._analysis)))


def new_analysis(
oss: OpticStudioSystem, analysis_type: constants.Analysis.AnalysisIDM, settings_first: bool = True
Expand Down
Loading