Skip to content

Commit

Permalink
test: enforce 100 percent test coverage on project (#136)
Browse files Browse the repository at this point in the history
* test: enforce 100 percent project cov

* more cov

* test safe_eval

* test: more coverage
  • Loading branch information
tlambert03 committed Oct 31, 2023
1 parent a401890 commit b7a5262
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ coverage:
patch:
default:
target: 100%
project:
default:
target: 100%
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ exclude_lines = [
"if TYPE_CHECKING:",
"@overload",
"except ImportError",
"return NotImplemented",
"pass",
]
skip_covered = true
Expand Down
1 change: 0 additions & 1 deletion src/app_model/backends/qt/_qmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ def rebuild(
)

def _on_about_to_show(self) -> None:
# this would also be a reasonable place to call
for action in self.actions():
if isinstance(action, QCommandRuleAction):
action._refresh()
Expand Down
3 changes: 3 additions & 0 deletions tests/test_command_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def test_commands_registry() -> None:
reg.register_command("my.id", lambda: 42, "My Title")
assert "(1 commands)" in repr(reg)
assert "my.id" in str(reg)
assert "my.id" in reg
with pytest.raises(KeyError, match="my.id2"):
reg["my.id2"]

with pytest.raises(ValueError, match="Command 'my.id' already registered"):
reg.register_command("my.id", lambda: 42, "My Title")
Expand Down
3 changes: 3 additions & 0 deletions tests/test_context/test_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def test_comparison():
def test_iter_names():
expr = "a if b in c else d > e"
a = parse_expression(expr)
assert a is parse_expression(a)
b = Expr.parse(expr) # alias
assert sorted(_iter_names(a)) == ["a", "b", "c", "d", "e"]
assert sorted(_iter_names(b)) == ["a", "b", "c", "d", "e"]
Expand Down Expand Up @@ -225,6 +226,8 @@ def test_safe_eval():
assert safe_eval(expr, {"x": 3}) is True
assert safe_eval(expr, {"x": 10}) is False
assert safe_eval(expr, {"x": 1}) == 3
assert safe_eval(True) is True
assert safe_eval(False) is False

with pytest.raises(SyntaxError, match="Type 'Call' not supported"):
safe_eval("func(x)")
Expand Down
3 changes: 2 additions & 1 deletion tests/test_qt/test_qmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_menu(
) -> None:
app = full_app

menu = MenuCls(app.Menus.EDIT, app)
menu = MenuCls(app.Menus.EDIT, app, title="just-for-coverage")
qtbot.addWidget(menu)

# The "" are separators, according to our group settings in full_app
Expand Down Expand Up @@ -81,6 +81,7 @@ def test_submenu(qtbot: QtBot, full_app: FullApp) -> None:
submenu.setVisible(True)
assert submenu.isVisible()
assert submenu.isEnabled()
menu.aboutToShow.emit() # for test coverage

# "not something_open" is the when clause
# "friday" is the enablement clause
Expand Down

0 comments on commit b7a5262

Please sign in to comment.