From a48b8dbd4447437a27441818aa930b7794ae00b3 Mon Sep 17 00:00:00 2001 From: Ravachol Date: Sun, 24 Mar 2024 06:54:35 +0800 Subject: [PATCH 1/3] added unit test (pytest) --- requirements.txt | 4 ++++ tests/text_test.py | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/text_test.py diff --git a/requirements.txt b/requirements.txt index 2b273d0..cce2946 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,10 @@ certifi==2024.2.2 charset-normalizer==3.3.2 idna==3.6 +iniconfig==2.0.0 +packaging==24.0 +pluggy==1.4.0 pyTelegramBotAPI==4.16.1 +pytest==8.1.1 requests==2.31.0 urllib3==2.2.1 diff --git a/tests/text_test.py b/tests/text_test.py new file mode 100644 index 0000000..ecfb26a --- /dev/null +++ b/tests/text_test.py @@ -0,0 +1,11 @@ +# text tests + +from app.services.text_service import generate_random_text + +def test_text_generated(): + text = generate_random_text() + assert isinstance(text, str) + +def test_text_length(): + text = generate_random_text() + assert len(text) >= 30 and len(text) <= 120 From 93bee931f30354dec47e0e56bbd361ed431a3f3c Mon Sep 17 00:00:00 2001 From: Ravachol Date: Sun, 24 Mar 2024 06:57:37 +0800 Subject: [PATCH 2/3] changed .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c1e5f13..943671e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ **/__pycache__/** **~ **/.venv**/** - +**/.pytest_cache/** From d42f74d389aafa3f6a4400cacf6fbabeb8515d18 Mon Sep 17 00:00:00 2001 From: Ravachol Date: Sun, 24 Mar 2024 07:01:51 +0800 Subject: [PATCH 3/3] add pytest workflow for github actions --- .github/workflows/pytest.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/pytest.yml diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 0000000..f89ee4c --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,29 @@ +name: Randomology + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python3 -m pip install --upgrade pip + python3 -m pip install -r requirements.txt + - name: Test with pytest + run: | + python3 -m pytest \ No newline at end of file