From 776ae9c339cdd44c06a4b08824923cf06520fe4f Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Tue, 24 Sep 2024 09:05:16 -0700 Subject: [PATCH] Add str value for TargetProfile --- pip/src/interpreter.rs | 13 +++++++++++++ pip/tests/test_qsharp.py | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/pip/src/interpreter.rs b/pip/src/interpreter.rs index b4bd7387f0..8aa35b04db 100644 --- a/pip/src/interpreter.rs +++ b/pip/src/interpreter.rs @@ -110,6 +110,19 @@ pub(crate) enum TargetProfile { Unrestricted, } +#[pymethods] +#[allow(clippy::trivially_copy_pass_by_ref)] +impl TargetProfile { + fn __str__(&self) -> String { + match self { + TargetProfile::Base => "Base", + TargetProfile::Adaptive_RI => "Adaptive_RI", + TargetProfile::Unrestricted => "Unrestricted", + } + .to_owned() + } +} + impl From for Profile { fn from(profile: TargetProfile) -> Self { match profile { diff --git a/pip/tests/test_qsharp.py b/pip/tests/test_qsharp.py index f4d57c3ec0..9d7cf906f3 100644 --- a/pip/tests/test_qsharp.py +++ b/pip/tests/test_qsharp.py @@ -331,3 +331,15 @@ def test_run_with_invalid_shots_produces_error() -> None: assert str(e) == "The number of shots must be greater than 0." else: assert False + + +def test_target_profile_str_values_match_enum_values() -> None: + target_profile = qsharp.TargetProfile.Base + str_value = str(target_profile) + assert str_value == "Base" + target_profile = qsharp.TargetProfile.Adaptive_RI + str_value = str(target_profile) + assert str_value == "Adaptive_RI" + target_profile = qsharp.TargetProfile.Unrestricted + str_value = str(target_profile) + assert str_value == "Unrestricted"