Skip to content

Commit

Permalink
Python: added code coverage and vscode tasks def for python (microsof…
Browse files Browse the repository at this point in the history
…t#4193)

### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
To improve the code and PR quality I want to add code coverage to the
dev dependencies, and setup. I then also added tasks into the python
folder for both the pre-commit config and running unit tests with code
coverage. Fixes microsoft#3980

Initially I excluded code coverage for all connectors, that needs to be
refined and this can also be added to the GH actions once we have it
setup well.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
  • Loading branch information
eavanvalkenburg authored and BR committed Oct 6, 2024
1 parent 3d8f0d6 commit c56dab7
Show file tree
Hide file tree
Showing 6 changed files with 303 additions and 86 deletions.
21 changes: 21 additions & 0 deletions python/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[run]
source = semantic_kernel
omit =
semantic_kernel/connectors/*

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain about missing debug-only code:
def __repr__

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# TYPE_CHECKING and @overload blocks are never executed during pytest run
if TYPE_CHECKING:
@overload
4 changes: 3 additions & 1 deletion python/.vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// See https://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"littlefoxteam.vscode-python-test-adapter"
"littlefoxteam.vscode-python-test-adapter",
"streetsidesoftware.code-spell-checker",
"ms-python.python",
]
}
37 changes: 32 additions & 5 deletions python/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
{
"python.analysis.extraPaths": [
"./src"
"./semantic_kernel"
],
"explorer.compactFolders": false,
"prettier.enable": true,
"editor.formatOnType": true,
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"python.formatting.provider": "black",
"python.formatting.autopep8Args": [
"--max-line-length=160"
],
"editor.defaultFormatter": "charliermarsh.ruff",
"notebook.output.textLineLimit": 500,
"cSpell.languageSettings": [
{
"languageId": "py",
"allowCompoundWords": true,
"locale": "en-US"
}
],
"cSpell.words": [
"aeiou",
"nopep",
"OPENAI",
"skfunction"
],
"cSpell.patterns": [
{
"name": "import",
"pattern": "import [a-zA-Z0-9_]+"
},
{
"name": "from import",
"pattern": "from [a-zA-Z0-9_]+ import [a-zA-Z0-9_]+"
}
],
"python.testing.pytestArgs": [
"tests"
],
Expand All @@ -29,4 +43,17 @@
"run",
"pytest"
],
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.fixAll": "explicit"
},
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff",
},
"notebook.formatOnSave.enabled": true,
"notebook.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
}
}
94 changes: 94 additions & 0 deletions python/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Python: Run Checks",
"type": "shell",
"command": "poetry",
"args": [
"run",
"pre-commit",
"run",
"-c",
".conf/.pre-commit-config.yaml",
"-a"
],
"problemMatcher": {
"owner": "python",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4
}
},
"presentation": {
"reveal": "silent",
"panel": "shared"
}
},
{
"label": "Python: Install",
"type": "shell",
"command": "poetry",
"args": [
"install"
],
"presentation": {
"reveal": "silent",
"panel": "shared"
},
"problemMatcher": []
},
{
"label": "Python: Tests - Unit",
"type": "shell",
"command": "poetry",
"args": [
"run",
"pytest",
"tests/unit/"
],
"group": "test",
"presentation": {
"reveal": "always",
"panel": "shared"
},
"problemMatcher": []
},
{
"label": "Python: Tests - Code Coverage",
"type": "shell",
"command": "poetry run pytest --cov=semantic_kernel --cov-report term-missing tests/unit/",
"group": "test",
"presentation": {
"reveal": "always",
"panel": "shared"
},
"problemMatcher": []
},
{
"label": "Python: Tests - All",
"type": "shell",
"command": "poetry",
"args": [
"run",
"pytest",
"tests/"
],
"group": "test",
"presentation": {
"reveal": "always",
"panel": "shared"
},
"problemMatcher": []
}
]
}
Loading

0 comments on commit c56dab7

Please sign in to comment.