Skip to content

Commit

Permalink
Added --legacy-connection-setup option to pytest to specifically test…
Browse files Browse the repository at this point in the history
… the old connection method
  • Loading branch information
LucVV committed Jul 19, 2023
1 parent 7921b6f commit f44bc42
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
29 changes: 23 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
def pytest_addoption(parser):
parser.addoption("--extension", action="store_true", help="Connect to Zemax OpticStudio as extension")

parser.addoption("--legacy-connection-setup", action="store_true", help="Use legacy method to setup connection")

parser.addoption("--output-directory", type=Path)


Expand All @@ -22,6 +24,11 @@ def connection_mode(request):
return "extension" if request.config.getoption("--extension") else "standalone"


@pytest.fixture(scope="session")
def legacy_connection_setup(request):
return request.config.getoption("--legacy-connection-setup")


@pytest.fixture(scope="session")
def system_save_file(request):
output_directory = request.config.getoption("--output-directory")
Expand All @@ -34,14 +41,17 @@ def system_save_file(request):


@pytest.fixture(scope="session")
def zos() -> zp.ZOS:
zos = zp.ZOS()
def zos(legacy_connection_setup) -> zp.ZOS:
if not legacy_connection_setup:
zos = zp.ZOS()
else:
zos = zp.ZOS()
zos.wakeup()

return zos


@pytest.fixture
def oss(zos: zp.ZOS, connection_mode) -> zp.zpcore.OpticStudioSystem:
def _oss(zos: zp.ZOS, connection_mode) -> zp.zpcore.OpticStudioSystem:
if connection_mode == "extension":
oss = zos.connect_as_extension(return_primary_system=True)
else:
Expand All @@ -54,8 +64,7 @@ def oss(zos: zp.ZOS, connection_mode) -> zp.zpcore.OpticStudioSystem:
zos.Application.CloseApplication()


@pytest.fixture
def oss_legacy(zos: zp.ZOS, connection_mode) -> zp.zpcore.OpticStudioSystem:
def _oss_legacy(zos: zp.ZOS, connection_mode) -> zp.zpcore.OpticStudioSystem:
if connection_mode == "extension":
connected = zos.connect_as_extension()
else:
Expand All @@ -70,6 +79,14 @@ def oss_legacy(zos: zp.ZOS, connection_mode) -> zp.zpcore.OpticStudioSystem:
zos.Application.CloseApplication()


@pytest.fixture
def oss(zos: zp.ZOS, connection_mode, legacy_connection_setup) -> zp.zpcore.OpticStudioSystem:
if not legacy_connection_setup:
yield from _oss(zos=zos, connection_mode=connection_mode)
else:
yield from _oss_legacy(zos=zos, connection_mode=connection_mode)


@pytest.fixture(scope="session")
def optic_studio_version(zos, connection_mode) -> str:
if connection_mode == "extension":
Expand Down
7 changes: 1 addition & 6 deletions tests/test_zpcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@


@pytest.mark.must_pass
@pytest.mark.parametrize(
"oss_fixture",
["oss_legacy", "oss"],
)
def test_can_connect(oss_fixture, request):
oss = request.getfixturevalue(oss_fixture)
def test_can_connect(oss):
assert oss._System is not None


Expand Down
8 changes: 8 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ labels =
env_list =
format
lint
py39-standalone-legacy-zpcoreonly
py39-standalone
py310-standalone-legacy-zpcoreonly
py310-standalone
py311-standalone-legacy-zpcoreonly
py311-standalone

[testenv]
Expand All @@ -22,6 +25,11 @@ deps = [test]
description = run unit tests on specific Python versions in extension mode
commands = pytest tests --extension {posargs}

[testenv:py3{8,9,10,11}-standalone-legacy-zpcoreonly]
description = run unit tests on specific Python versions in standalone mode with a legacy connection
passenv = *
commands = pytest tests/test_zpcore.py --legacy-connection-setup {posargs}

[testenv:py3{8,9,10,11}-standalone]
description = run unit tests on specific Python versions in standalone mode
passenv = *
Expand Down

0 comments on commit f44bc42

Please sign in to comment.