Skip to content

Commit

Permalink
Merge pull request #186 from BBN-Q/f.185.detect-bad-qwait-kind
Browse files Browse the repository at this point in the history
if the "kind" is unknown, raise an exception
  • Loading branch information
Diego Ristè committed Jan 30, 2019
2 parents 946bac7 + 70ae571 commit 22fe0bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion QGL/ControlFlow.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ def qwait(kind="TRIG", addr=None, channels=None):
return LoadCmp(channels)
elif kind == "RAM":
if addr is None:
raise Exception('Please specify address')
raise ValueError('Please specify addr')
return [WriteAddrInstruction('INVALIDATE', None, 1, addr, 0xffffffff, False), LoadCmpVramInstruction('LOADCMPVRAM', 1, addr, 0xff, False)]

raise ValueError('Unknown kind parameter [%s]' % str(kind))


def qsync(channels=None):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_ControlFlow.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ def test_qwait(self):
assert (isinstance(seq1[2][0], TdmInstructions.WriteAddrInstruction))
assert (isinstance(seq1[2][1], TdmInstructions.LoadCmpVramInstruction))

def test_qwait_err(self):
q1 = self.q1
with self.assertRaises(ValueError) as exc:
seq1 = [qwait(kind='FOO')]
exc_str = str(exc.exception)
assert (exc_str == 'Unknown kind parameter [FOO]')

with self.assertRaises(ValueError) as exc:
seq1 = [qwait(kind='RAM')]
exc_str = str(exc.exception)
assert (exc_str == 'Please specify addr')

# test the legal values
seq1 = [qwait(kind='TRIG')]
seq1 = [qwait(kind='CMP')]
seq1 = [qwait(kind='RAM', addr=0xff)]

def test_compile(self):
q1 = self.q1
seq1 = [X90(q1), Y90(q1)]
Expand Down

0 comments on commit 22fe0bd

Please sign in to comment.