Skip to content

Commit 895d072

Browse files
Improve test coverage (#74)
* increase test coverage * set test failure when less than 100% * update cryptography to 41.0.4 * complete test coverage for program.py * complete test coverage for base.py * simplify tests
1 parent 70bc029 commit 895d072

File tree

7 files changed

+125
-43
lines changed

7 files changed

+125
-43
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ open-docs:
3737

3838
.PHONY: check-tests
3939
check-tests:
40-
pytest --cov=oqpy -vv --color=yes tests
40+
pytest --cov=oqpy -vv --color=yes tests --cov-fail-under=100
4141

4242
.PHONY: check-citation
4343
check-citation:

oqpy/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class ExpressionConvertible(Protocol):
337337
"""This is the protocol an object can implement in order to be usable as an expression."""
338338

339339
def _to_oqpy_expression(self) -> HasToAst:
340-
...
340+
... # pragma: no cover
341341

342342

343343
@runtime_checkable
@@ -352,7 +352,7 @@ class CachedExpressionConvertible(Protocol):
352352
"""
353353

354354
def _to_cached_oqpy_expression(self) -> HasToAst:
355-
...
355+
... # pragma: no cover
356356

357357

358358
class OQPyUnaryExpression(OQPyExpression):
@@ -365,7 +365,7 @@ def __init__(self, op: ast.UnaryOperator, exp: AstConvertible):
365365
if isinstance(exp, OQPyExpression):
366366
self.type = exp.type
367367
else:
368-
raise TypeError("exp is an expression")
368+
raise TypeError("exp is not an expression")
369369

370370
def to_ast(self, program: Program) -> ast.UnaryExpression:
371371
"""Converts the OQpy expression into an ast node."""
@@ -447,7 +447,7 @@ class HasToAst(Protocol):
447447

448448
def to_ast(self, program: Program) -> ast.Expression:
449449
"""Converts the OQpy object into an ast node."""
450-
...
450+
... # pragma: no cover
451451

452452

453453
AstConvertible = Union[

oqpy/control_flow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def ForIn(
8686
iterator: Iterable[AstConvertible] | range | AstConvertible,
8787
identifier_name: Optional[str],
8888
) -> contextlib._GeneratorContextManager[IntVar]:
89-
...
89+
... # pragma: no cover
9090

9191

9292
@overload
@@ -96,7 +96,7 @@ def ForIn(
9696
identifier_name: Optional[str],
9797
identifier_type: type[ClassicalVarT],
9898
) -> contextlib._GeneratorContextManager[ClassicalVarT]:
99-
...
99+
... # pragma: no cover
100100

101101

102102
@contextlib.contextmanager

oqpy/program.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def __iadd__(self, other: Program) -> Program:
128128
self._state.finalize_if_clause()
129129
self._state.body.extend(other._state.body)
130130
self._state.if_clause = other._state.if_clause
131+
self._state.annotations.extend(other._state.annotations)
131132
self._state.finalize_if_clause()
132133
self.defcals.update(other.defcals)
133134
for name, subroutine_stmt in other.subroutines.items():

oqpy/subroutines.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,17 @@ def increment_variable(int[32] i) {
100100
for argname in argnames[1:]: # arg 0 should be program
101101
if argname not in type_hints:
102102
raise ValueError(f"No type hint provided for {argname} on subroutine {name}.")
103+
elif not issubclass(type_hints[argname], (_ClassicalVar, Qubit)):
104+
raise ValueError(
105+
f"Type hint for {argname} on subroutine {name} is not an oqpy variable type."
106+
)
107+
103108
input_ = inputs[argname] = type_hints[argname](name=argname)
104109

105110
if isinstance(input_, _ClassicalVar):
106111
arguments.append(ast.ClassicalArgument(input_.type, ast.Identifier(argname)))
107112
elif isinstance(input_, Qubit):
108113
arguments.append(ast.QuantumArgument(ast.Identifier(input_.name), None))
109-
else:
110-
raise ValueError(
111-
f"Type hint for {argname} on subroutine {name} is not an oqpy variable type."
112-
)
113114

114115
inner_prog = oqpy.Program()
115116
for input_val in inputs.values():

poetry.lock

Lines changed: 25 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)