Skip to content

Improve test coverage #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ open-docs:

.PHONY: check-tests
check-tests:
pytest --cov=oqpy -vv --color=yes tests
pytest --cov=oqpy -vv --color=yes tests --cov-fail-under=100

.PHONY: check-citation
check-citation:
Expand Down
8 changes: 4 additions & 4 deletions oqpy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class ExpressionConvertible(Protocol):
"""This is the protocol an object can implement in order to be usable as an expression."""

def _to_oqpy_expression(self) -> HasToAst:
...
... # pragma: no cover


@runtime_checkable
Expand All @@ -352,7 +352,7 @@ class CachedExpressionConvertible(Protocol):
"""

def _to_cached_oqpy_expression(self) -> HasToAst:
...
... # pragma: no cover


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

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

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


AstConvertible = Union[
Expand Down
4 changes: 2 additions & 2 deletions oqpy/control_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def ForIn(
iterator: Iterable[AstConvertible] | range | AstConvertible,
identifier_name: Optional[str],
) -> contextlib._GeneratorContextManager[IntVar]:
...
... # pragma: no cover


@overload
Expand All @@ -96,7 +96,7 @@ def ForIn(
identifier_name: Optional[str],
identifier_type: type[ClassicalVarT],
) -> contextlib._GeneratorContextManager[ClassicalVarT]:
...
... # pragma: no cover


@contextlib.contextmanager
Expand Down
1 change: 1 addition & 0 deletions oqpy/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def __iadd__(self, other: Program) -> Program:
self._state.finalize_if_clause()
self._state.body.extend(other._state.body)
self._state.if_clause = other._state.if_clause
self._state.annotations.extend(other._state.annotations)
self._state.finalize_if_clause()
self.defcals.update(other.defcals)
for name, subroutine_stmt in other.subroutines.items():
Expand Down
9 changes: 5 additions & 4 deletions oqpy/subroutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,17 @@ def increment_variable(int[32] i) {
for argname in argnames[1:]: # arg 0 should be program
if argname not in type_hints:
raise ValueError(f"No type hint provided for {argname} on subroutine {name}.")
elif not issubclass(type_hints[argname], (_ClassicalVar, Qubit)):
raise ValueError(
f"Type hint for {argname} on subroutine {name} is not an oqpy variable type."
)

input_ = inputs[argname] = type_hints[argname](name=argname)

if isinstance(input_, _ClassicalVar):
arguments.append(ast.ClassicalArgument(input_.type, ast.Identifier(argname)))
elif isinstance(input_, Qubit):
arguments.append(ast.QuantumArgument(ast.Identifier(input_.name), None))
else:
raise ValueError(
f"Type hint for {argname} on subroutine {name} is not an oqpy variable type."
)

inner_prog = oqpy.Program()
for input_val in inputs.values():
Expand Down
50 changes: 25 additions & 25 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading