-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
258 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: CI Pipeline | ||
|
||
on: | ||
push: | ||
branches: | ||
- '**' | ||
pull_request: | ||
branches: | ||
- '**' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Checkout the repository | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
# 安裝系統依賴,確保 OpenCV 可以正確運行 | ||
- name: Install OpenCV dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y libgl1-mesa-glx libglib2.0-0 | ||
# 設置 Python 環境(這裡以 Python 為例) | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.10 | ||
|
||
# 安裝 Python 依賴 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
# 執行測試 | ||
- name: Run tests | ||
run: | | ||
python -m unittest discover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,6 @@ decode.ipynb | |
img.png | ||
temp.png | ||
version3_origin_M_20.png | ||
.tox | ||
.tox | ||
/htmlcov/ | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Qart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,73 @@ | ||
import pytest | ||
import os | ||
from Qart import Image | ||
import unittest | ||
from Qart.img import Image | ||
import shutil | ||
import os | ||
import tempfile | ||
from unittest.mock import patch | ||
|
||
|
||
class TestImage(unittest.TestCase): | ||
@patch('matplotlib.pyplot.imsave') | ||
def test_imgsave(self, mock_plt_save): | ||
# 资源目录中的文件路径 | ||
resource_dir = "tests" | ||
resource_file = "1.png" | ||
resource_path = os.path.join(resource_dir, resource_file) | ||
|
||
# 确保资源文件存在 | ||
self.assertTrue(os.path.exists(resource_path), f"Resource file {resource_path} does not exist") | ||
|
||
# 创建临时目录 | ||
with tempfile.TemporaryDirectory() as tmpdirname: | ||
temp_file = os.path.join(tmpdirname, resource_file) | ||
|
||
# 将资源文件复制到临时目录中 | ||
shutil.copy(resource_path, temp_file) | ||
|
||
# 使用 NamedTemporaryFile 创建临时保存路径 | ||
with tempfile.NamedTemporaryFile(suffix=".png", delete=True) as temp_output_file: | ||
# 创建 Image 对象并使用临时文件路径 | ||
img = Image(temp_file) | ||
img.SetModuleNums(20) | ||
|
||
# 保存到临时文件路径,文件会在测试结束后自动删除 | ||
img.save(temp_output_file.name, mode="Modulebase") | ||
img.save(temp_output_file.name, mode="RGB") | ||
img.save(temp_output_file.name, mode="Grayscale") | ||
img.save(mode="OTSU") | ||
|
||
# 确保 save() 调用了4次 | ||
self.assertEqual(mock_plt_save.call_count, 4) | ||
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=True) as temp_output_file: | ||
# 创建 Image 对象并使用临时文件路径 | ||
img = Image(temp_file) | ||
img.SetModuleNums(20) | ||
|
||
# 保存到临时文件路径,文件会在测试结束后自动删除 | ||
img.save(temp_output_file.name, mode="Modulebase") | ||
img.save(temp_output_file.name, mode="RGB") | ||
img.save(temp_output_file.name, mode="Grayscale") | ||
img.save(mode="OTSU") | ||
|
||
# 确保 save() 调用了4次 | ||
self.assertEqual(mock_plt_save.call_count, 8) | ||
|
||
@patch('matplotlib.pyplot.show') | ||
def test_imgshow(self, mock_plt_show): | ||
resource_dir = "tests" | ||
resource_file = "1.png" | ||
resource_path = os.path.join(resource_dir, resource_file) | ||
self.assertTrue(os.path.exists(resource_path), f"Resource file {resource_path} does not exist") | ||
img = Image(resource_path) | ||
img.SetModuleNums(20) | ||
img.show() | ||
img.show("Grayscale") | ||
img.show("OTSU") | ||
img.show("Modulebase") | ||
|
||
# 确保 plt.show() 被调用过 | ||
self.assertEqual(mock_plt_show.call_count, 4) | ||
|
||
def test_img(tmpdir): | ||
# 资源目录中的文件路径 | ||
resource_dir = "tests" | ||
resource_file = "1.png" | ||
resource_path = os.path.join(resource_dir, resource_file) | ||
|
||
# 确保资源文件存在 | ||
assert os.path.exists(resource_path), f"Resource file {resource_path} does not exist" | ||
|
||
# 将资源文件复制到临时目录中 | ||
temp_file = tmpdir.join(resource_file) | ||
shutil.copy(resource_path, str(temp_file)) | ||
|
||
# 创建 Image 对象并使用临时文件路径 | ||
img = Image(str(temp_file)) | ||
img.SetModuleNums(20) | ||
img.save(mode = "Modulebase") | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,44 @@ | ||
import pytest | ||
import os | ||
from Qart import Qart | ||
import unittest | ||
from Qart.qart import Qart | ||
import shutil | ||
import os | ||
import tempfile | ||
from unittest.mock import patch | ||
|
||
|
||
class TestQart(unittest.TestCase): | ||
@patch('matplotlib.pyplot.imsave') | ||
def test_Qartsave(self, mock_plt_save): | ||
# 资源目录中的文件路径 | ||
resource_dir = "tests" | ||
resource_file = "1.png" | ||
resource_path = os.path.join(resource_dir, resource_file) | ||
|
||
# 确保资源文件存在 | ||
self.assertTrue(os.path.exists(resource_path), f"Resource file {resource_path} does not exist") | ||
|
||
# 创建临时目录 | ||
with tempfile.TemporaryDirectory() as tmpdirname: | ||
temp_file = os.path.join(tmpdirname, resource_file) | ||
|
||
def test_qrcode(tmpdir): | ||
Qr = Qart('accept') | ||
# 资源目录中的文件路径 | ||
resource_dir = "tests" | ||
resource_file = "img2.jpeg" | ||
resource_path = os.path.join(resource_dir, resource_file) | ||
temp_file = tmpdir.join(resource_file) | ||
shutil.copy(resource_path, str(temp_file)) | ||
Qr.generate(temp_file, 20, "L", mask = 0, mode = "Normal") | ||
Qr.show() | ||
|
||
# 将资源文件复制到临时目录中 | ||
shutil.copy(resource_path, temp_file) | ||
|
||
# 使用 NamedTemporaryFile 创建临时保存路径 | ||
with tempfile.NamedTemporaryFile(suffix=".png", delete=True) as temp_output_file: | ||
Qr = Qart("Accepted") | ||
Qr.generate(resource_path, 6, "L", mask = 0, mode = "Normal") | ||
# # 创建 Image 对象并使用临时文件路径 | ||
# img = Image(temp_file) | ||
# img.SetModuleNums(20) | ||
|
||
# 保存到临时文件路径,文件会在测试结束后自动删除 | ||
Qr.save() | ||
self.assertEqual(mock_plt_save.call_count, 1) | ||
with tempfile.NamedTemporaryFile(suffix=".png", delete=True) as temp_output_file: | ||
Qr = Qart("Acceptedwadawdqawdewrwareawerwarewd") | ||
Qr.generate(resource_path, 10, "L", mask = 0, mode = "Normal") | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import unittest | ||
from Qart.qart import Qrcode | ||
from Qart.Error import EncodeError | ||
import shutil | ||
import os | ||
import tempfile | ||
from unittest.mock import patch | ||
|
||
|
||
class TestQrcode(unittest.TestCase): | ||
@patch('matplotlib.pyplot.imsave') | ||
def test_qrcodesave(self, mock_plt_save): | ||
# 资源目录中的文件路径 | ||
resource_dir = "tests" | ||
resource_file = "1.png" | ||
resource_path = os.path.join(resource_dir, resource_file) | ||
|
||
# 确保资源文件存在 | ||
self.assertTrue(os.path.exists(resource_path), f"Resource file {resource_path} does not exist") | ||
|
||
# 创建临时目录 | ||
with tempfile.TemporaryDirectory() as tmpdirname: | ||
temp_file = os.path.join(tmpdirname, resource_file) | ||
|
||
# 将资源文件复制到临时目录中 | ||
shutil.copy(resource_path, temp_file) | ||
|
||
# 使用 NamedTemporaryFile 创建临时保存路径 | ||
with tempfile.NamedTemporaryFile(suffix=".png", delete=True) as temp_output_file: | ||
Qr = Qrcode("Accepted") | ||
Qr.generate(6, "L", mask = 0, mode = "Normal") | ||
Qr = Qrcode("1234") | ||
Qr.generate(6, "L", mask = 1, mode = "Micro") | ||
Qr = Qrcode("12345") | ||
Qr.generate(6, "L", mask = 2, mode = "Normal") | ||
Qr = Qrcode("/O.O/") | ||
Qr.generate(6, "H", mask = 3, mode = "Normal") | ||
Qr = Qrcode("謝") | ||
Qr.generate(6, "M", mask = 4, mode = "Normal") | ||
Qr = Qrcode("Accepted") | ||
Qr.generate(6, "Q", mask = 5, mode = "Normal") | ||
Qr.save("test.jpg") | ||
Qr = Qrcode("Accepted") | ||
Qr.generate(6, "M", mask = 6, mode = "Normal") | ||
Qr.save("test.png") | ||
Qr = Qrcode("Accepted") | ||
Qr.generate(6, "Q", mask = 7, mode = "Normal") | ||
num = Qr.InformationMask() | ||
# Qr.showdata() | ||
# # 创建 Image 对象并使用临时文件路径 | ||
# img = Image(temp_file) | ||
# img.SetModuleNums(20) | ||
|
||
# 保存到临时文件路径,文件会在测试结束后自动删除 | ||
Qr.save() | ||
self.assertEqual(mock_plt_save.call_count, 3) | ||
with tempfile.NamedTemporaryFile(suffix=".png", delete=True) as temp_output_file: | ||
Qr = Qrcode("Acceptedwadawdqawdewrwareawerwarewd") | ||
Qr.generate(20, "L", mask = 0, mode = "Normal") | ||
|
||
@patch('matplotlib.pyplot.show') | ||
def test_qrcode_data_show(self, mock_plt_show): | ||
Qr = Qrcode("Accepted") | ||
Qr.generate(6, "Q", mask = 7, mode = "Normal") | ||
num = Qr.InformationMask() | ||
Qr.showdata() | ||
self.assertEqual(mock_plt_show.call_count, 1) | ||
|
||
@patch('matplotlib.pyplot.show') | ||
def test_qrcode_show(self, mock_plt_show): | ||
Qr = Qrcode("Accepted") | ||
Qr.generate(6, "Q", mask = 7, mode = "Normal") | ||
Qr.show() | ||
self.assertEqual(mock_plt_show.call_count, 1) | ||
|
||
def test_qrcode_tp_numpy(self): | ||
Qr = Qrcode("Accepted") | ||
Qr.generate(6, "Q", mask = 7, mode = "Normal") | ||
Qr.to_numpy() | ||
def test_encode_error(self): | ||
with self.assertRaises(EncodeError): | ||
Qr = Qrcode("한") | ||
Qr.generate(6, "L", mask = 0, mode = "Normal") | ||
|
||
def test_value_error(self): | ||
with self.assertRaises(ValueError): | ||
Qr = Qrcode("dwadw") | ||
Qr.generate(50, "L", mask = 0, mode = "Normal") | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |