1
- import os . path
1
+ import os
2
2
import re
3
3
import shutil
4
4
import subprocess
@@ -29,7 +29,7 @@ def test_should_not_commit() -> None:
29
29
30
30
# @pytest.mark.skip(reason="for test")
31
31
def test_find_lines () -> None :
32
- lines = process .find_lines (load_image ("limit-lines-1.png" ), True , {})
32
+ lines = process .find_lines (load_image ("limit-lines-1.png" ), vertical = True , config = {})
33
33
assert 1821 in [line [0 ] for line in lines ]
34
34
35
35
@@ -38,7 +38,7 @@ def test_find_limit_contour() -> None:
38
38
context = process_utils .Context ({"args" : {}}, {})
39
39
context .image = load_image ("limit-contour-1.png" )
40
40
contours = process .find_contours (context .image , context , "limit" , {})
41
- limits = process .find_limit_contour (context .image , True , contours )
41
+ limits = process .find_limit_contour (context .image , vertical = True , contours = contours )
42
42
assert limits == [1589 ]
43
43
44
44
@@ -199,7 +199,7 @@ async def test_assisted_split_full(type_, limit, better_value, cut_white) -> Non
199
199
assert step ["name" ] == "split"
200
200
images = step ["sources" ]
201
201
assert len (images ) == 1
202
- assert os . path . basename (images [0 ]) == config ["assisted_split" ][0 ]["image" ]
202
+ assert Path (images [0 ]). name == Path ( config ["assisted_split" ][0 ]["image" ]). name
203
203
print (f"Compare '{ images [0 ]} ' with expected image 'assisted-split-{ type_ } -1.expected.png'." )
204
204
check_image_file (
205
205
str (root_folder ),
@@ -290,11 +290,11 @@ async def test_assisted_split_join_full() -> None:
290
290
"sources" : ["image-1.png" , "image-2.png" ],
291
291
}
292
292
config_file_name = root_folder / "config.yaml"
293
- step = await process .transform (config , step , config_file_name , root_folder )
293
+ step = await process .transform (config , step , str ( config_file_name ) , root_folder )
294
294
assert step ["name" ] == "split"
295
295
images = step ["sources" ]
296
- assert os .path .basename (images [0 ]) == config ["assisted_split" ][0 ]["image" ]
297
296
assert len (images ) == 2
297
+ assert Path (images [0 ]).name == Path (config ["assisted_split" ][0 ]["image" ]).name
298
298
for number , elements in enumerate (
299
299
[
300
300
({"value" : 738 , "vertical" : True , "margin" : 0 }, ["-" , "1.2" ]),
@@ -432,7 +432,7 @@ async def test_full(progress) -> None:
432
432
"images" : [str (Path (__file__ ).parent / "all-1.png" )],
433
433
}
434
434
step = {"sources" : [str (Path (__file__ ).parent / "all-1.png" )]}
435
- step = await process .transform (config , step , "/tmp/test-config.yaml" , root_folder )
435
+ step = await process .transform (config , step , "/tmp/test-config.yaml" , root_folder ) # noqa: S108
436
436
assert len (step ["sources" ]) == 1
437
437
print (f"Compare '{ step ['sources' ][0 ]} ' with expected image 'all-1.expected.png'." )
438
438
check_image_file (
@@ -508,7 +508,7 @@ async def test_credit_card_full() -> None:
508
508
str (Path (__file__ ).parent / "credit-card-2.png" ),
509
509
],
510
510
}
511
- step = await process .transform (config , step , "/tmp/test-config.yaml" , root_folder )
511
+ step = await process .transform (config , step , "/tmp/test-config.yaml" , root_folder ) # noqa: S108
512
512
assert len (step ["sources" ]) == 2
513
513
assert step ["name" ] == "finalize"
514
514
await process .finalize (config , step , root_folder )
@@ -558,7 +558,7 @@ async def test_empty() -> None:
558
558
str (Path (__file__ ).parent / "empty.png" ),
559
559
],
560
560
}
561
- step = await process .transform (config , step , "/tmp/test-config.yaml" , root_folder )
561
+ step = await process .transform (config , step , "/tmp/test-config.yaml" , root_folder ) # noqa: S108
562
562
assert len (step ["sources" ]) == 0
563
563
assert step ["name" ] == "finalize"
564
564
shutil .rmtree (root_folder )
@@ -577,7 +577,7 @@ async def test_custom_process(test: str, args: dict[str, Any]) -> None:
577
577
root_folder .mkdir (parents = True , exist_ok = True )
578
578
config = {"args" : args }
579
579
step = {"sources" : [str (Path (__file__ ).parent / f"{ test } .png" )]}
580
- step = await process .transform (config , step , "/tmp/test-config.yaml" , root_folder )
580
+ step = await process .transform (config , step , "/tmp/test-config.yaml" , root_folder ) # noqa: S108
581
581
assert len (step ["sources" ]) == 1
582
582
try :
583
583
print (f"Compare '{ step ['sources' ][0 ]} ' with expected image '{ test } .expected.png'." )
@@ -607,8 +607,8 @@ async def test_qr_code(name) -> None:
607
607
await add_code .add_codes (Path (__file__ ).parent / f"{ name } .pdf" , Path (f"/results/{ name } .pdf" ))
608
608
root_folder = Path ("/results/qrcode" )
609
609
for page in range (2 ):
610
- subprocess .run (
611
- [
610
+ subprocess .run ( # noqa: S603, ASYNC221
611
+ [ # noqa: S607
612
612
"gm" ,
613
613
"convert" ,
614
614
"-density" ,
@@ -696,8 +696,8 @@ async def test_multi_code() -> None:
696
696
)
697
697
root_folder = Path ("/results/qrcode" )
698
698
for page in range (3 ):
699
- subprocess .run (
700
- [
699
+ subprocess .run ( # noqa: S603, ASYNC221
700
+ [ # noqa: S607
701
701
"gm" ,
702
702
"convert" ,
703
703
"-density" ,
@@ -743,9 +743,9 @@ async def test_tiff_jupyter() -> None:
743
743
config_file_name = str (root_folder / "config.yaml" )
744
744
step = await process .transform (config , step , config_file_name , root_folder )
745
745
assert step ["sources" ] == ["/results/tiff/image-1.png" ]
746
- assert [ p for p in root_folder .rglob ("*.tiff" )] == [root_folder / "source/image-1.tiff" ]
746
+ assert list ( root_folder .rglob ("*.tiff" )) == [root_folder / "source/image-1.tiff" ]
747
747
748
- with open ("/results/tiff/jupyter/jupyter.ipynb" ) as f :
748
+ with Path ("/results/tiff/jupyter/jupyter.ipynb" ). open () as f : # noqa: ASYNC230
749
749
nb = nbformat .read (f , as_version = 4 )
750
750
ep = ExecutePreprocessor (timeout = 600 , kernel_name = "python3" )
751
751
ep .preprocess (nb , {"metadata" : {"path" : "/results/tiff/jupyter/" }})
@@ -809,7 +809,7 @@ def test_auto_mask_combine() -> None:
809
809
check_image (
810
810
"/results/" ,
811
811
cv2 .cvtColor (context .mask , cv2 .COLOR_BGR2RGB ),
812
- os . path . join ( os . path . dirname (__file__ ), "auto_mask_combine.expected.png" ),
812
+ str ( Path (__file__ ). parent / "auto_mask_combine.expected.png" ),
813
813
generate_expected_image = REGENERATE ,
814
814
)
815
815
@@ -818,12 +818,12 @@ def test_auto_mask_combine() -> None:
818
818
def test_auto_cut () -> None :
819
819
init_test ()
820
820
context = process_utils .Context ({"args" : {"cut" : {}, "background_color" : [255 , 0 , 0 ]}}, {})
821
- context .image = cv2 .imread (os . path . join ( os . path . dirname (__file__ ), "auto-mask-source.png" ))
821
+ context .image = cv2 .imread (str ( Path (__file__ ). parent / "auto-mask-source.png" ))
822
822
context .do_initial_cut ()
823
823
check_image (
824
824
"/results/" ,
825
825
cv2 .cvtColor (context .image , cv2 .COLOR_BGR2RGB ),
826
- os . path . join ( os . path . dirname (__file__ ), "auto_cut.expected.png" ),
826
+ str ( Path (__file__ ). parent / "auto_cut.expected.png" ),
827
827
generate_expected_image = REGENERATE ,
828
828
)
829
829
@@ -833,13 +833,13 @@ def test_auto_cut() -> None:
833
833
async def test_color_cut () -> None :
834
834
init_test ()
835
835
context = process_utils .Context ({"args" : {"cut_white" : 200 }}, {})
836
- context .image = cv2 .imread (os . path . join ( os . path . dirname (__file__ ), "white-cut.png" ))
836
+ context .image = cv2 .imread (str ( Path (__file__ ). parent / "white-cut.png" ))
837
837
await process .color_cut (context )
838
838
cv2 .imwrite ("/results/white-cut.actual.png" , context .image )
839
839
check_image (
840
840
"/results/" ,
841
841
cv2 .cvtColor (context .image , cv2 .COLOR_BGR2RGB ),
842
- os . path . join ( os . path . dirname (__file__ ), "white-cut.expected.png" ),
842
+ str ( Path (__file__ ). parent / "white-cut.expected.png" ),
843
843
generate_expected_image = REGENERATE ,
844
844
)
845
845
@@ -858,21 +858,21 @@ async def test_histogram() -> None:
858
858
},
859
859
{},
860
860
)
861
- context .image = cv2 .imread (os . path . join ( os . path . dirname (__file__ ), "limit-contour-all-1.png" ))
861
+ context .image = cv2 .imread (str ( Path (__file__ ). parent / "limit-contour-all-1.png" ))
862
862
context .image_name = "histogram.png"
863
- context .root_folder = Path ("/tmp" )
863
+ context .root_folder = Path ("/tmp" ) # noqa: S108
864
864
await process .histogram (context )
865
865
print ("Compare '/results/histogram/histogram.png' with expected image 'histogram.expected.png'." )
866
866
check_image_file (
867
867
"/results/histogram/" ,
868
- "/tmp/ histogram/ histogram.png" ,
869
- os . path . join ( os . path . dirname (__file__ ), "histogram.expected.png" ),
868
+ str ( Path ( "/tmp" ) / " histogram" / " histogram.png"), # noqa: S108
869
+ str ( Path (__file__ ). parent / "histogram.expected.png" ),
870
870
generate_expected_image = REGENERATE ,
871
871
)
872
872
print ("Compare '/results/histogram/log-histogram.png' with expected image 'histogram-log.expected.png'." )
873
873
check_image_file (
874
874
"/results/histogram/" ,
875
- "/tmp/ histogram/ log-histogram.png" ,
876
- os . path . join ( os . path . dirname (__file__ ), "histogram-log.expected.png" ),
875
+ str ( Path ( "/tmp" ) / " histogram" / " log-histogram.png"), # noqa: S108
876
+ str ( Path (__file__ ). parent / "histogram-log.expected.png" ),
877
877
generate_expected_image = REGENERATE ,
878
878
)
0 commit comments