microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
iadavis/pipeline-issue-debugging

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/pip/tests/test_enums.py

106lines · modecode

1# Copyright (c) Microsoft Corporation.
2# Licensed under the MIT License.
3
4from textwrap import dedent
5import pytest
6import qsharp
7import qsharp.code
8import qsharp.utils
9from contextlib import redirect_stdout
10import io
11
12from qsharp import TargetProfile
13# pull in from native module for tests so that we don't have to install qiskit
14# using the interop module
15from qsharp._native import OutputSemantics, ProgramType
16
17
18def test_target_profile_int_values_match_enum_values() -> None:
19 assert 0 == TargetProfile.Base
20 assert 1 == TargetProfile.Adaptive_RI
21 assert 2 == TargetProfile.Adaptive_RIF
22 assert 3 == TargetProfile.Unrestricted
23
24
25def test_target_profile_serialization() -> None:
26 input = [
27 TargetProfile.Base,
28 TargetProfile.Adaptive_RI,
29 TargetProfile.Adaptive_RIF,
30 TargetProfile.Unrestricted,
31 ]
32 import pickle
33
34 ser = pickle.dumps(input)
35 de = pickle.loads(ser)
36 assert de == input
37
38
39def test_target_profile_str_values_match_enum_values() -> None:
40 target_profile = TargetProfile.Base
41 str_value = str(target_profile)
42 assert str_value == "Base"
43 target_profile = TargetProfile.Adaptive_RI
44 str_value = str(target_profile)
45 assert str_value == "Adaptive_RI"
46 target_profile = TargetProfile.Adaptive_RIF
47 str_value = str(target_profile)
48 assert str_value == "Adaptive_RIF"
49 target_profile = TargetProfile.Unrestricted
50 str_value = str(target_profile)
51 assert str_value == "Unrestricted"
52
53
54def test_target_profile_from_str_match_enum_values() -> None:
55 target_profile = TargetProfile.Base
56 str_value = str(target_profile)
57 assert TargetProfile.from_str(str_value) == target_profile
58 target_profile = TargetProfile.Adaptive_RI
59 str_value = str(target_profile)
60 assert TargetProfile.from_str(str_value) == target_profile
61 target_profile = TargetProfile.Adaptive_RIF
62 str_value = str(target_profile)
63 assert TargetProfile.from_str(str_value) == target_profile
64 target_profile = TargetProfile.Unrestricted
65 str_value = str(target_profile)
66 assert TargetProfile.from_str(str_value) == target_profile
67 with pytest.raises(ValueError):
68 TargetProfile.from_str("Invalid")
69
70
71def test_output_semantics_int_values_match_enum_values() -> None:
72 assert 0 == OutputSemantics.Qiskit
73 assert 1 == OutputSemantics.OpenQasm
74 assert 2 == OutputSemantics.ResourceEstimation
75
76
77def test_output_semantics_serialization() -> None:
78 input = [
79 OutputSemantics.Qiskit,
80 OutputSemantics.OpenQasm,
81 OutputSemantics.ResourceEstimation,
82 ]
83 import pickle
84
85 ser = pickle.dumps(input)
86 de = pickle.loads(ser)
87 assert de == input
88
89
90def test_program_type_int_values_match_enum_values() -> None:
91 assert 0 == ProgramType.File
92 assert 1 == ProgramType.Operation
93 assert 2 == ProgramType.Fragments
94
95
96def test_program_type_serialization() -> None:
97 input = [
98 ProgramType.File,
99 ProgramType.Operation,
100 ProgramType.Fragments,
101 ]
102 import pickle
103
104 ser = pickle.dumps(input)
105 de = pickle.loads(ser)
106 assert de == input
107