Skip to content

Commit 170af13

Browse files
committed
Tests 4 W01
1 parent 37567f1 commit 170af13

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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: Week01 Homework
5+
6+
on:
7+
push:
8+
branches: [ "master" ]
9+
paths: ['Week01/**']
10+
pull_request:
11+
branches: [ "master" ]
12+
paths: ['Week01/**']
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
build:
19+
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v3
24+
- name: Set up Python 3.12
25+
uses: actions/setup-python@v3
26+
with:
27+
python-version: "3.12"
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install flake8 pytest
32+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
33+
- name: Lint with flake8
34+
run: |
35+
# stop the build if there are Python syntax errors or undefined names
36+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
37+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
38+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
39+
- name: Test with pytest
40+
run: |
41+
pytest -q --tb=no 'Week01/test_info.py'

Week01/test_info.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
3+
4+
files = [f for f in os.listdir(os.path.dirname(__file__)) if f.startswith("info")]
5+
for f in files:
6+
exec("import " + f[:-3] + " as " + f[:-3])
7+
print(f"The module {f[:-3]} has been imported.")
8+
9+
10+
def test_names():
11+
for f in files:
12+
assert "student_id" in dir(eval(f[:-3])), (
13+
"student_id is not defined in " + f[:-3]
14+
)
15+
assert "full_name" in dir(eval(f[:-3])), "full_name is not defined in " + f[:-3]
16+
17+
18+
def test_types():
19+
for f in files:
20+
assert isinstance(eval(f[:-3]).student_id, str), (
21+
"student_id is not a string in " + f[:-3]
22+
)
23+
assert isinstance(eval(f[:-3]).full_name, str), (
24+
"full_name is not a string in " + f[:-3]
25+
)

0 commit comments

Comments
 (0)