Best Python code snippet using pandera_python
test_decoder.py
Source:test_decoder.py
...76 assert isinstance(item2, list)77 _compare_list(item1, item2)78 elif isinstance(item1, dict):79 assert isinstance(item2, dict)80 _compare_dict(item1, item2)81 else:82 assert item1 == item283def _compare_dict(d1, d2):84 for k1 in d1:85 assert k1 in d286 v1 = d1[k1]87 v2 = d2[k1]88 if isinstance(v1, list):89 assert isinstance(v2, list)90 elif isinstance(v1, dict):91 assert isinstance(v2, dict)92 _compare_dict(v1, v2)93 else:94 assert v1 == v295target = {96 "name": "damnever",97 "age": [21, 22],98 21: True,99 22: False,100 None: "null",101 True: {102 "www": "github",103 },104 "negative": -123.456,105}106JSON_STR = r"""107{108 "name": "damnever",109 "age": [21, 22],110 21: true,111 22: false,112 null: "null",113 true: {114 "www": "github",115 },116 "negative": -123.456,117}118"""119def test_loads():120 data = loads(JSON_STR)121 _compare_dict(target, data)122def test_load():123 path = os.path.join(os.path.dirname(__file__), 'data.txt')124 with open(path, 'rb') as f:125 data = load(f)...
test_skip_qobj_validation.py
Source:test_skip_qobj_validation.py
...14from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister15from qiskit import BasicAer16from test.common import QiskitAquaTestCase17from qiskit.aqua import QuantumInstance18def _compare_dict(dict1, dict2):19 equal = True20 for key1, value1 in dict1.items():21 if key1 not in dict2:22 equal = False23 break24 if value1 != dict2[key1]:25 equal = False26 break27 return equal28class TestSkipQobjValidation(QiskitAquaTestCase):29 def setUp(self):30 super().setUp()31 self.random_seed = 1059832 qr = QuantumRegister(2)33 cr = ClassicalRegister(2)34 qc = QuantumCircuit(qr, cr)35 qc.h(qr[0])36 qc.cx(qr[0], qr[1])37 # Ensure qubit 0 is measured before qubit 138 qc.barrier(qr)39 qc.measure(qr[0], cr[0])40 qc.barrier(qr)41 qc.measure(qr[1], cr[1])42 self.qc = qc43 self.backend = BasicAer.get_backend('qasm_simulator')44 def test_wo_backend_options(self):45 quantum_instance = QuantumInstance(self.backend, seed_transpiler=self.random_seed,46 seed_simulator=self.random_seed, shots=1024, circuit_caching=False)47 # run without backend_options and without noise48 res_wo_bo = quantum_instance.execute(self.qc).get_counts(self.qc)49 quantum_instance.skip_qobj_validation = True50 res_wo_bo_skip_validation = quantum_instance.execute(self.qc).get_counts(self.qc)51 self.assertTrue(_compare_dict(res_wo_bo, res_wo_bo_skip_validation))52 def test_w_backend_options(self):53 # run with backend_options54 quantum_instance = QuantumInstance(self.backend, seed_transpiler=self.random_seed,55 seed_simulator=self.random_seed, shots=1024,56 backend_options={'initial_statevector': [.5, .5, .5, .5]},57 circuit_caching=False)58 res_w_bo = quantum_instance.execute(self.qc).get_counts(self.qc)59 quantum_instance.skip_qobj_validation = True60 res_w_bo_skip_validation = quantum_instance.execute(self.qc).get_counts(self.qc)61 self.assertTrue(_compare_dict(res_w_bo, res_w_bo_skip_validation))62 def test_w_noise(self):63 # build noise model64 # Asymetric readout error on qubit-0 only65 try:66 from qiskit.providers.aer.noise import NoiseModel67 from qiskit import Aer68 self.backend = Aer.get_backend('qasm_simulator')69 except Exception as e:70 self.skipTest("Aer doesn't appear to be installed. Error: '{}'".format(str(e)))71 return72 probs_given0 = [0.9, 0.1]73 probs_given1 = [0.3, 0.7]74 noise_model = NoiseModel()75 noise_model.add_readout_error([probs_given0, probs_given1], [0])76 quantum_instance = QuantumInstance(self.backend, seed_transpiler=self.random_seed,77 seed_simulator=self.random_seed, shots=1024,78 noise_model=noise_model,79 circuit_caching=False)80 res_w_noise = quantum_instance.execute(self.qc).get_counts(self.qc)81 quantum_instance.skip_qobj_validation = True82 res_w_noise_skip_validation = quantum_instance.execute(self.qc).get_counts(self.qc)83 self.assertTrue(_compare_dict(res_w_noise, res_w_noise_skip_validation))84if __name__ == '__main__':...
check_rewowr_container_config.py
Source:check_rewowr_container_config.py
...9from rewowr.public.interfaces.container_interface_config import \10 get_rewowr_container_interface_config11from rewowr.public.interfaces.re_wr_interface_config import get_rewowr_re_wr_interface_config12from rewowr.public.interfaces.work_interface_config import get_rewowr_work_interface_config13def _compare_dict(local_dict: Dict, rewowr_dict: Dict, /) -> None:14 for key_name in local_dict.keys():15 if key_name in rewowr_dict:16 raise CheckReWoWrContainerConfigError(17 f"The key {key_name} was found in the ReWoWr dictionary!"18 )19def check_rewowr_container_config(config: ConfigContainer, /) -> None:20 _compare_dict(21 work_config(config.net_container, config.connection_container),22 get_rewowr_work_interface_config()23 )24 _compare_dict(re_wr_config(config.plotter), get_rewowr_re_wr_interface_config())25 _compare_dict(26 container_config().container_dict, get_rewowr_container_interface_config().container_dict...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!