GitLab CI/CD使用经验,来自于莫纳什大学的考试任务解析

news2024/11/29 4:53:45

CI/CD简介

CI/CD的作用在于自动化和加速软件开发、测试和交付流程,通过持续集成确保代码协同工作和质量,通过持续交付降低风险,使每次代码变更都能够快速、高质量地交付到生产环境,从而提高软件开发效率、质量和协作。

作业要求

学校给出一个售货系统的代码,需要学生对于代码进行构建CI/CD(flake8,mypy,pycodestyle,pydocstyle,pylint),并且使用Python完善软件测试(test)。

解析方案

在构建CI/CD管道时,在使用配置文件创建静态分析时,我最初没有区分地将所有阶段合并在一起。在后来的过程中,我通过为每个阶段使用相同的阶段名称来解决这个问题。当测试没有被代码纠正时发生的测试用例。
Below is my code:

stages:
  - Static Analysis 
  - Test

flake8:
  stage: Static Analysis
  script:
    - pip install flake8
    - flake8 megamart.py
  allow_failure: true

mypy:
  stage: Static Analysis  
  script:
    - pip install mypy
    - mypy megamart.py
  allow_failure: true

pycodestyle:
  stage: Static Analysis
  script: 
    - pip install pycodestyle
    - pycodestyle megamart.py 
  allow_failure: true

pydocstyle:
  stage: Static Analysis
  script:
    - pip install pydocstyle
    - pydocstyle megamart.py
  allow_failure: true

pylint:
  stage: Static Analysis
  script:
    - pip install pylint
    - pylint megamart.py
  allow_failure: true

testing:
  stage: Test
  script:
    - python -m unittest test_megamart.py
  allow_failure: false

在这里插入图片描述在修改完测试用例后可以登录你的GitLab可以看到你的测试结果已经通过,但是你的代码风格分析产生一些错误异常

在这里插入图片描述

分析代码风格产生异常的原因

PyCodeStyles

使用Python绘制一个柱状图来查看代码风格产生异常的错误代码
在这里插入图片描述
接下来根据每一个错误给出解决错误的方式
D200: One-line docstring should fit on one line with quotes (found 4):
这个错误只需要在导入一个模块的时候加上备注写入对于模块的描述就可以解决这个问题,下面是对比:
An Example of the Original Version.

from datetime import datetime

An Example of the Fixed Version.

"""
This is the Megamart module.

It is Megamart
"""
from datetime import datetime

D205: 1 blank line required between summary line and description
An Example of the Original Version.

def is_not_allowed_to_purchase_item(item: Item, customer: Customer, purchase_date_string: str) -> bool:
  """
  Returns True if the customer is not allowed to purchase the specified item, False otherwise.
  If an item object or the purchase date string was not actually provided, an Exception should be raised.
  Items that are under the alcohol, tobacco or knives category may only be sold to customers who are aged 18+ and have their ID verified.
  An item potentially belongs to many categories - as long as it belongs to at least one of the three categories above, restrictions apply to that item.
  The checking of an item's categories against restricted categories should be done in a case-insensitive manner.
   For example, if an item A is in the category ['Alcohol'] and item B is in the category ['ALCOHOL'], both items A and B should be identified as restricted items.
  Even if the customer is aged 18+ and is verified, they must provide/link their member account to the transaction when purchasing restricted items.
  Otherwise, if a member account is not provided, they will not be allowed to purchase the restricted item even if normally allowed to.
  It is optional for customers to provide their date of birth in their profile.
  Purchase date string should be of the format dd/mm/yyyy.
  The age of the customer is calculated from their specified date of birth, which is also of the format dd/mm/yyyy.
  If an item is a restricted item but the purchase or birth date is in the incorrect format, an Exception should be raised.
  A customer whose date of birth is 01/08/2005 is only considered to be age 18+ on or after 01/08/2023.
  """

An Example of the Fixed Version.

def is_not_allowed_to_purchase_item(item: Item, customer: Customer, purchase_date_string: str) -> bool:
  """
  Returns True if the customer is not allowed to purchase the specified item, False otherwise.

  Args:
      item (Item): The item being purchased.
      customer (Customer): The customer attempting the purchase.
      purchase_date_string (str): The purchase date in the format dd/mm/yyyy.

  Raises:
      Exception: If the provided item is None.

  If an item object or the purchase date string was not actually provided, an Exception should be raised.
  Items that are under the alcohol, tobacco or knives category may only be sold to customers who are aged 18+ and have their ID verified.
  An item potentially belongs to many categories - as long as it belongs to at least one of the three categories above, restrictions apply to that item.
  The checking of an item's categories against restricted categories should be done in a case-insensitive manner.
  For example, if an item A is in the category ['Alcohol'] and item B is in the category ['ALCOHOL'], both items A and B should be identified as restricted items.
  Even if the customer is aged 18+ and is verified, they must provide/link their member account to the transaction when purchasing restricted items.
  Otherwise, if a member account is not provided, they will not be allowed to purchase the restricted item even if normally allowed to.
  It is optional for customers to provide their date of birth in their profile.
  Purchase date string should be of the format dd/mm/yyyy.
  The age of the customer is calculated from their specified date of birth, which is also of the format dd/mm/yyyy.
  If an item is a restricted item but the purchase or birth date is in the incorrect format, an Exception should be raised.
  A customer whose date of birth is 01/08/2005 is only considered to be age 18+ on or after 01/08/2023.
  """

