Skip to content

Commit

Permalink
rename python test to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hofbi committed Oct 4, 2022
1 parent b9a2161 commit 6484cec
Show file tree
Hide file tree
Showing 50 changed files with 3,225 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:

Expand Down
30 changes: 15 additions & 15 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
# supported CodeQL languages.
# ******** NOTE ********

name: "CodeQL"
name: CodeQL

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]
schedule:
- cron: '0 9 * * 6'
- cron: 0 9 * * 6

jobs:
analyze:
Expand All @@ -28,26 +28,26 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'python' ]
language: [python]

steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -60,5 +60,5 @@ jobs:
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
49 changes: 37 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
default_stages: [commit]

ci:
autoupdate_commit_msg: "chore(deps): pre-commit.ci autoupdate"
autoupdate_schedule: "monthly"
autofix_commit_msg: "style: pre-commit.ci fixes"
autoupdate_commit_msg: 'chore(deps): pre-commit.ci autoupdate'
autoupdate_schedule: monthly
autofix_commit_msg: 'style: pre-commit.ci fixes'

repos:
- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
Expand All @@ -22,8 +26,25 @@ repos:
- id: detect-private-key
- id: end-of-file-fixer
- id: name-tests-test
args:
- --pytest-test-first
exclude: (?x)( tools/tests/code_evaluation/jobs/modules/ | tools/tests/helper.py )
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
hooks:
- id: mdformat
exclude: ^slides/
additional_dependencies:
- mdformat-gfm
- mdformat-black
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.2
hooks:
- id: yamlfmt
args: [--mapping, '2', --sequence, '4', --offset, '2', --implicit_start]
exclude: (?x)( .gitlab-ci.yml | .clang-format | .clang-tidy )
- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
Expand All @@ -46,10 +67,10 @@ repos:
rev: v0.6.13
hooks:
- id: cmake-format
additional_dependencies: ["cmakelang"]
additional_dependencies: [cmakelang]
- id: cmake-lint
additional_dependencies: ["cmakelang"]
exclude: "cmake/.*"
additional_dependencies: [cmakelang]
exclude: cmake/.*
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
Expand All @@ -62,23 +83,23 @@ repos:
rev: 5.10.1
hooks:
- id: isort
args: [--profile, black, --multi-line, "3"]
args: [--profile, black, --multi-line, '3']
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
rev: v0.981
hooks:
- id: mypy
args: [--python-version, "3.10"]
args: [--python-version, '3.10']
- repo: https://github.com/PyCQA/pylint
rev: v2.15.0
rev: v2.15.3
hooks:
- id: pylint
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
rev: v3.0.0
hooks:
- id: pyupgrade
args: [--py310-plus, --keep-runtime-typing]
- repo: https://github.com/PyCQA/autoflake
rev: v1.5.3
rev: v1.6.1
hooks:
- id: autoflake
- repo: https://github.com/asottile/yesqa
Expand All @@ -89,3 +110,7 @@ repos:
rev: v0.8.0.4
hooks:
- id: shellcheck
- repo: https://github.com/crate-ci/typos
rev: v1.12.8
hooks:
- id: typos
3 changes: 3 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[default.extend-words]
# German Adresse
Adresse = "Adresse"
4 changes: 2 additions & 2 deletions docs/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ services:
html:
image: asciidoctor/docker-asciidoctor:latest
volumes:
- "./:/documents"
- ./:/documents
command: make html
pdf:
image: asciidoctor/docker-asciidoctor:latest
volumes:
- "./:/documents"
- ./:/documents
command: make pdf
4 changes: 2 additions & 2 deletions slides/.marprc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ options:
breaks: true # newlines in paragraphs are rendered as <br>
bespoke:
progress: true
output: "./build/"
themeSet: "./themes"
output: ./build/
themeSet: ./themes
theme: tum
2 changes: 1 addition & 1 deletion slides/homework/hw_example/slide-deck.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ They can used via local links relative to the repo root, e.g. the [README.md](/t

- [CMake Documentation](https://cmake.org/cmake/help/latest/)
- [CMake Tutorial](https://cmake.org/cmake/help/latest/guide/tutorial/) (Step 1 and 2 might be interesting)
- [`add_libary`](https://cmake.org/cmake/help/latest/command/add_library.html)
- [`add_library`](https://cmake.org/cmake/help/latest/command/add_library.html)
1 change: 1 addition & 0 deletions source/example/install.sh
2 changes: 1 addition & 1 deletion tools/.coveragerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[run]
omit =
**/test/*
**/tests/*
**/__init__.py
Empty file added tools/tests/__init__.py
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Empty test module."""
20 changes: 20 additions & 0 deletions tools/tests/code_evaluation/jobs/modules/factory_test_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Test module."""

from sel_tools.code_evaluation.jobs.common import EvaluationJob
from sel_tools.code_evaluation.jobs.factory import EvaluationJobFactory
from sel_tools.utils.repo import GitlabProject
from tests.helper import SimplePassingJob


class TestFactory(EvaluationJobFactory):
"""Test factory."""

@staticmethod
def create(
gitlab_projects: list[GitlabProject], homework_number: int
) -> list[EvaluationJob]:
evaluation_map: dict[int, list[EvaluationJob]] = {
1: [],
2: [SimplePassingJob()],
}
return evaluation_map[homework_number]
74 changes: 74 additions & 0 deletions tools/tests/code_evaluation/jobs/test_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""Common code evaluation job test."""

import unittest
from pathlib import Path
from subprocess import CalledProcessError
from unittest.mock import MagicMock, patch

from pyfakefs.fake_filesystem_unittest import TestCase
from sel_tools.code_evaluation.jobs.common import (
run_shell_command,
run_shell_command_with_output,
)
from sel_tools.code_evaluation.report import EvaluationResult
from tests.helper import ComplexJob, SimpleFailingJob, SimplePassingJob


class EvaluationJobTest(unittest.TestCase):
"""Evaluation job test."""

def test_simple_failing_job(self) -> None:
unit = SimpleFailingJob()
results = unit.run(Path())
self.assertListEqual(
[EvaluationResult("simple_fail", 0, "This caused the fail")], results
)

def test_simple_passing_job(self) -> None:
unit = SimplePassingJob()
results = unit.run(Path())
self.assertListEqual([EvaluationResult("simple_pass", 1)], results)

def test_simple_passing_job_with_weight(self) -> None:
unit = SimplePassingJob(3)
results = unit.run(Path())
self.assertListEqual([EvaluationResult("simple_pass", 3)], results)

def test_complex_job(self) -> None:
unit = ComplexJob()
results = unit.run(Path())
self.assertListEqual(
[
EvaluationResult("simple_fail", 0, "This caused the fail"),
EvaluationResult("simple_pass", 2),
EvaluationResult("complex", 3),
],
results,
)


class JobsTest(TestCase):
"""Test for jobs module."""

@patch("subprocess.check_call", MagicMock(return_value=0))
def test_run_shell_command_success(self) -> None:
result = run_shell_command("make", Path())
self.assertEqual(1, result)

@patch("subprocess.check_call", MagicMock(side_effect=CalledProcessError(2, "")))
def test_run_shell_command_fail(self) -> None:
result = run_shell_command("make", Path())
self.assertEqual(0, result)

@patch("subprocess.check_output", MagicMock(return_value=b"success"))
def test_run_shell_command_with_output_success(self) -> None:
result = run_shell_command_with_output("make", Path())
self.assertEqual((1, "success"), result)

@patch(
"subprocess.check_output",
MagicMock(side_effect=CalledProcessError(2, "", output=b"fail")),
)
def test_run_shell_command_with_output_fail(self) -> None:
result = run_shell_command_with_output("make", Path())
self.assertEqual((0, "fail"), result)
Loading

0 comments on commit 6484cec

Please sign in to comment.