From 88b7101b1318d88124f7a7a49a9b4aa5457f48cc Mon Sep 17 00:00:00 2001 From: Lili <145091144+fjzll@users.noreply.github.com> Date: Fri, 23 Aug 2024 13:48:34 +0800 Subject: [PATCH 1/3] Enable automated testing --- .github/workflows/python-app.yml | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..7820094 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,46 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + pull-requests: write + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest pytest-cov + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest and calculate coverage + run: | + pytest --cov-report "xml:coverage.xml" --cov=. + - name: Create Coverage + if: ${{ github.event_name == 'pull_request' }} + uses: orgoro/coverage@v3 + with: + coverageFile: coverage.xml + token: ${{ secrets.GITHUB_TOKEN }} From 835294df2987eacc8853a0719148685421f6a2ed Mon Sep 17 00:00:00 2001 From: Lili Date: Fri, 23 Aug 2024 13:53:44 +0800 Subject: [PATCH 2/3] update test_function.py --- __pycache__/functions.cpython-312.pyc | Bin 0 -> 718 bytes .../test_functions.cpython-312-pytest-8.3.2.pyc | Bin 0 -> 2137 bytes test_functions.py | 14 +++++++------- 3 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 __pycache__/functions.cpython-312.pyc create mode 100644 __pycache__/test_functions.cpython-312-pytest-8.3.2.pyc diff --git a/__pycache__/functions.cpython-312.pyc b/__pycache__/functions.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9e3d722ce73db9d4cdb8cd2d10d46dc9a8e88774 GIT binary patch literal 718 zcma)3O-my|5bd6cOEiXM{Q^ND*MY^8UPSbuf`UXLD+@9Z#_5g@PG(|vk2sP;4j%L_ z#GhdBj|eIVUY21`dh)h7hXwIqRVTB%C*6X6{kp6ARdv;Mu{c1$eve+&9$?j*(C&q1zI} zN~M?8#aVk(av^Pp)xE%8;&M-g4SRKCy<&goe9w=U54mtX$)&v!f8$bl!OrrbQ*Zd( zu0?^XyfBbcjW{tK#za5JV&!Q8phbQZ22b`+XIg719LfLHDX@BxL+AtORVwnple~QI-2#)m*~18pe?!Lr^N#cS^uGo!@o zN>EDvLoWFP!M~$W+DmgXOb9;Y=G8<&g z-khOv-0HQc^BDEo1t#u+4!uTfWe1chPYl;34??NDWEjgRj|+m;*)U5VGA{i=u)$fn z!6NC)%nw;CqM-;U$(hLmY{NKo9Fr*?Lq=mPVMQg3&I$lh8+XzYv} z@ltAU1Dg=xU7%nyz|_?~18a9;L2I&JS#IhK-htf-{}74!nfRvO$4%vw-JN92XFXa| z^_2L#M~Wezx2t%M&j?k~|HTe}pq=%Bc6Mb)>rdUC8r0mS9&L==2pg^@PgVi=r#-t!-CM{|FdR`*p3nREn1Zj>JR!a3U5nKl&uCl>c zqa}^5YII$r<(-p(5O84`?{1d}<>W=Tt6Y%>Aybanh;r31j3!CL1XRsic_EpQe!$hI zei+2D&somHEXf1TR14Jp`Y?ifF%_y7XJ8@JXTI3ThA}m!{)0GM4`M$J5~doy2nI|? zP$zDie4;E}XMXQve)~>m?_+*{I-NsU z2qGtxSGAs>0fCzL%gxd$`vsNgaQ28t5*j}hsrp35PivpXv}k6-as7UAeI~drnX(5< zp{kW(O(CBlenD%`0Xp)&N-{c(+1LCMu=;rtp96YrV~qC^dW`na#pmeaOLX%EY9H1t Ie91V!0ilkw0{{R3 literal 0 HcmV?d00001 diff --git a/test_functions.py b/test_functions.py index ffd7a65..cf4f2b9 100644 --- a/test_functions.py +++ b/test_functions.py @@ -8,12 +8,12 @@ def test_add(): assert add("space", "ship") == "spaceship" -# def test_subtract(): -# assert subtract(3,2) == 1 +def test_subtract(): + assert subtract(3,2) == 1 -# def test_convert_fahrenheit_to_celsius(): -# assert f2c(32) == 0 -# assert f2c(122) == pytest.approx(50) -# with pytest.raises(AssertionError): -# f2c(-600) +def test_convert_fahrenheit_to_celsius(): + assert f2c(32) == 0 + assert f2c(122) == pytest.approx(50) + with pytest.raises(AssertionError): + f2c(-600) From f3e6c720b58cff4a638e3252a73f2e9ed908c419 Mon Sep 17 00:00:00 2001 From: Lili Date: Fri, 23 Aug 2024 14:07:41 +0800 Subject: [PATCH 3/3] restore function subtract; fixes #1 --- __pycache__/functions.cpython-312.pyc | Bin 718 -> 845 bytes ...est_functions.cpython-312-pytest-8.3.2.pyc | Bin 2137 -> 5162 bytes functions.py | 6 ++++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/__pycache__/functions.cpython-312.pyc b/__pycache__/functions.cpython-312.pyc index 9e3d722ce73db9d4cdb8cd2d10d46dc9a8e88774..24a0e5775df8cfc113ce634d5a3679da9d8ae9db 100644 GIT binary patch delta 300 zcmX@ddX|mvG%qg~0}%XCJCPQ|xRH;Uk&$b10i)t%W5)h^KcK{Ph8l(x#%v}Ah9d3~ zMvzhvNMTwHWj8UFFhj%`7)n@SETA6d)j&NUkir6E1v6-}`lZXaz7E{6tL8wJK}c$D zL26NANoi54LQ-l@ez`(oQgMDxX-TR=RccYbp+aV{LSBA}LP36Uab{9Zs@_Wlpn2&< zGRF&Ljz6^5WWL4cSX`W1RFavW=UP;hUo@GW$yr$hsD>Aai?x761H%n=!3pk{*ro6A z$y|{2zswh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WHAm zhQ^%`If9Ij0nk;-qa{=2n8$HU-1tr)2#Sv_^hH21f@u86_5zYoATV3?U(J>Sd>+_^ zt&U+6ArBfI79jkr)oAege6l5ReGULVSncZp+BV}o)^dzHGE<0G) z$pCM6;CpTZ`aZIuHzx3&?qG4Og8O{GywC6YUkiT&2BL38AD|4p*rT>?}|FS z{9ru4sKeJ2{htqhI{4*>KPL|TNvO8#x{>@B S9-}YcOj5dU)llg!spfAis(YFM delta 163 zcmZ3baZ`ZzG%qg~0}y-{J&|^5BCjN)&qQ@!mP$rV){QMiEbN+$znE-oH7EaNab(n- zY|kpiST#9{bqkQq&vukib@ElVYkZn~w>XkYGjmEZ^NNeaC+7+qGm1`LD6C|Bi#g3G z`4(G2Wl3srNs%hhmX!=eYCx(;1xWnju*uC&Da}c>E7AvY8G*Q1dh%akNv_XqOpN+q Fg#cr|Et&uT diff --git a/functions.py b/functions.py index 7cdbb28..a6481f0 100644 --- a/functions.py +++ b/functions.py @@ -3,7 +3,7 @@ def add(a, b): def subtract(a, b): - return a + b + return a - b def multiply(a, b): @@ -11,4 +11,6 @@ def multiply(a, b): def convert_fahrenheit_to_celsius(fahrenheit): - return multiply(subtract(fahrenheit, 32), 9 / 5) + if fahrenheit < -459.67: + raise AssertionError("Temperature below absolute zero is not possible.") + return multiply(subtract(fahrenheit, 32), 5 / 9)