Skip to content

Commit 21d3389

Browse files
committed
test case
1 parent 812f926 commit 21d3389

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

Diff for: .github/workflows/python-app.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# This workflow will install Python dependencies, run tests and lint with a single version of Python
1+
# This workflow will install Python dependencies, run tests, lint with flake8,
2+
# and validate Jupyter notebooks using nbval with a single version of Python.
23
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
34

45
name: Python application
@@ -19,21 +20,26 @@ jobs:
1920

2021
steps:
2122
- uses: actions/checkout@v4
23+
2224
- name: Set up Python 3.10
2325
uses: actions/setup-python@v3
2426
with:
2527
python-version: "3.10"
28+
2629
- name: Install dependencies
2730
run: |
2831
python -m pip install --upgrade pip
29-
pip install flake8 pytest
32+
pip install flake8 pytest nbval # Install pytest and nbval for notebook validation
3033
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
34+
3135
- name: Lint with flake8
3236
run: |
3337
# stop the build if there are Python syntax errors or undefined names
3438
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
3539
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
3640
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
41+
3742
- name: Test with pytest
3843
run: |
39-
pytest
44+
# Run pytest on Jupyter notebooks with the nbval plugin
45+
pytest --nbval # This will run tests inside .ipynb files in the current directory

Diff for: tests/.ipynb_checkpoints/test_Literals_in_Python-checkpoint.ipynb

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
"outputs": [],
99
"source": [
1010
"import pytest\n",
11+
"from unittest.mock import patch\n",
1112
"\n",
12-
"# Define your tests here, as shown in the previous answer\n",
13+
"# Mocking an example of input function for testing purposes\n",
1314
"def test_number_literals():\n",
1415
" a = 0b1010\n",
1516
" b = 100\n",
@@ -70,7 +71,15 @@
7071
"\n",
7172
"def test_special_literal():\n",
7273
" a = None\n",
73-
" assert a is None\n"
74+
" assert a is None\n",
75+
"\n",
76+
"# Mocking user input to test the input function\n",
77+
"@patch('builtins.input', return_value='5') # Mocking input to return '5' when called\n",
78+
"def test_input_function(mock_input):\n",
79+
" # Test scenario where input is used\n",
80+
" user_input = input(\"Enter a number: \")\n",
81+
" assert user_input == '5'\n",
82+
" assert mock_input.call_count == 1 # Checking that the mock was called once\n"
7483
]
7584
},
7685
{

Diff for: tests/test_Literals_in_Python.ipynb

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
"outputs": [],
99
"source": [
1010
"import pytest\n",
11+
"from unittest.mock import patch\n",
1112
"\n",
12-
"# Define your tests here, as shown in the previous answer\n",
13+
"# Mocking an example of input function for testing purposes\n",
1314
"def test_number_literals():\n",
1415
" a = 0b1010\n",
1516
" b = 100\n",
@@ -70,7 +71,15 @@
7071
"\n",
7172
"def test_special_literal():\n",
7273
" a = None\n",
73-
" assert a is None\n"
74+
" assert a is None\n",
75+
"\n",
76+
"# Mocking user input to test the input function\n",
77+
"@patch('builtins.input', return_value='5') # Mocking input to return '5' when called\n",
78+
"def test_input_function(mock_input):\n",
79+
" # Test scenario where input is used\n",
80+
" user_input = input(\"Enter a number: \")\n",
81+
" assert user_input == '5'\n",
82+
" assert mock_input.call_count == 1 # Checking that the mock was called once\n"
7483
]
7584
},
7685
{

0 commit comments

Comments
 (0)