Skip to content

Commit 3688949

Browse files
committed
2 parents 8829f6a + 5118d03 commit 3688949

5 files changed

+118
-0
lines changed

.github/workflows/python-app.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Python application
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Display the path
22+
run: echo $PATH
23+
shell: bash
24+
- uses: actions/checkout@v3
25+
- name: Set up Python 3.10
26+
uses: actions/setup-python@v3
27+
with:
28+
python-version: "3.10"
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install flake8 pytest
33+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
34+
- name: Lint with flake8
35+
run: |
36+
# stop the build if there are Python syntax errors or undefined names
37+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
38+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
39+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
40+
- name: Test with pytest
41+
run: |
42+
pytest

.github/workflows/python-package2.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Python package
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
python-version: ["3.8", "3.9", "3.10"]
20+
21+
steps:
22+
- uses: actions/checkout@v3
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v3
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
python -m pip install flake8 pytest
31+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
32+
- name: Lint with flake8
33+
run: |
34+
# stop the build if there are Python syntax errors or undefined names
35+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
36+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
37+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
38+
- name: Test with pytest
39+
run: |
40+
pytest

factorial.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python3
2+
#function computes factorial of a given number
3+
def factorial(n):
4+
result = 1
5+
i=1
6+
while i<=n:
7+
result*=i
8+
i+=1
9+
return result
10+
def test_answer():
11+
assert factorial(4) == 24
12+
13+
#read input from user
14+
n = 5 #int(input('Enter a number: '))
15+
16+
#calculate factorial
17+
result = factorial(n)
18+
19+
print(result)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def test_one_should_pass():
2+
assert True
3+
4+
def test_two():
5+
assert True
6+
7+
def Passing_test_threeshould_pass():
8+
assert True
9+

tests/xtest_fact.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def test_answer2():
2+
assert factorial(2) == 2
3+
4+
def test_answer3():
5+
assert factorial(3) == 6
6+
7+
def test_answer4():
8+
assert factorial(4) == 24

0 commit comments

Comments
 (0)