Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding testing coverage #222

Merged
merged 11 commits into from
May 13, 2023
10 changes: 7 additions & 3 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Python Lint and Test

on:
push:
branches: [ main ]
branches: [ Adding-Testing-Coverage ]
pull_request:
branches: [ main ]
branches: [ Adding-Testing-Coverage ]

permissions:
contents: read
Expand All @@ -25,6 +25,7 @@ jobs:
working-directory: ./apps/backend
run: |
python -m pip install --upgrade pip
python -m pip install coverage
pip install pipenv
pipenv install --dev --system --deploy --ignore-pipfile
- name: Analyze with pylint
Expand All @@ -39,4 +40,7 @@ jobs:
run: pylint --fail-on=E --fail-under=9.0 --recursive=y app.py ./modules/ ./tests/
- name: Test with pytest
working-directory: ./apps/backend
run: pytest
run: coverage run -m pytest
- name: Printing Coverage Report
working-directory: ./apps/backend
run: coverage report -m
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"wmaurer.change-case",
"ramyaraoa.show-offset",
"ms-vscode-remote.vscode-remote-extensionpack",
"ryanluker.vscode-coverage-gutters",

// Frontend
"herrmannplatz.npm-dependency-links",
Expand Down
10 changes: 5 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "0.2.0",
"configurations": [
{
"name": "Debug Backend",
"name": "Debug Backend Locally",
"type": "python",
"request": "launch",
"module": "flask",
Expand All @@ -15,10 +15,10 @@
},
"args": [
"run",
"--no-debugger", // I have no idea why VSCode suggested this be here, I assume it turns off flask's own debugger?
"--no-debugger", // no idea why VSCode suggested this be here, presumably turns off flask's own debugger?
"--host=0.0.0.0",
"-p",
"5050" // TODO try to read env var for BACKEND_PORT? or up to the dev to manage this?
"5050" // not sure how to get this to read env var for BACKEND_PORT
],
"jinja": true,
"justMyCode": false,
Expand All @@ -28,7 +28,7 @@
},
},
{
"name": "Debug Frontend",
"name": "Debug Frontend Locally",
"type": "node",
"request": "launch",
"runtimeArgs": [
Expand All @@ -47,7 +47,7 @@
},
},
{
"name": "Python: Current File (in Backend App)",
"name": "Python: Debug Current File (in Backend App)",
"presentation": {
"group": "local-debug"
},
Expand Down
19 changes: 16 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,32 @@
"panel": "shared",
"showReuseMessage": true,
"clear": false
}
},
"group": "none"
},
{
"label": "DEVELOPMENT Docker Compose Up (Attached)",
"type": "shell",
"command": "docker compose --file docker-compose.yml --file docker-compose.dev.yml up --build",
"problemMatcher": []
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "PRODUCTION Docker Compose Up (Attached)",
"type": "shell",
"command": "docker compose up --build",
"problemMatcher": []
"problemMatcher": [],
"group": "build"
},
{
"label": "Backend Code Coverage Report",
"type": "shell",
"command": "cd ./apps/backend; source ./.venv/scripts/activate; bash ./coverage.sh",
"problemMatcher": [],
"group": "test"
}
]
}
4 changes: 4 additions & 0 deletions apps/backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ logs/
__pycache__
.venv

# Code Coverage reports
.coverage
coverage.xml

# All below this point is uncategorized (categorize them!)
2 changes: 2 additions & 0 deletions apps/backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ python-dotenv = "*"
matplotlib = "*"
pymongo = "*"
pydantic = "*"
pytest-cov = "*"

[dev-packages]
# libmagic dlls for windows hosts https://pypi.org/project/python-magic/ (when missing, vague errors and it crashes)
python-magic-bin = {version = "*", markers = "platform_system == 'Windows'"}
yapf = "*"
pylint = "*"
pytest = "*"
coverage = "*"

[requires]
python_version = "3.8"
725 changes: 424 additions & 301 deletions apps/backend/Pipfile.lock

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions apps/backend/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Avoid pollution from past runs
rm -f .coverage
rm -f coverage.xml

# Can't find docs on how to automatically detect subdirectories?
# https://pytest-cov.readthedocs.io/en/latest/config.html

pytest --cov-report xml:coverage.xml \
--cov-branch \
--cov . \
--cov modules/ \
--cov modules/data/ \
--cov modules/db/ \
--cov modules/logging/ \
--cov modules/output/

# Print information in the console for the user as well
coverage report -m

echo "Use the VSCode action 'Coverage Gutters: Display Coverage' to see coverage in the editor"
1 change: 1 addition & 0 deletions apps/backend/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; TODO from old team, axe?
[pytest]
markers =
should_fail: marks a set of test that should throw an error when run
Expand Down
1 change: 1 addition & 0 deletions apps/backend/tox.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; TODO from old team, axe?
[tox]
envlist = py{35,36}-pytest{3,4,5,6}

Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
],
"prefer-template": "error",
"no-tabs": "off",
"space-before-function-paren": "off",
"space-before-function-paren": "off", // cspell:disable-line
"comma-dangle": "warn",
"object-curly-spacing": [
"warn",
Expand Down
1 change: 1 addition & 0 deletions example_experiments/python/addNums.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
y, 1, 1, 10, 1
"""

# pylint: disable=glados-print-used

def main():
config = configparser.ConfigParser()
Expand Down
1 change: 1 addition & 0 deletions example_experiments/python/addNumsFailsOnXis1Yis5.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
y, default: 1, min: 1, max: 10, step: 1
"""

# pylint: disable=glados-print-used

def main():
config = configparser.ConfigParser()
Expand Down
1 change: 1 addition & 0 deletions example_experiments/python/addNumsTimeOutOnXis1Yis5.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
waitTime = 2
"""

# pylint: disable=glados-print-used

def main():
config = configparser.ConfigParser()
Expand Down
1 change: 1 addition & 0 deletions example_experiments/python/addNumsTimed.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
waitTime = 3
"""

# pylint: disable=glados-print-used

def main():
config = configparser.ConfigParser()
Expand Down
1 change: 1 addition & 0 deletions example_experiments/python/addNumsWithConstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
c = Test String
"""

# pylint: disable=glados-print-used

def shuffle_word(word):
word = list(word)
Expand Down
2 changes: 1 addition & 1 deletion example_experiments/python/alwaysFail.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""

# There is intentionally unreachable code in this example
# pylint: disable=unreachable
# pylint: disable=unreachable glados-print-used


def main():
Expand Down
6 changes: 4 additions & 2 deletions example_experiments/python/genetic_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#sample experiment that runs a truncation generational loop with a genome represented by a list of 0s and 1s. fitness is measured by number of 1s
#in genome. maximum fitness is measured at the given generation number.
#number of population, genome length, and mutation rate are given. a number can be given for seed or an r can be given for a random seed
# pylint: disable = W0612

# pylint: disable-next=pointless-string-statement
"""
This experiment demonstrates doing things with Post Processing.
Expand Down Expand Up @@ -39,13 +39,15 @@

"""

# pylint: disable = unused-variable glados-print-used
# cspell:ignore chrom

class Chromosome:
genome = []
fitness = 0

#determine fitness of chromosome
def chromFitness(self):
def chromosomeFitness(self):
self.fitness = 0
for bit in self.genome:
if bit == 1:
Expand Down