Skip to content
Snippets Groups Projects
Commit 6129b3a2 authored by wep23441's avatar wep23441
Browse files

moving things around & clean up

parent 731518b5
Branches
No related tags found
No related merge requests found
Showing
with 44 additions and 148 deletions
stages:
- code_quality
- security_checks
# # - test
- test
# - build_image
# - test_image
include:
# - local: ci-configs/case-3-build/unit_test.yml
# - local: ci-configs/case-3-build/build_image.yml
# - local: ci-configs/case-4-security/container_scan.yml
- local: ci-configs/case-4-security/sast.yml
# # Case 1 Lint
# # stages: code_quality
# - local: ci-configs/case-1-lint/linting_job.yml
# # Case 2 Test
# # stages: code_quality, test
# - local: ci-configs/case-2-test/lint.yml
# - local: ci-configs/case-2-test/coverage.yml
# - local: ci-configs/case-2-test/unit_test.yml
# Case 3 Build
# stages: code_quality, test, build, build_image
- local: ci-configs/case-3-build/lint.yml
- local: ci-configs/case-3-build/coverage.yml
- local: ci-configs/case-3-build/unit_test.yml
- local: ci-configs/case-3-build/build.yml
- local: ci-configs/case-3-build/build_image.yml
# Case 4 Security
# stages: code_quality, security_checks, test, build, build_image, test_image
# - local: ci-configs/case-4-security/container_scan.yml
# - local: ci-configs/case-4-security/sast.yml
# - local: ci-configs/case-4-security/secret_detection.yml
......
### Task Case 1 Lint:
Fix the issues in the CI/CD pipeline and Python script by editing the files
within the `case-1-lint/` and and the corresponding CI jobs in `ci-configs/case-1-lint/` folders. Ensure the pipeline
runs successfully and the Python code adheres to linting and formatting standards.
!Dont forget to uncomment the corresponding case section in the `.gitlab-ci.yml`!
\ No newline at end of file
File moved
linting_job:
stage: code_quality
image: python:3.11
script:
- pip install flake8 black
- flake8 ./case-0-linting/
- black --check ./case-0-linting/
\ No newline at end of file
import math
def f(x):
return x * 2 + 3 * math.pi**2 if x > 5 else x * 3 + 2.7182
def g(a, b, c):
return a + b * c - (b / a) + math.sin(a)
def h():
return {"key": [1, 2, 3, 4], "val": "example"}
class Horrible:
def __init__(self):
self.val = 0
def m1(self, a):
self.val += a
def m2(self):
return self.val
def m3(self):
return self.val * 10
def m4(self, a):
self.val -= a
a = Horrible()
a.m1(5)
a.m2()
a.m4(3)
print(f(a.m2()) + g(2, 3, 4) - h()["key"][2] * a.m3())
include README.md
\ No newline at end of file
File deleted
File deleted
import math
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
def get_circle_area(radius):
return math.pi * radius * radius
Metadata-Version: 1.2
Name: my-smart-package
Version: 0.1.0
Summary: UNKNOWN
Home-page: UNKNOWN
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
Requires-Python: >=3.9
MANIFEST.in
setup.py
my_smart_package.egg-info/PKG-INFO
my_smart_package.egg-info/SOURCES.txt
my_smart_package.egg-info/dependency_links.txt
my_smart_package.egg-info/requires.txt
my_smart_package.egg-info/top_level.txt
\ No newline at end of file
coverage>=7.7.0
pytest-cov>=6.0.0
pytest>=8.3.5
from setuptools import setup, find_packages
setup(
name='my_smart_package',
version='0.1.0',
packages=find_packages(),
install_requires=[
'pytest>=8.3.5',
'pytest-cov>=6.0.0',
'coverage>=7.7.0',
],
tests_require=['pytest'],
python_requires='>=3.9',
)
# import pytest
from functions import add, subtract, multiply, divide, get_circle_area
def test_add():
assert add(1, 2) == 3
assert add(-1, 1) == 0
assert add(0, 0) == 0
def test_subtract():
assert subtract(5, 3) == 1
assert subtract(0, 5) == -5
assert subtract(10, 0) == 10
def test_multiply():
assert multiply(2, 3) == 6
assert multiply(-1, 3) == -3
assert multiply(0, 100) == 0
def test_divide():
assert divide(6, 3) == 2
assert divide(10, 2) == 5
assert divide(7, 7) == 1
with pytest.raises(ValueError):
divide(1, 0)
def test_get_circle_area():
assert get_circle_area(3) == pytest.approx(28.274, 0.001)
assert get_circle_area(0) == 0
assert get_circle_area(1) == pytest.approx(3.14159, 0.001)
### Task:
### Task Case 2 Test:
Fix the issues in the CI/CD pipeline and Python script by editing the files
within the `case-0-linting/` and `ci-configs/case0-lint/` folders. Ensure the pipeline
within the `case-2-test/` and the corresponding CI jobs in `ci-configs/case-2-test/` folders. Ensure the pipeline
runs successfully and the Python code adheres to linting and formatting standards.
!Dont forget to uncomment the corresponding section in the `.gitlab-ci.yml`!
\ No newline at end of file
### Solution:
1. break dependencies (correct version of pytest==8.3.5)
5. coverage not enough to pass the job (uncomment tests inside test_functions.py)
2. failing tests (line12: assert subtract(5, 3) == 2)
3. incorrect command in unit_test.yml (line 6: pytestt --> pytest)
\ No newline at end of file
### Task Case 3 Build:
Fix the issues in the CI/CD pipeline and Python script by editing the files
within the `case-3-build/` and the corresponding CI jobs in `ci-configs/case-3-build/` folders, as well as the `Dockerfile` in the root of the repo. Ensure the pipeline
runs successfully and the Python code adheres to linting and formatting standards.
!Dont forget to uncomment the corresponding section in the `.gitlab-ci.yml`!
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment