File tree Expand file tree Collapse file tree 5 files changed +65
-2
lines changed Expand file tree Collapse file tree 5 files changed +65
-2
lines changed Original file line number Diff line number Diff line change 1+ name : " Test Suite"
2+ description : " Run tests"
3+
4+ runs :
5+ using : " composite"
6+ steps :
7+ - name : Install deps
8+ run : |
9+ pip install -r requirements.txt
10+ shell : bash
11+
12+ - name : Run Tests
13+ run : |
14+ pytest src/
15+ shell : bash
16+
Original file line number Diff line number Diff line change 1+ name : Pull Request
2+
3+ on :
4+ pull_request :
5+ branches :
6+ - ' *'
7+
8+ paths-ignore :
9+ - ' **.md'
10+
11+ jobs :
12+ test :
13+ runs-on : ubuntu-latest
14+ steps :
15+ - name : " Checkout code"
16+ uses : actions/checkout@v2
17+
18+ - name : " Test Suite"
19+ uses : ./.github/actions/test_suite
Original file line number Diff line number Diff line change 11requests == 2.28.1
2- black == 22.10.0
2+ black == 22.10.0
3+ pytest == 7.2.0
Original file line number Diff line number Diff line change 11import requests
2+ from random import randint
23
34
45def make_a_request () -> int :
56 response = requests .get ('https://example.com' )
67 return response .status_code
8+
9+
10+ def roll_fate (bonus : int = 0 ) -> int :
11+ return sum ([_fate_to_number (randint (1 , 6 )) for _ in range (4 )]) + bonus
12+
13+
14+ def _fate_to_number (raw : int ) -> int :
15+ if raw < 3 :
16+ return - 1
17+ if raw > 4 :
18+ return 1
19+ return 0
Original file line number Diff line number Diff line change 11from http import HTTPStatus
2- from some_file import make_a_request
2+ from unittest .mock import patch
3+
4+ from some_file import make_a_request , roll_fate
35
46
57def test_make_a_request () -> None :
68 assert make_a_request () == HTTPStatus .OK
9+
10+
11+ def test_roll_fate_no_mock () -> None :
12+ assert - 4 <= roll_fate (0 ) <= 4
13+
14+
15+ class TestRollFate :
16+ def test_all_1s_returns_negative_four (self ) -> None :
17+ with patch ('some_file.randint' , return_value = 1 ):
18+ assert roll_fate (0 ) == - 4
19+ assert roll_fate (0 ) == - 4
20+ assert roll_fate (0 ) == - 4
You can’t perform that action at this time.
0 commit comments