-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### 背景 > 描述这个 Pull Request 之前代码的状态 ### 目标 > 描述这个 Pull Request 要完成的功能 ### 其他信息 > 描述这个 Pull Request 相关的其他信息
- Loading branch information
1 parent
41fa3de
commit 86318b9
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Python | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
|
||
jobs: | ||
build_and_test_python: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.9" | ||
|
||
# 以下步骤将在 3kctl 目录下执行 | ||
- name: Change to 3kctl directory | ||
run: cd 3kctl | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
working-directory: 3kctl | ||
|
||
- name: Lint with flake8 | ||
run: | | ||
pip install flake8 | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
working-directory: 3kctl | ||
|
||
- name: Test with pytest | ||
run: | | ||
pip install pytest | ||
pytest | ||
working-directory: 3kctl | ||
|
||
- name: Test with coverage | ||
run: | | ||
pip install pytest-cov | ||
pytest --cov=./ --cov-report=xml | ||
working-directory: 3kctl | ||
|
||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
file: ./coverage.xml | ||
fail_ci_if_error: true | ||
verbose: true | ||
working-directory: 3kctl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import unittest | ||
from unittest.mock import mock_open, patch | ||
from .utils import dict_to_obj, parse_yaml, parse_ini | ||
|
||
|
||
class TestDictToObj(unittest.TestCase): | ||
|
||
def test_dict_to_obj(self): | ||
test_dict = {"a": 1, "b": 2} | ||
obj = dict_to_obj(test_dict) | ||
self.assertEqual(obj.a, 1) | ||
self.assertEqual(obj.b, 2) | ||
|
||
|
||
class TestParseYaml(unittest.TestCase): | ||
|
||
@patch("builtins.open", new_callable=mock_open, read_data="a: 1\nb: 2") | ||
def test_parse_yaml(self, mock_file): | ||
result = parse_yaml() | ||
self.assertEqual(result.a, 1) | ||
self.assertEqual(result.b, 2) | ||
|
||
|
||
class TestParseIni(unittest.TestCase): | ||
|
||
@patch("builtins.open", new_callable=mock_open, read_data="[section]\nkey=value") | ||
def test_parse_ini(self, mock_file): | ||
config = parse_ini() | ||
self.assertEqual(config.section.key, 'value') | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |