Commit 3e1b3ea1 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

coverage 93%

parent 430584ea
Pipeline #1425 failed with stage
in 0 seconds
......@@ -4,3 +4,11 @@ install:
uninstall:
pip uninstall csst_proto -y
test:
coverage run -m pytest . --import-mode=importlib --cov-report=html --cov-report=term-missing
coverage report -m
rm -rf .coverage .pytest_cache
......@@ -3,8 +3,10 @@ from .flip_image import flip_image, read_default_image
from .flip_image_in_parallel import flip_multiple_images_jl, flip_multiple_images_mp
from .config import read_config
# 版本号,可以通过csst_proto.__version__获取
__version__ = "0.0.1"
# 定义__all__变量,其中所有的对象会被检查类型标注和docstring
__all__ = [
"demo_function",
"DemoClass",
......
......@@ -75,6 +75,6 @@ def read_default_image():
--------
>>> test_image = read_default_image()
"""
fp_img = os.path.join(HERE, "/data/test_image.txt")
fp_img = os.path.join(HERE, "data/test_image.txt")
print("reading file {} ...".format(fp_img))
return np.loadtxt(fp_img, dtype=int)
"""
Identifier: csst_proto/test_config.py
Name: test_config.py
Description: Test reading toml format config.
Author: Bo Zhang
Created: 2023-10-26
Modified-History:
2023-10-26, Bo Zhang, created
2023-10-26, Bo Zhang, add module header
"""
import unittest
from csst_proto import read_config
class TestDemoFunction(unittest.TestCase):
def test_read_config(self):
"""
Aim
---
Test demo function.
Criteria
--------
Pass if the demo function returns `1`.
Details
-------
The demo function returns the length of the input argument list.
This case aims to test whether the demo function returns `1` if input is `None`.
"""
# demo function test
config = read_config()
self.assertTrue(
set(config.keys()) == {"A", "B"} and config["A"] == 1 and config["B"] == 2,
"Single-argument case failed.",
)
......@@ -10,7 +10,7 @@ Modified-History:
"""
import unittest
from csst_proto.api import a_demo_function
from csst_proto import demo_function
class TestDemoFunction(unittest.TestCase):
......@@ -31,7 +31,7 @@ class TestDemoFunction(unittest.TestCase):
"""
# demo function test
self.assertTrue(
a_demo_function(None) == 1,
demo_function(None) == 1,
"Single-argument case failed.",
)
......@@ -52,7 +52,7 @@ class TestDemoFunction(unittest.TestCase):
"""
# demo function test
self.assertEqual(
a_demo_function(None, None),
demo_function(None, None),
2,
"Double-argument case failed.",
)
......@@ -61,7 +61,7 @@ class TestDemoFunction(unittest.TestCase):
"""
Aim
---
Test demo function.
Test demo function in bad case.
Criteria
--------
......@@ -74,8 +74,8 @@ class TestDemoFunction(unittest.TestCase):
if input is `None, None, None`.
"""
# demo function test
self.assertNotEquals(
a_demo_function(None, None, None),
self.assertNotEqual(
demo_function(None, None, None),
2,
"Triple-argument case failed.",
)
......@@ -2,15 +2,15 @@ import unittest
import numpy as np
from csst_proto.api import flip_image, read_test_image
from csst_proto.flip_image import flip_multiple_images_jl, flip_multiple_images_mp
from csst_proto import flip_image, read_default_image
from csst_proto import flip_multiple_images_jl, flip_multiple_images_mp
class FlipImageTestCase(unittest.TestCase):
def test_flip_image(self):
""" test flip image """
"""test flip image"""
self.assertTrue(
np.all(flip_image(read_test_image()) == np.array([[4, 3], [2, 1]]))
np.all(flip_image(read_default_image()) == np.array([[4, 3], [2, 1]]))
)
# the code fails for 1D array
......@@ -18,21 +18,17 @@ class FlipImageTestCase(unittest.TestCase):
flip_image(np.array([1, 2, 3, 4]))
def test_flip_multiple_images_mp(self):
""" test flip multiple images with multiprocessing """
"""test flip multiple images with multiprocessing"""
n_jobs = 10
imgs = [read_test_image() for i_job in range(n_jobs)]
imgs = [read_default_image() for i_job in range(n_jobs)]
flipped_imgs = flip_multiple_images_mp(imgs, n_jobs)
for i_job in range(n_jobs):
self.assertTrue(
np.all(flipped_imgs[i_job] == np.array([[4, 3], [2, 1]]))
)
self.assertTrue(np.all(flipped_imgs[i_job] == np.array([[4, 3], [2, 1]])))
def test_flip_multiple_images_jl(self):
""" test flip multiple images with joblib """
"""test flip multiple images with joblib"""
n_jobs = 10
imgs = [read_test_image() for i_job in range(n_jobs)]
imgs = [read_default_image() for i_job in range(n_jobs)]
flipped_imgs = flip_multiple_images_jl(imgs, n_jobs)
for i_job in range(n_jobs):
self.assertTrue(
np.all(flipped_imgs[i_job] == np.array([[4, 3], [2, 1]]))
)
self.assertTrue(np.all(flipped_imgs[i_job] == np.array([[4, 3], [2, 1]])))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment