[dechin@dechin-manjaro pytest]$ python3 -m pip install flake8-htmlCollecting flake8-htmlDownloading flake8_html-0.4.1-py2.py3-none-any.whl (13 kB)Requirement already satisfied: pygments>=2.2.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from flake8-html) (2.7.2)Requirement already satisfied: flake8>=3.3.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from flake8-html) (3.8.4)Requirement already satisfied: jinja2>=2.9.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from flake8-html) (2.11.2)Requirement already satisfied: importlib-metadata in /home/dechin/anaconda3/lib/python3.8/site-packages (from flake8-html) (2.0.0)Requirement already satisfied: pycodestyle<2.7.0,>=2.6.0a1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from flake8>=3.3.0->flake8-html) (2.6.0)Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from flake8>=3.3.0->flake8-html) (0.6.1)Requirement already satisfied: pyflakes<2.3.0,>=2.2.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from flake8>=3.3.0->flake8-html) (2.2.0)Requirement already satisfied: MarkupSafe>=0.23 in /home/dechin/anaconda3/lib/python3.8/site-packages (from jinja2>=2.9.0->flake8-html) (1.1.1)Requirement already satisfied: zipp>=0.5 in /home/dechin/anaconda3/lib/python3.8/site-packages (from importlib-metadata->flake8-html) (3.4.0)Installing collected packages: flake8-htmlSuccessfully installed flake8-html-0.4.1使用方法如下:
[dechin@dechin-20n2s01200 pytest]$ flake8 --format=html --htmldir=flake-report./random_number.py has issues: medium: 4在當(dāng)前目錄執(zhí)行后,相關(guān)的規(guī)范的issue就不會(huì)在命令行里面逐一顯示,都在flake-report目錄下的index.html中可以查看:
我們可以點(diǎn)擊進(jìn)入相應(yīng)文件的issue清單中去查看:
可以點(diǎn)擊每一個(gè)issue,展開(kāi)內(nèi)容中包含了issue所對(duì)應(yīng)行的代碼內(nèi)容:
經(jīng)過(guò)一番修改之后,我們得到的flake8配置文件和源代碼文件如下:
# .flake8[flake8]exclude = ./test*ignore = W391# random_number.pyfrom projectq import MainEnginefrom projectq.ops import H, Measuredef random_number_generator():eng = MainEngine()qubit = eng.allocate_qubit()H | qubiteng.flush()Measure | qubitrandom_number = int(qubit)eng.flush(deallocate_qubits=True)return random_numberif __name__ == '__main__':random_number = random_number_generator()print('Random number generated by quantum simulator is:{}'.format(random_number))最終我們的目的是使得flake8執(zhí)行的issue清零:
[dechin@dechin-manjaro pytest]$ flake8 --format=html --htmldir=flake-report[dechin@dechin-manjaro pytest]$總結(jié)概要本文通過(guò)引入一個(gè)隨機(jī)數(shù)生成器的案例,介紹了在量子計(jì)算中產(chǎn)生真隨機(jī)數(shù)的方案,同時(shí)給出了量子計(jì)算模擬實(shí)現(xiàn) 。借此機(jī)會(huì)也同時(shí)介紹了python的單元測(cè)試庫(kù)pytest的一些常規(guī)和擴(kuò)展使用方法,以及python的編碼規(guī)范測(cè)試庫(kù)flake8的基本使用方法,希望能夠?qū)Υ蠹矣兴鶈l(fā)以及幫助 。
以上關(guān)于本文的內(nèi)容,僅作參考!溫馨提示:如遇健康、疾病相關(guān)的問(wèn)題,請(qǐng)您及時(shí)就醫(yī)或請(qǐng)專(zhuān)業(yè)人士給予相關(guān)指導(dǎo)!
「愛(ài)刨根生活網(wǎng)」www.malaban59.cn小編還為您精選了以下內(nèi)容,希望對(duì)您有所幫助:- js實(shí)現(xiàn)文件下載功能 html圖片按鈕代碼
- 自己制作一個(gè)網(wǎng)站的方法 html5制作網(wǎng)頁(yè)教程
- 浪漫的html表白源代碼 網(wǎng)頁(yè)表白代碼大全
- html頁(yè)面獲取url參數(shù) jquery獲取url中的參數(shù)有哪些
- 講解html中title標(biāo)簽的作用 html標(biāo)題代碼
- 網(wǎng)頁(yè)設(shè)計(jì)菜單欄導(dǎo)航實(shí)例 html5導(dǎo)航欄代碼
- 分享文件轉(zhuǎn)換工具類(lèi) html轉(zhuǎn)換成word文檔
- html左圖右文布局方法 html左右布局模板
- c語(yǔ)言二維數(shù)組定義和賦值 隨機(jī)數(shù)c語(yǔ)言代碼
- html簡(jiǎn)易計(jì)算器代碼 javascript計(jì)算器代碼