pyLine

在这里插入图片描述

C0301: Line too long (103/100) (line-too-long)
An Example of the Original Version.

def is_not_allowed_to_purchase_item(item: Item, customer: Customer, purchase_date_string: str) -> bool:
  """
  Determine if the customer is allowed to purchase the specified item.

  Returns True if the customer is not allowed to purchase the specified item, False otherwise.

def is_not_allowed_to_purchase_item(item: Item, 
                                    customer: Customer, 
                                    purchase_date_string: str) -> bool:
  """
  Determine if the customer is allowed to purchase the specified item.

  Returns True if the customer is not allowed to purchase the specified item, False otherwise.

  Args:
      item (Item): The item being purchased.
      customer (Customer): The customer attempting the purchase.
      purchase_date_string (str): The purchase date in the format dd/mm/yyyy.

PyDocstyle

在这里插入图片描述

Lizard

在这里插入图片描述

Mypy

在这里插入图片描述

Flake8

在这里插入图片描述

对比汇总表

在这里插入图片描述
其实这个项目中出现的错误有很多,但是因为篇幅问题我没有办法一一把示例代码给出,所以在此我制作出一个统计表格,总结下来CI/CD可以检测代码风格进行统一管理,方便于不同工程师之间进行协同时,因为有统一的代码和备注风格所以减少协同成本。

结论和建议

在"megamart"文件中,最常见的问题是"pyflakes ",其次是"pydocstyles "。这些问题大多与代码注释有关。为了解决这些问题,建议保持代码注释简洁,并遵循一致的代码格式标准。如果您正在使用集成开发环境(IDE),请考虑为自动代码格式化配置插件。

最复杂的函数是“checkout”,因为它涉及18个逻辑条件,包括检查空值和特定数据类型。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1176772.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

如何处理msvcp110.dll缺失的问题,msvcp110.dll修复方法分享

当我们试图运行用Visual Studio 2012开发的应用程序时,有时可能会收到一个错误提示:“程序无法启动,因为计算机中丢失了msvcp110.dll”。这是非常常见的DLL(动态链接库)错误之一。它通常是因为该dll文件丢失或损坏所造…

VERT900 Antenna

782773-01 VERT900 Vertical Antenna (824-960 MHz, 1710-1990 MHz) Dualband Includes one VERT900 824 to 960 MHz, 1710 to 1990 MHz Quad-band Cellular/PCS and ISM Band omni-directional vertical antenna, at 3dBi Gain.

如何对非线性【SVM】进行三维可视化

首先导入相应的模块, from sklearn.datasets import make_blobs from sklearn.svm import SVC import matplotlib.pyplot as plt import numpy as np 我们使用make_circles()函数创建散点图,并将散点图中的点的横纵坐标赋值给x,y,其中x是特…

大数据房价预测分析与可视 计算机竞赛

0 前言 🔥 优质竞赛项目系列,今天要分享的是 🚩 大数据房价预测分析与可视 🥇学长这里给一个题目综合评分(每项满分5分) 难度系数:3分工作量:3分创新点:4分 该项目较为新颖,适合…

网络爬虫的实战项目:使用JavaScript和Axios爬取Reddit视频并进行数据分析

概述 网络爬虫是一种程序或脚本,用于自动从网页中提取数据。网络爬虫的应用场景非常广泛,例如搜索引擎、数据挖掘、舆情分析等。本文将介绍如何使用JavaScript和Axios这两个工具,实现一个网络爬虫的实战项目,即从Reddit这个社交媒…

C# winform 定时器

1.加入Timer using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;namespace Te…

Linux实现进度条小程序(包含基础版本和模拟下载过程版本)

Linux实现进度条小程序[包含基础版本和模拟下载过程版本] Linux实现进度条小程序1.预备的两个小知识1.缓冲区1.缓冲区概念的引出2.缓冲区的概念 2.回车与换行1.小例子2.倒计时小程序 2.基础版进度条1.的回车方式的打印2.百分比的打印3.状态提示符的打印 3.升级版进度条1.设计:进…

