Skip to content

Commit

Permalink
feat: Changing the way with tests files in conftest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
a-bouth committed Dec 6, 2024
1 parent 30ce744 commit 7abc315
Show file tree
Hide file tree
Showing 41 changed files with 479 additions and 763 deletions.
27 changes: 0 additions & 27 deletions src/ansys/sound/core/examples_helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,6 @@
Helper functions for managing the PyAnsys Sound example files.
"""

from ._get_example_files import (
get_absolute_path_for_accel_with_rpm_wav,
get_absolute_path_for_fluctuating_noise_wav,
get_absolute_path_for_fluctuating_tone_wav,
get_absolute_path_for_flute2_wav,
get_absolute_path_for_flute_psd_txt,
get_absolute_path_for_flute_wav,
get_absolute_path_for_rough_noise_wav,
get_absolute_path_for_rough_tone_wav,
get_absolute_path_for_sharp_noise_wav,
get_absolute_path_for_sharper_noise_wav,
get_absolute_path_for_xtract_demo_signal_1_wav,
get_absolute_path_for_xtract_demo_signal_2_wav,
)
from .download import (
download_accel_with_rpm_2_wav,
download_accel_with_rpm_3_wav,
Expand All @@ -51,18 +36,6 @@
)

__all__ = (
"get_absolute_path_for_accel_with_rpm_wav",
"get_absolute_path_for_flute2_wav",
"get_absolute_path_for_flute_wav",
"get_absolute_path_for_sharp_noise_wav",
"get_absolute_path_for_sharper_noise_wav",
"get_absolute_path_for_rough_noise_wav",
"get_absolute_path_for_rough_tone_wav",
"get_absolute_path_for_fluctuating_noise_wav",
"get_absolute_path_for_fluctuating_tone_wav",
"get_absolute_path_for_xtract_demo_signal_1_wav",
"get_absolute_path_for_xtract_demo_signal_2_wav",
"get_absolute_path_for_flute_psd_txt",
"download_flute_psd",
"download_flute_wav",
"download_flute_2_wav",
Expand Down
185 changes: 0 additions & 185 deletions src/ansys/sound/core/examples_helpers/_get_example_files.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@

from ansys.dpf.core import (
LicenseContextManager,
ServerConfig,
connect_to_server,
load_library,
server_factory,
start_local_server,
)

Expand Down Expand Up @@ -86,7 +88,10 @@ def connect_to_or_start_server(
**connect_kwargs,
)
else: # pragma: no cover
server = start_local_server(ansys_path=ansys_path)
grpc_config = ServerConfig(
protocol=server_factory.CommunicationProtocols.gRPC, legacy=False
)
server = start_local_server(config=grpc_config, ansys_path=ansys_path, as_global=True)
full_path_dll = os.path.join(server.ansys_path, "Acoustics\\SAS\\ads\\")

required_version = "8.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def method(self) -> int:
def method(self, method: int):
"""Set the sound generation method."""
if method not in [m.value for m in SpectrumSynthesisMethods]:
available_methods = "\n".join(f"{m.value}: {m.name}" for m in SpectrumSynthesisMethods)
raise PyAnsysSoundException(
"Method must be an integer. Available options are:"
f"{"".join(list(f"\n{m.value}: {m.name}" for m in SpectrumSynthesisMethods))}"
"Method must be an integer. Available options are:\n" + available_methods
)
self.__method = method

Expand Down
121 changes: 72 additions & 49 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,62 +22,85 @@

import os

from ansys.dpf.core import (
AvailableServerContexts,
LicenseContextManager,
connect_to_server,
load_library,
)
from ansys.dpf.core import upload_file_in_tmp_folder
import pytest

CONTAINER_SERVER_PORT = 6780
STR_DPF_SOUND = "dpf_sound.dll"
STR_DPF_SOUND_DLL = "dpf_sound.dll"
from ansys.sound.core.server_helpers import connect_to_or_start_server


def pytest_configure():
pytest.data_path_flute_in_container = "C:\\data\\flute.wav"
pytest.data_path_flute2_in_container = "C:\\data\\flute2.wav"
pytest.data_path_flute_nonUnitaryCalib_in_container = "C:\\data\\flute_nonUnitaryCalib.wav"
pytest.data_path_sharp_noise_in_container = "C:\\data\\sharp_noise.wav"
pytest.data_path_sharper_noise_in_container = "C:\\data\\sharper_noise.wav"
pytest.data_path_rough_noise_in_container = "C:\\data\\rough_noise.wav"
pytest.data_path_rough_tone_in_container = "C:\\data\\rough_tone.wav"
pytest.data_path_fluctuating_noise_in_container = "C:\\data\\fluctuating_noise.wav"
pytest.data_path_fluctuating_tone_in_container = "C:\\data\\fluctuating_tone.wav"
pytest.data_path_white_noise_in_container = "C:\\data\\white_noise.wav"
pytest.data_path_accel_with_rpm_in_container = "C:\\data\\accel_with_rpm.wav"
pytest.data_path_flute_psd_in_container = "C:\\data\\flute_psd.txt"
pytest.data_path_swl_project_file_in_container = (
"C:\\data\\SoundPowerLevelProject_hemisphere_2025R1_20243008.spw"
)
pytest.data_path_swl_project_file_with_calibration_in_container = (
"C:\\data\\SoundPowerLevelProject_hemisphere_signalsWithCalibration_2025R1_20240919.spw"
)
pytest.data_path_sound_composer_spectrum_source_in_container = (
"C:\\data\\AnsysSound_Spectrum_v3_-_nominal_-_dBSPLperHz_2024R2_20241121.txt"
)
pytest.data_path_flute_nonUnitaryCalib_as_txt_in_container = (
"C:\\data\\flute_nonUnitaryCalib_as_text_2024R2_20241125.txt"
)
pytest.data_path_rpm_profile_as_wav_in_container = "C:\\data\\RPM_profile_2024R2_20241126.wav"
pytest.data_path_rpm_profile_as_txt_in_container = "C:\\data\\RPM_profile_2024R2_20241126.txt"

# TODO comment
server = connect_to_or_start_server(use_license_context=True)

@pytest.fixture(scope="session")
def dpf_sound_test_server():
port_in_env = os.environ.get("ANSRV_DPF_SOUND_PORT")
if port_in_env is not None:
port = int(port_in_env)
else:
port = CONTAINER_SERVER_PORT
# # Get the current directory of the conftest.py file
base_dir = os.path.dirname(__file__)

# Connecting to server
server = connect_to_server(port=port, context=AvailableServerContexts.premium)
# Construct the paths of the different test files after uploading them on the server
pytest.data_path_flute_in_container = upload_file_in_tmp_folder(
os.path.join(base_dir, "data", "flute.wav"), server=server
)
pytest.data_path_flute2_in_container = upload_file_in_tmp_folder(
os.path.join(base_dir, "data", "flute2.wav"), server=server
)
pytest.data_path_flute_nonUnitaryCalib_in_container = upload_file_in_tmp_folder(
os.path.join(base_dir, "data", "flute_nonUnitaryCalib.wav"), server=server
)
pytest.data_path_sharp_noise_in_container = upload_file_in_tmp_folder(
os.path.join(base_dir, "data", "sharp_noise.wav"), server=server
)
pytest.data_path_sharper_noise_in_container = upload_file_in_tmp_folder(
os.path.join(base_dir, "data", "sharper_noise.wav"), server=server
)
pytest.data_path_rough_noise_in_container = upload_file_in_tmp_folder(
os.path.join(base_dir, "data", "rough_noise.wav"), server=server
)
pytest.data_path_rough_tone_in_container = upload_file_in_tmp_folder(
os.path.join(base_dir, "data", "rough_tone.wav"), server=server
)
pytest.data_path_fluctuating_noise_in_container = upload_file_in_tmp_folder(
os.path.join(base_dir, "data", "fluctuating_noise.wav"), server=server
)
pytest.data_path_fluctuating_tone_in_container = upload_file_in_tmp_folder(
os.path.join(base_dir, "data", "fluctuating_tone.wav"), server=server
)
pytest.data_path_white_noise_in_container = upload_file_in_tmp_folder(
os.path.join(base_dir, "data", "white_noise.wav"), server=server
)
pytest.data_path_accel_with_rpm_in_container = upload_file_in_tmp_folder(
os.path.join(base_dir, "data", "accel_with_rpm.wav"), server=server
)
pytest.data_path_flute_psd_in_container = upload_file_in_tmp_folder(
os.path.join(base_dir, "data", "flute_psd.txt"), server=server
)
pytest.data_path_swl_project_file_in_container = upload_file_in_tmp_folder(
os.path.join(base_dir, "data", "SoundPowerLevelProject_hemisphere_2025R1_20243008.spw"),
server=server,
)
pytest.data_path_swl_project_file_with_calibration_in_container = upload_file_in_tmp_folder(
os.path.join(
base_dir,
"data",
"SoundPowerLevelProject_hemisphere_signalsWithCalibration_2025R1_20240919.spw",
),
server=server,
)
pytest.data_path_sound_composer_spectrum_source_in_container = upload_file_in_tmp_folder(
os.path.join(
base_dir, "data", "AnsysSound_Spectrum_v3_-_nominal_-_dBSPLperHz_2024R2_20241121.txt"
),
server=server,
)

# Initializing licence context manager, will make tests faster by avoiding licenses checkouts
licence_context_manager = LicenseContextManager(increment_name="avrxp_snd_level1")
pytest.data_path_flute_nonUnitaryCalib_as_txt_in_container = upload_file_in_tmp_folder(
os.path.join(base_dir, "data", "flute_nonUnitaryCalib_as_text_2024R2_20241125.txt"),
server=server,
)

# Loading DPF Sound
load_library(STR_DPF_SOUND_DLL, STR_DPF_SOUND)
yield server
pytest.data_path_rpm_profile_as_wav_in_container = upload_file_in_tmp_folder(
os.path.join(base_dir, "data", "RPM_profile_2024R2_20241126.wav"), server=server
)
pytest.data_path_rpm_profile_as_txt_in_container = upload_file_in_tmp_folder(
os.path.join(base_dir, "data", "RPM_profile_2024R2_20241126.txt"), server=server
)
pytest.temporary_folder = os.path.dirname(pytest.data_path_flute_in_container)
Loading

0 comments on commit 7abc315

Please sign in to comment.