Skip to content

Commit

Permalink
add test demo
Browse files Browse the repository at this point in the history
  • Loading branch information
jlcoo committed Sep 6, 2024
1 parent 0d3a3d9 commit 50c964c
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/checkut.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ jobs:
- name: Run tox
# Run tox using the version of Python in `PATH`
run: tox -e py
- name: Run tox coverage
run: tox -e coverage
Empty file added easypackages/__init__.py
Empty file.
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
from specrepair import SpecBot
import sys
import os
import shutil
import sys

from specrepair import SpecBot

# 参数说明:specFile
# specFilePath:.spec源文件路径,必输
# logFilePath:日志文件路径,必输
# repairSpecFIlePath: .spec文件修复后的路径,必输
# suggestionPath:ai建议保存路径,必输

# 设置环境变量
os.environ['OPENAI_API_KEY'] = 'xxxxxxx'
os.environ['OPENAI_BASE_URL'] = 'xxxxx'
os.environ["OPENAI_API_KEY"] = "xxxxxxx"
os.environ["OPENAI_BASE_URL"] = "xxxxx"

print("Ai repair spec begin ...")

if len(sys.argv) != 6:
print('error argumengs num [{}]'.format(len(sys.argv)))
print("error argumengs num [{}]".format(len(sys.argv)))
for i in sys.argv:
print(i)
sys.exit(1)
Expand Down Expand Up @@ -53,11 +54,12 @@
os.makedirs(path)

specbot = SpecBot()
suggestion, flag = specbot.repair(spec_src_file, log_src_file,
spec_repair_file, ai_log_file)
suggestion, flag = specbot.repair(
spec_src_file, log_src_file, spec_repair_file, ai_log_file
)

# 打开文件用于写入,如果文件不存在则创建
with open(suggestion_file, 'w') as file:
with open(suggestion_file, "w") as file:
# 将字符串写入文件
file.write(suggestion)

Expand Down
Empty file.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions easypackages/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def add(x, y):
return x + y


def subtract(x, y):
return x - y


def multiply(x, y):
return x * y


def divide(x, y):
if y == 0:
raise ValueError("Cannot divide by zero!")
return x / y
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# setup.py
from setuptools import setup, find_packages

setup(
name="easypackages",
version="0.1",
packages=find_packages(),
install_requires=[],
)
Empty file added tests/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions tests/test_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# tests/test_calculator.py

import pytest

from easypackages.demo import add, divide, multiply, subtract


def test_add():
assert add(3, 5) == 8
assert add(-1, 1) == 0


def test_subtract():
assert subtract(10, 5) == 5
assert subtract(-1, -1) == 0


def test_multiply():
assert multiply(3, 5) == 15
assert multiply(-1, 5) == -5


def test_divide():
assert divide(10, 2) == 5
assert divide(10, 5) == 2

with pytest.raises(ValueError):
divide(10, 0)
37 changes: 37 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[tox]
envlist = py38, py39, py310, py311, lint, coverage

[testenv]
deps =
pytest
pytest-cov
requests
mock
commands =
pytest tests/ --cov=easypackages --cov-report=term-missing

[testenv:lint]
deps =
flake8
black
isort
commands =
flake8 easypackages/ tests/
black --check easypackages/ tests/
isort --check-only easypackages/ tests/

[testenv:coverage]
deps =
coverage
commands =
coverage report --fail-under=22 # 将阈值设置为80%
coverage html

[testenv:format]
description = "Auto-format the code using black and isort"
deps =
black
isort
commands =
black easypackages/ tests/
isort easypackages/ tests/

0 comments on commit 50c964c

Please sign in to comment.