Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-pipeline
csst_proto
Commits
3e1b3ea1
Commit
3e1b3ea1
authored
Oct 28, 2023
by
BO ZHANG
🏀
Browse files
coverage 93%
parent
430584ea
Pipeline
#1425
failed with stage
in 0 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
3e1b3ea1
...
@@ -4,3 +4,11 @@ install:
...
@@ -4,3 +4,11 @@ install:
uninstall
:
uninstall
:
pip uninstall csst_proto
-y
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
csst_proto/__init__.py
View file @
3e1b3ea1
...
@@ -3,8 +3,10 @@ from .flip_image import flip_image, read_default_image
...
@@ -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
.flip_image_in_parallel
import
flip_multiple_images_jl
,
flip_multiple_images_mp
from
.config
import
read_config
from
.config
import
read_config
# 版本号,可以通过csst_proto.__version__获取
__version__
=
"0.0.1"
__version__
=
"0.0.1"
# 定义__all__变量,其中所有的对象会被检查类型标注和docstring
__all__
=
[
__all__
=
[
"demo_function"
,
"demo_function"
,
"DemoClass"
,
"DemoClass"
,
...
...
csst_proto/flip_image.py
View file @
3e1b3ea1
...
@@ -75,6 +75,6 @@ def read_default_image():
...
@@ -75,6 +75,6 @@ def read_default_image():
--------
--------
>>> test_image = 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
))
print
(
"reading file {} ..."
.
format
(
fp_img
))
return
np
.
loadtxt
(
fp_img
,
dtype
=
int
)
return
np
.
loadtxt
(
fp_img
,
dtype
=
int
)
tests/test_config.py
0 → 100644
View file @
3e1b3ea1
"""
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."
,
)
tests/test_demo_function.py
View file @
3e1b3ea1
...
@@ -10,7 +10,7 @@ Modified-History:
...
@@ -10,7 +10,7 @@ Modified-History:
"""
"""
import
unittest
import
unittest
from
csst_proto
.api
import
a_
demo_function
from
csst_proto
import
demo_function
class
TestDemoFunction
(
unittest
.
TestCase
):
class
TestDemoFunction
(
unittest
.
TestCase
):
...
@@ -31,7 +31,7 @@ class TestDemoFunction(unittest.TestCase):
...
@@ -31,7 +31,7 @@ class TestDemoFunction(unittest.TestCase):
"""
"""
# demo function test
# demo function test
self
.
assertTrue
(
self
.
assertTrue
(
a_
demo_function
(
None
)
==
1
,
demo_function
(
None
)
==
1
,
"Single-argument case failed."
,
"Single-argument case failed."
,
)
)
...
@@ -52,7 +52,7 @@ class TestDemoFunction(unittest.TestCase):
...
@@ -52,7 +52,7 @@ class TestDemoFunction(unittest.TestCase):
"""
"""
# demo function test
# demo function test
self
.
assertEqual
(
self
.
assertEqual
(
a_
demo_function
(
None
,
None
),
demo_function
(
None
,
None
),
2
,
2
,
"Double-argument case failed."
,
"Double-argument case failed."
,
)
)
...
@@ -61,7 +61,7 @@ class TestDemoFunction(unittest.TestCase):
...
@@ -61,7 +61,7 @@ class TestDemoFunction(unittest.TestCase):
"""
"""
Aim
Aim
---
---
Test demo function.
Test demo function
in bad case
.
Criteria
Criteria
--------
--------
...
@@ -74,8 +74,8 @@ class TestDemoFunction(unittest.TestCase):
...
@@ -74,8 +74,8 @@ class TestDemoFunction(unittest.TestCase):
if input is `None, None, None`.
if input is `None, None, None`.
"""
"""
# demo function test
# demo function test
self
.
assertNotEqual
s
(
self
.
assertNotEqual
(
a_
demo_function
(
None
,
None
,
None
),
demo_function
(
None
,
None
,
None
),
2
,
2
,
"Triple-argument case failed."
,
"Triple-argument case failed."
,
)
)
tests/test_flip_image.py
View file @
3e1b3ea1
...
@@ -2,15 +2,15 @@ import unittest
...
@@ -2,15 +2,15 @@ import unittest
import
numpy
as
np
import
numpy
as
np
from
csst_proto
.api
import
flip_image
,
read_
tes
t_image
from
csst_proto
import
flip_image
,
read_
defaul
t_image
from
csst_proto
.flip_image
import
flip_multiple_images_jl
,
flip_multiple_images_mp
from
csst_proto
import
flip_multiple_images_jl
,
flip_multiple_images_mp
class
FlipImageTestCase
(
unittest
.
TestCase
):
class
FlipImageTestCase
(
unittest
.
TestCase
):
def
test_flip_image
(
self
):
def
test_flip_image
(
self
):
"""
test flip image
"""
"""test flip image"""
self
.
assertTrue
(
self
.
assertTrue
(
np
.
all
(
flip_image
(
read_
tes
t_image
())
==
np
.
array
([[
4
,
3
],
[
2
,
1
]]))
np
.
all
(
flip_image
(
read_
defaul
t_image
())
==
np
.
array
([[
4
,
3
],
[
2
,
1
]]))
)
)
# the code fails for 1D array
# the code fails for 1D array
...
@@ -18,21 +18,17 @@ class FlipImageTestCase(unittest.TestCase):
...
@@ -18,21 +18,17 @@ class FlipImageTestCase(unittest.TestCase):
flip_image
(
np
.
array
([
1
,
2
,
3
,
4
]))
flip_image
(
np
.
array
([
1
,
2
,
3
,
4
]))
def
test_flip_multiple_images_mp
(
self
):
def
test_flip_multiple_images_mp
(
self
):
"""
test flip multiple images with multiprocessing
"""
"""test flip multiple images with multiprocessing"""
n_jobs
=
10
n_jobs
=
10
imgs
=
[
read_
tes
t_image
()
for
i_job
in
range
(
n_jobs
)]
imgs
=
[
read_
defaul
t_image
()
for
i_job
in
range
(
n_jobs
)]
flipped_imgs
=
flip_multiple_images_mp
(
imgs
,
n_jobs
)
flipped_imgs
=
flip_multiple_images_mp
(
imgs
,
n_jobs
)
for
i_job
in
range
(
n_jobs
):
for
i_job
in
range
(
n_jobs
):
self
.
assertTrue
(
self
.
assertTrue
(
np
.
all
(
flipped_imgs
[
i_job
]
==
np
.
array
([[
4
,
3
],
[
2
,
1
]])))
np
.
all
(
flipped_imgs
[
i_job
]
==
np
.
array
([[
4
,
3
],
[
2
,
1
]]))
)
def
test_flip_multiple_images_jl
(
self
):
def
test_flip_multiple_images_jl
(
self
):
"""
test flip multiple images with joblib
"""
"""test flip multiple images with joblib"""
n_jobs
=
10
n_jobs
=
10
imgs
=
[
read_
tes
t_image
()
for
i_job
in
range
(
n_jobs
)]
imgs
=
[
read_
defaul
t_image
()
for
i_job
in
range
(
n_jobs
)]
flipped_imgs
=
flip_multiple_images_jl
(
imgs
,
n_jobs
)
flipped_imgs
=
flip_multiple_images_jl
(
imgs
,
n_jobs
)
for
i_job
in
range
(
n_jobs
):
for
i_job
in
range
(
n_jobs
):
self
.
assertTrue
(
self
.
assertTrue
(
np
.
all
(
flipped_imgs
[
i_job
]
==
np
.
array
([[
4
,
3
],
[
2
,
1
]])))
np
.
all
(
flipped_imgs
[
i_job
]
==
np
.
array
([[
4
,
3
],
[
2
,
1
]]))
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment