Skip to content

Commit

Permalink
Add str value for TargetProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
idavis committed Sep 24, 2024
1 parent ffadd7e commit 776ae9c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pip/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TargetProfile> for Profile {
fn from(profile: TargetProfile) -> Self {
match profile {
Expand Down
12 changes: 12 additions & 0 deletions pip/tests/test_qsharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 776ae9c

Please sign in to comment.