Skip to content

Commit f7b1b85

Browse files
committed
Add instructions for tests and demonstration
1 parent 452e7a9 commit f7b1b85

File tree

6 files changed

+235
-1
lines changed

6 files changed

+235
-1
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# v1.2.3
2+
3+
![](https://img.shields.io/badge/Version-v1.2.3-green)
4+
5+
## 🌟 Add
6+
7+
- `docs/README.md`: instructions for docs, provide some tool suggestions to help you quickly build your own document.
8+
- `tests/README.md`: instructions for testing, provide the whole procedure of testing.
9+
- `examples/demo.ipynb`: provide an example of how to demonstrate your project.
10+
11+
## 🗑️ Delete
12+
13+
- `docs/.gitkeep`
14+
- `tests/.gitkeep`
15+
- `examples/.gitkeep`
16+
17+
---
18+
119
# v1.2.2
220

321
![](https://img.shields.io/badge/Version-v1.2.2-green)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## 📦 A Project Template for Self-developed Python Package
22

3-
![Package Version](https://img.shields.io/badge/Version-v1.2.2-green)
3+
[![Package Version](https://img.shields.io/badge/Version-v1.2.3-green)](https://github.com/Ahzyuan/Python-package-template/releases/tag/v1.2.3)
44
[![License](https://img.shields.io/badge/License-MIT-khaki)](https://opensource.org/license/MIT)
55
![Pypi Template](https://img.shields.io/badge/PyPI-Package_pattern-yellow?logo=pypi&labelColor=%23FAFAFA)
66

examples/.gitkeep

Whitespace-only changes.

examples/demo.ipynb

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Demonstrate your project here\n",
8+
"\n",
9+
"- With `Jupyter Notebook`, you can showcase your project, including code, results and visualizations.\n",
10+
"\n",
11+
"- `Jupyter Notebook` can save the running results of code blocks, including output text, images, tables, etc.\n",
12+
"\n",
13+
"- Therefore, if your project has rich outputs, you can show the correct operation method and its effect of your project here."
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": null,
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"# --------------------- Below is an example ---------------------"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": null,
28+
"metadata": {},
29+
"outputs": [
30+
{
31+
"name": "stdout",
32+
"output_type": "stream",
33+
"text": [
34+
"Looking in indexes: https://test.pypi.org/simple\n",
35+
"Collecting patest\n",
36+
" Using cached https://test-files.pythonhosted.org/packages/c5/1f/83a14b343305c5c0a453f49d1ce7d160bd542734109e1796918caf8c91d1/patest-1.0.0-py3-none-any.whl.metadata (6.9 kB)\n",
37+
"Requirement already satisfied: isort in /home/hzy/.conda/envs/hzy_env/lib/python3.12/site-packages (from patest) (4.3.21)\n",
38+
"Using cached https://test-files.pythonhosted.org/packages/c5/1f/83a14b343305c5c0a453f49d1ce7d160bd542734109e1796918caf8c91d1/patest-1.0.0-py3-none-any.whl (6.4 kB)\n",
39+
"Installing collected packages: patest\n",
40+
"Successfully installed patest-1.0.0\n",
41+
"Note: you may need to restart the kernel to use updated packages.\n"
42+
]
43+
}
44+
],
45+
"source": [
46+
"# Note: the `patest` here is a simple package created by myself\n",
47+
"# that only use for this demo.\n",
48+
"%pip install patest -i https://test.pypi.org/simple"
49+
]
50+
},
51+
{
52+
"cell_type": "code",
53+
"execution_count": 1,
54+
"metadata": {},
55+
"outputs": [
56+
{
57+
"name": "stdout",
58+
"output_type": "stream",
59+
"text": [
60+
"Greetings, dear Sir Ahzyuan!\n",
61+
"Greetings, dear Sir Ahzyuan!\n",
62+
"Greetings, dear Sir Ahzyuan!\n",
63+
"None\n"
64+
]
65+
}
66+
],
67+
"source": [
68+
"# This is an example of calling the `patest` api in code.\n",
69+
"\n",
70+
"from patest import greet\n",
71+
"\n",
72+
"print(greet(name='Ahzyuan',\n",
73+
" gender='masculine',\n",
74+
" knight=True,\n",
75+
" count=3))"
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": null,
81+
"metadata": {},
82+
"outputs": [
83+
{
84+
"name": "stdout",
85+
"output_type": "stream",
86+
"text": [
87+
"Greetings, dear Ms. Ahzyuan!\n",
88+
"Greetings, dear Ms. Ahzyuan!\n",
89+
"Greetings, dear Ms. Ahzyuan!\n"
90+
]
91+
}
92+
],
93+
"source": [
94+
"# This is an example of calling the `patest` command-line tool.\n",
95+
"\n",
96+
"!patest Ahzyuan --gender feminine --count 3"
97+
]
98+
}
99+
],
100+
"metadata": {
101+
"kernelspec": {
102+
"display_name": "hzy_env",
103+
"language": "python",
104+
"name": "python3"
105+
},
106+
"language_info": {
107+
"codemirror_mode": {
108+
"name": "ipython",
109+
"version": 3
110+
},
111+
"file_extension": ".py",
112+
"mimetype": "text/x-python",
113+
"name": "python",
114+
"nbconvert_exporter": "python",
115+
"pygments_lexer": "ipython3",
116+
"version": "3.12.4"
117+
}
118+
},
119+
"nbformat": 4,
120+
"nbformat_minor": 2
121+
}

tests/.gitkeep

Whitespace-only changes.

tests/README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Testing your project
2+
3+
> This directory is used to store the testing code for the project.
4+
5+
- Testing your Python projects is an important job to ensure code quality, stability and performance.
6+
7+
- However, given that the implementation details and testing requirements varying from project to project, we can not provide a universal pattern for code testing.
8+
9+
- But, we will provide the whole procedure of testing here. Hope it will be helpful for you. ✨
10+
11+
---
12+
13+
<details>
14+
<summary>① 𝐓𝐞𝐬𝐭𝐢𝐧𝐠 𝐩𝐫𝐞𝐩𝐚𝐫𝐚𝐭𝐢𝐨𝐧</summary>
15+
16+
1. 𝗗𝗲𝗳𝗶𝗻𝗲 𝗼𝗯𝗷𝗲𝗰𝘁𝗶𝘃𝗲𝘀 𝗼𝗳 𝘁𝗲𝘀𝘁𝗶𝗻𝗴
17+
18+
- 🧪 **Functional testing**: Verify whether each function works as expected.
19+
- 📊 **Performance testing**: Evaluate project performance under load (response time, throughput, etc.).
20+
- 🧩 **Compatibility test**: Check project performance on different Python versions.
21+
- 🔬 *For projects involving databases, network communications, etc., additional safety tests may be needed to ensure user safety.*
22+
23+
2. 𝗣𝗿𝗲𝗽𝗮𝗿𝗲 𝘁𝗲𝘀𝘁𝗶𝗻𝗴 𝗱𝗮𝘁𝗮
24+
25+
- 📈 **Create simulated data**: Use fake data or generators (such as `Faker`) to create test data.
26+
- 🛢 **Database configuration**: Configure a test database(such as SQLite) for rapid testing.
27+
28+
</details>
29+
30+
<details>
31+
<summary>② 𝐂𝐫𝐞𝐚𝐭𝐞 𝐭𝐞𝐬𝐭 𝐜𝐚𝐬𝐞𝐬</summary>
32+
33+
1. 𝗨𝗻𝗶𝘁 𝘁𝗲𝘀𝘁
34+
35+
- 🛠️ **Tool Recommendation**: [`nose2`](https://github.com/nose-devs/nose2), [`pytest`](https://github.com/pytest-dev/pytest)
36+
- 📖 **Method**: Write test cases for each function and class method to cover all code paths. Use assertions to verify if expected results match actual results.
37+
38+
```python
39+
# Example of using assertions.
40+
def test_addition():
41+
assert 1 + 1 == 2
42+
```
43+
44+
2. 𝗜𝗻𝘁𝗲𝗴𝗿𝗮𝘁𝗶𝗼𝗻 𝘁𝗲𝘀𝘁𝗶𝗻𝗴: Ensure modules/components work together correctly.
45+
46+
- 🛠️ **Tool Recommendation**: Use `unittest.mock` or `pytest-mock` to mock external services or APIs.
47+
48+
```python
49+
import pytest
50+
from unittest.mock import patch
51+
52+
@patch('my_module.external_api_call')
53+
def test_external_api_integration(mock_api_call):
54+
mock_api_call.return_value = {'data': 'expected'}
55+
result = my_module.fetch_data()
56+
assert result == 'expected'
57+
```
58+
59+
3. 𝗘𝗻𝗱-𝘁𝗼-𝗲𝗻𝗱 𝘁𝗲𝘀𝘁𝗶𝗻𝗴
60+
61+
- 🤖 **Simulate user operations**: Conduct a comprehensive test of the entire application process from beginning to end.
62+
- 🚀 **Automation script**: Write automation scripts to ensure that these tests can be run quickly after every code change.
63+
64+
</details>
65+
66+
67+
<details>
68+
<summary>③ 𝐏𝐞𝐫𝐟𝐨𝐫𝐦 𝐭𝐞𝐬𝐭𝐬</summary>
69+
70+
1. 🧐 **Manual testing**: Invite real users to conduct tests to ensure that the project meets user needs.
71+
72+
2. 💻 **Automated testing**: Integrate testing into CI/CD pipelines such as `GitHub Actions`.
73+
74+
</details>
75+
76+
<details>
77+
<summary>④ 𝐓𝐞𝐬𝐭 𝐚𝐧𝐚𝐥𝐲𝐬𝐢𝐬 𝐚𝐧𝐝 𝐢𝐦𝐩𝐫𝐨𝐯𝐞𝐦𝐞𝐧𝐭</summary>
78+
79+
1. 𝗧𝗲𝘀𝘁𝗶𝗻𝗴 𝗿𝗲𝘀𝘂𝗹𝘁 𝗮𝗻𝗮𝗹𝘆𝘀𝗶𝘀
80+
81+
-**Failure analysis**: Determine whether it is a code error, a test data problem or an environmental issue.
82+
- 📋 **Coverage report**: Use tools (such as `coverage`) to ensure that tests cover all critical paths.
83+
84+
```bash
85+
# Generate coverage report
86+
coverage run -m pytest
87+
coverage report
88+
```
89+
90+
2. 𝗧𝗲𝘀𝘁𝗶𝗻𝗴 𝗼𝗽𝘁𝗶𝗺𝗶𝘇𝗮𝘁𝗶𝗼𝗻
91+
92+
- ⚙️ **Optimize test cases**: Optimize test cases according to test results to improve the accuracy and efficiency of testing.
93+
- ✏️ **Refactor code**: For code segments that are difficult to test, consider refactoring to make them easier to test.
94+
95+
</details>

0 commit comments

Comments
 (0)