一题都看不懂,大厂的面试是真的变态......

最近我的一个读者朋友去了字节面试,来给我发信息吐槽,说字节的面试太困难了,像他这种三年经验的测试员,在技术面,居然一题都答不上来,这要多高的水平才能有资格去面试字节的测试岗位。 确实,字…

nacos的部署与配置中心

文章目录 一、nacos部署安装的方式单机模式:集群模式:多集群模式: 二、安装的步骤1、预备环境准备2、载安装包以及安装2.1、Nacos有以下两种安装方式:2.2、更换数据源数据源切换为MySQL 2.3、开启控制台授权登录(可选) 3、配置中心的使用3.1、创建配置信…

星戈瑞Sulfo Cy3-COOH生物学有那些常见应用呢?

Sulfo Cy3-COOH(磺酸基花青3羧酸)(来自星戈瑞的花菁染料)是一种常用的荧光标记物,应用于生物学研究中,其常见应用包括但不限于以下几个领域: 1.免疫荧光染色:Sulfo Cy3-COOH通常用于标记抗体,用…

《进化优化》第7章 遗传规划

文章目录 7.1 LISP: 遗传规划的语言Lisp程序的交叉 7.2 遗传规划的基础7.2.1 适应度的度量7.2.2 终止准则7.2.3 终止集合7.2.4 函数集合7.2.5 初始化7.2.6 遗传规划的参数 7.3 最短时间控制的遗传规划7.4 遗传规划的膨胀7.5 演化实体而非计算机程序7.6 遗传规划的数学分析 遗传…

使用Selenium Grid远程执行测试

我们将在同一台工作电脑上,分别启动主控(Hub)和节点(Node)2个Selenium Grid服务,IP地址均使用环回地址127.0.0.1,端口分别为4444和5555。开始以下操作前,请确认你的机器上已经安装、…

VERT2450 Antenna

VERT2450 Vertical Antenna (2.4-2.5 and 4.9-5.9 GHz) Dualband Includes one VERT2450 Dual Band 2.4 to 2.48 GHz and 4.9 to 5.9 GHz omni-directional vertical antenna, at 3dBi Gain.

GPT-4V:AI在医疗领域的应用

OpenAI最新发布的GPT-4V模型为ChatGPT增添了语音和图像功能,为用户提供了更多在日常生活中使用ChatGPT的方式。这次更新将为用户带来更加便捷、直观的交互体验,用户可以直接通过拍照上传图片,并提出相关问题。OpenAI的最终目标是构建一个安全…

数据库多数据组合 取别名,某项多项数据为null,导致整个结果为null,SQLSERVER,MYSQL

最近遇到一个通过查多项数据,并且组合拼接展示的场景, 发现所有数据单查都没问题,唯独含有一个或多个结果是null的拼接结果出了问题 简单的demo如下: 此时我们可以看到拼接的结果返回[null],我们想要的是即使是null也拼接进去获取其他展示情况我们视需求开发而定, 比如我现在…

阿里云python训练营-Python基础学习01

基础知识 a "hello" b "hello" print(a is b, a b) # True True print(a is not b, a ! b) # False False a ["hello"] b ["hello"] print(a is b, a b) # False True print(a is not b, a ! b) # True False 注意&#xff1a…

Java 设计模式——外观模式

目录 1.概述2.结构3.实现3.1.子系统类3.2.外观类3.3.测试 4.优缺点5.使用场景6.源码解析 1.概述 (1)有些人可能炒过股票,但其实大部分人都不太懂,这种没有足够了解证券知识的情况下做股票是很容易亏钱的,刚开始炒股肯…

2023测试开发常见面试题

1. 什么是软件测试, 谈谈你对软件测试的了解 软件测试就是验证产品特性是否符合用户需求, 软件测试贯穿于软件的整个生命周期. >>> 那软件测试具体是什么呢 ? 就拿生活中的例子来说, 比如说我们去商场买衣服, 会有以下几个步骤: 第一步:…

leetcode:189. 轮转数组(python3解法)

难度:中等 给定一个整数数组 nums,将数组中的元素向右轮转 k 个位置,其中 k 是非负数。 示例 1: 输入: nums [1,2,3,4,5,6,7], k 3 输出: [5,6,7,1,2,3,4]解释: 向右轮转 1 步: [7,1,2,3,4,5,6] 向右轮转 2 步: [6,7,1,2,3,4,5] 向右轮转 3…

Spring @Value注解读取yml配置文件中的list和map

配置文件 myConfig:userList: 张三,李四userMap: {"张三":"10","李四":"20"} 读取代码 Value("${myConfig.userList}")private List<String> userList;Value("#{${myConfig.userMap}}")private Map<S…