-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathtest_rsgislib_cli.py
998 lines (835 loc) · 30.1 KB
/
test_rsgislib_cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
import os
import subprocess
import pprint
import glob
from shutil import copy2
import platform
import pytest
import rsgislib.tools.filetools
DATA_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
RASTERGIS_DATA_DIR = os.path.join(DATA_DIR, "rastergis")
IMGUTILS_DATA_DIR = os.path.join(DATA_DIR, "imageutils")
# TODO Need to figure out what is happening on windows but get it building first!
on_windows = platform.system() == "Windows"
JINJA2_NOT_AVAIL = False
try:
import jinja2
except ImportError:
JINJA2_NOT_AVAIL = True
gdal2tiles_cmd_avail = rsgislib.tools.filetools.is_cmd_tool_avail(
"gdal2tiles.py", test_call_cmd=["gdal2tiles.py", "-h"]
)
gdal_translate_cmd_avail = rsgislib.tools.filetools.is_cmd_tool_avail(
"gdal_translate", test_call_cmd=["gdal_translate", "-h"]
)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgis_config_version():
rtn_info = subprocess.run(
["rsgis-config", "--version"], capture_output=True, text=True, check=True
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("5" in rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgis_config_prefix():
rtn_info = subprocess.run(
["rsgis-config", "--prefix"], capture_output=True, text=True, check=True
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgis_config_libs():
rtn_info = subprocess.run(
["rsgis-config", "--libs"], capture_output=True, text=True, check=True
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgis_config_cflags():
rtn_info = subprocess.run(
["rsgis-config", "--cflags"], capture_output=True, text=True, check=True
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgis_config_ldflags():
rtn_info = subprocess.run(
["rsgis-config", "--ldflags"], capture_output=True, text=True, check=True
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgis_config_libdir():
rtn_info = subprocess.run(
["rsgis-config", "--libdir"], capture_output=True, text=True, check=True
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgis_config_includes():
rtn_info = subprocess.run(
["rsgis-config", "--includes"], capture_output=True, text=True, check=True
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgis_config_fail():
rtn_info = subprocess.run(
["rsgis-config", "--hello"], capture_output=True, text=True, check=True
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" == rtn_info.stdout)
@pytest.mark.skipif(
(JINJA2_NOT_AVAIL or on_windows or (not gdal_translate_cmd_avail)),
reason="Either jinja2 not available or command not tested on Windows, "
"or gdal_translate is not available",
)
def test_rsgisapplycmd_run(tmp_path):
in_dir = os.path.join(tmp_path, "in")
os.mkdir(in_dir)
out_dir = os.path.join(tmp_path, "out")
os.mkdir(out_dir)
img1_in = os.path.join(DATA_DIR, "sen2_20210527_aber_vldmsk.kea")
img1_out = os.path.join(in_dir, "sen2_20210527_aber_vldmsk.kea")
copy2(img1_in, img1_out)
img2_in = os.path.join(DATA_DIR, "sen2_20210527_aber_subset_vldmsk.kea")
img2_out = os.path.join(in_dir, "sen2_20210527_aber_subset_vldmsk.kea")
copy2(img2_in, img2_out)
rtn_info = subprocess.run(
[
"rsgisapplycmd.py",
"--indir",
in_dir,
"--outdir",
out_dir,
"--inext",
"kea",
"--outext",
"tif",
"--nameapp",
"test",
"--cmd",
"gdal_translate -of GTIFF {{ input }} {{ output }}",
"--ncores",
"2",
],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and (
len(glob.glob(os.path.join(out_dir, "*.tif"))) == 2
)
@pytest.mark.skipif(
(JINJA2_NOT_AVAIL or on_windows or (not gdal_translate_cmd_avail)),
reason="Either jinja2 not available or command not tested on "
"Windows or gdal_translate is not available",
)
def test_rsgisapplycmd_print(tmp_path):
in_dir = os.path.join(tmp_path, "in")
os.mkdir(in_dir)
out_dir = os.path.join(tmp_path, "out")
os.mkdir(out_dir)
img1_in = os.path.join(DATA_DIR, "sen2_20210527_aber_vldmsk.kea")
img1_out = os.path.join(in_dir, "sen2_20210527_aber_vldmsk.kea")
copy2(img1_in, img1_out)
img2_in = os.path.join(DATA_DIR, "sen2_20210527_aber_subset_vldmsk.kea")
img2_out = os.path.join(in_dir, "sen2_20210527_aber_subset_vldmsk.kea")
copy2(img2_in, img2_out)
rtn_info = subprocess.run(
[
"rsgisapplycmd.py",
"--indir",
in_dir,
"--outdir",
out_dir,
"--inext",
"kea",
"--outext",
"tif",
"--nameapp",
"test",
"--cmd",
"gdal_translate -of GTIFF {{ input }} {{ output }}",
"--printcmds",
],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("gdal_translate" in rtn_info.stdout)
@pytest.mark.skipif(
((not gdal_translate_cmd_avail) or on_windows),
reason="Command not tested on Windows or gdal_translate is not available",
)
def test_rsgisbatchconvert2tif(tmp_path):
in_dir = os.path.join(tmp_path, "in")
os.mkdir(in_dir)
out_dir = os.path.join(tmp_path, "out")
os.mkdir(out_dir)
img1_in = os.path.join(DATA_DIR, "sen2_20210527_aber_vldmsk.kea")
img1_out = os.path.join(in_dir, "sen2_20210527_aber_vldmsk.kea")
copy2(img1_in, img1_out)
img2_in = os.path.join(DATA_DIR, "sen2_20210527_aber_subset_vldmsk.kea")
img2_out = os.path.join(in_dir, "sen2_20210527_aber_subset_vldmsk.kea")
copy2(img2_in, img2_out)
in_srch = os.path.join(in_dir, "*.kea")
rtn_info = subprocess.run(
["rsgisbatchconvert2tif.py", "-i", in_srch, "-o", out_dir],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and (
len(glob.glob(os.path.join(out_dir, "*.tif"))) == 2
)
@pytest.mark.skipif(
((not gdal_translate_cmd_avail) or on_windows),
reason="Command not tested on Windows or gdal_translate is not available",
)
def test_rsgisbatchconvert2tif_chk(tmp_path):
in_dir = os.path.join(tmp_path, "in")
os.mkdir(in_dir)
out_dir = os.path.join(tmp_path, "out")
os.mkdir(out_dir)
img1_in = os.path.join(DATA_DIR, "sen2_20210527_aber_vldmsk.kea")
img1_out = os.path.join(in_dir, "sen2_20210527_aber_vldmsk.kea")
copy2(img1_in, img1_out)
img2_in = os.path.join(DATA_DIR, "sen2_20210527_aber_subset_vldmsk.kea")
img2_out = os.path.join(in_dir, "sen2_20210527_aber_subset_vldmsk.kea")
copy2(img2_in, img2_out)
in_srch = os.path.join(in_dir, "*.kea")
rtn_info = subprocess.run(
["rsgisbatchconvert2tif.py", "-i", in_srch, "-o", out_dir, "--chkimgs"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and (
len(glob.glob(os.path.join(out_dir, "*.tif"))) == 2
)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisbuildimglut(tmp_path):
in_dir = os.path.join(tmp_path, "in")
os.mkdir(in_dir)
img1_in = os.path.join(DATA_DIR, "sen2_20210527_aber_vldmsk.kea")
img1_out = os.path.join(in_dir, "sen2_20210527_aber_vldmsk.kea")
copy2(img1_in, img1_out)
img2_in = os.path.join(DATA_DIR, "sen2_20210527_aber_subset_vldmsk.kea")
img2_out = os.path.join(in_dir, "sen2_20210527_aber_subset_vldmsk.kea")
copy2(img2_in, img2_out)
in_srch = os.path.join(in_dir, "*.kea")
out_lut_file = os.path.join(tmp_path, "lut.gpkg")
rtn_info = subprocess.run(
[
"rsgisbuildimglut.py",
"-i",
in_srch,
"-o",
out_lut_file,
"--veclyr",
"test_lut",
"--vecformat",
"GPKG",
],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and os.path.exists(out_lut_file)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisbuildimglut_wgs84(tmp_path):
in_dir = os.path.join(tmp_path, "in")
os.mkdir(in_dir)
img1_in = os.path.join(DATA_DIR, "sen2_20210527_aber_vldmsk.kea")
img1_out = os.path.join(in_dir, "sen2_20210527_aber_vldmsk.kea")
copy2(img1_in, img1_out)
img2_in = os.path.join(DATA_DIR, "sen2_20210527_aber_subset_vldmsk.kea")
img2_out = os.path.join(in_dir, "sen2_20210527_aber_subset_vldmsk.kea")
copy2(img2_in, img2_out)
in_srch = os.path.join(in_dir, "*.kea")
out_lut_file = os.path.join(tmp_path, "lut.gpkg")
rtn_info = subprocess.run(
[
"rsgisbuildimglut.py",
"-i",
in_srch,
"-o",
out_lut_file,
"--veclyr",
"test_lut",
"--vecformat",
"GPKG",
"--wgs84",
],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and os.path.exists(out_lut_file)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgiscalcimgstats_cont(tmp_path):
img_ref = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
img = os.path.join(tmp_path, "sen2_20210527_aber.kea")
copy2(img_ref, img)
rtn_info = subprocess.run(
["rsgiscalcimgstats.py", "-i", img, "-n", "0.0"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert rtn_info.returncode == 0
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgiscalcimgstats_therm(tmp_path):
img_ref = os.path.join(DATA_DIR, "sen2_20210527_aber_vldmsk.kea")
img = os.path.join(tmp_path, "sen2_20210527_aber_vldmsk.kea")
copy2(img_ref, img)
rtn_info = subprocess.run(
["rsgiscalcimgstats.py", "-i", img, "-n", "0.0", "-t"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert rtn_info.returncode == 0
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgiscalcimgstats_therm_tif(tmp_path):
img_ref = os.path.join(DATA_DIR, "sen2_20210527_aber_vldmsk.tif")
img = os.path.join(tmp_path, "sen2_20210527_aber_vldmsk.tif")
copy2(img_ref, img)
rtn_info = subprocess.run(
["rsgiscalcimgstats.py", "-i", img, "-n", "0.0", "-t"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert rtn_info.returncode == 0
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgischkgdalfile_sgl_img(tmp_path):
img_ref = os.path.join(DATA_DIR, "sen2_20210527_aber_vldmsk.kea")
img = os.path.join(tmp_path, "sen2_20210527_aber_vldmsk.kea")
copy2(img_ref, img)
rtn_info = subprocess.run(
[
"rsgischkgdalfile.py",
"-i",
img,
"--nbands",
"1",
"--epsg",
"27700",
"--chkproj",
"--readimg",
],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert rtn_info.returncode == 0
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgischkgdalfile_multi_img(tmp_path):
img_ref = os.path.join(DATA_DIR, "sen2_20210527_aber_vldmsk.kea")
img = os.path.join(tmp_path, "sen2_20210527_aber_vldmsk.kea")
copy2(img_ref, img)
img_ref = os.path.join(DATA_DIR, "sen2_20210527_aber_subset_vldmsk.kea")
img = os.path.join(tmp_path, "sen2_20210527_aber_subset_vldmsk.kea")
copy2(img_ref, img)
in_srch = os.path.join(tmp_path, "*.kea")
rtn_info = subprocess.run(
[
"rsgischkgdalfile.py",
"-i",
in_srch,
"--nbands",
"1",
"--epsg",
"27700",
"--chkproj",
"--readimg",
],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert rtn_info.returncode == 0
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgischkgdalfile_sgl_vec(tmp_path):
vec_ref = os.path.join(DATA_DIR, "aber_osgb_multi_polys.geojson")
vec = os.path.join(tmp_path, "aber_osgb_multi_polys.geojson")
copy2(vec_ref, vec)
rtn_info = subprocess.run(
["rsgischkgdalfile.py", "-i", vec, "--vec", "--epsg", "27700", "--chkproj"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert rtn_info.returncode == 0
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgischkgdalfile_multi_vec(tmp_path):
vec_ref = os.path.join(DATA_DIR, "aber_osgb_multi_polys.geojson")
vec = os.path.join(tmp_path, "aber_osgb_multi_polys.geojson")
copy2(vec_ref, vec)
vec_ref = os.path.join(DATA_DIR, "aber_osgb_single_poly_hole.geojson")
vec = os.path.join(tmp_path, "aber_osgb_single_poly_hole.geojson")
copy2(vec_ref, vec)
in_srch = os.path.join(tmp_path, "*.geojson")
rtn_info = subprocess.run(
["rsgischkgdalfile.py", "-i", in_srch, "--vec", "--epsg", "27700", "--chkproj"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert rtn_info.returncode == 0
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgiscopybandnames(tmp_path):
img_ref = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
img = os.path.join(tmp_path, "sen2_20210527_aber.kea")
copy2(img_ref, img)
img_bandnames_ref = os.path.join(DATA_DIR, "sen2_20210527_aber_subset.kea")
rtn_info = subprocess.run(
["rsgiscopybandnames.py", "-r", img_bandnames_ref, "-o", img],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert rtn_info.returncode == 0
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisfilehash_sha1():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisfilehash.py", "-i", img, "-o", "SHA1"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisfilehash_sha224():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisfilehash.py", "-i", img, "-o", "SHA224"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisfilehash_sha256():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisfilehash.py", "-i", img, "-o", "SHA256"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisfilehash_sha384():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisfilehash.py", "-i", img, "-o", "SHA384"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisfilehash_sha512():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisfilehash.py", "-i", img, "-o", "SHA512"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisfilehash_md5():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisfilehash.py", "-i", img, "-o", "MD5"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisfilehash_blake2b():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisfilehash.py", "-i", img, "-o", "Blake2B"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisfilehash_black2s():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisfilehash.py", "-i", img, "-o", "Blake2S"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisfilehash_sha3_224():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisfilehash.py", "-i", img, "-o", "SHA3_224"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisfilehash_sha3_256():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisfilehash.py", "-i", img, "-o", "SHA3_256"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisfilehash_sha3_234():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisfilehash.py", "-i", img, "-o", "SHA3_384"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisfilehash_sha3_512():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisfilehash.py", "-i", img, "-o", "SHA3_512"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisfilelut_copy(tmp_path):
import rsgislib.imageutils.imagelut
import glob
input_imgs = glob.glob(os.path.join(IMGUTILS_DATA_DIR, "s2_tiles", "*.kea"))
vec_lut_file = os.path.join(tmp_path, "test_lut.gpkg")
vec_lut_lyr = "test_lut"
rsgislib.imageutils.imagelut.create_img_extent_lut(
input_imgs,
vec_lut_file,
vec_lut_lyr,
"GPKG",
ignore_none_imgs=False,
out_proj_wgs84=False,
overwrite_lut_file=False,
)
roi_file = os.path.join(DATA_DIR, "aber_osgb_single_poly.geojson")
roi_lyr = "aber_osgb_single_poly"
rtn_info = subprocess.run(
[
"rsgisfilelut.py",
"-i",
vec_lut_file,
"--lutlyr",
vec_lut_lyr,
"--roifile",
roi_file,
"--roilyr",
roi_lyr,
"--dest",
tmp_path,
"--copy",
],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisfilelut_targz(tmp_path):
import rsgislib.imageutils.imagelut
import glob
input_imgs = glob.glob(os.path.join(IMGUTILS_DATA_DIR, "s2_tiles", "*.kea"))
vec_lut_file = os.path.join(tmp_path, "test_lut.gpkg")
vec_lut_lyr = "test_lut"
rsgislib.imageutils.imagelut.create_img_extent_lut(
input_imgs,
vec_lut_file,
vec_lut_lyr,
"GPKG",
ignore_none_imgs=False,
out_proj_wgs84=False,
overwrite_lut_file=False,
)
roi_file = os.path.join(DATA_DIR, "aber_osgb_single_poly.geojson")
roi_lyr = "aber_osgb_single_poly"
out_file = os.path.join(tmp_path, "out.tar.gz")
rtn_info = subprocess.run(
[
"rsgisfilelut.py",
"-i",
vec_lut_file,
"--lutlyr",
vec_lut_lyr,
"--roifile",
roi_file,
"--roilyr",
roi_lyr,
"--dest",
out_file,
"--targz",
],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisimg2kmz(tmp_path):
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
out_file = os.path.join(tmp_path, "sen2_20210527_aber.kmz")
rtn_info = subprocess.run(
["rsgisimg2kmz.py", "-i", img, "-o", out_file, "-b", "3,2,1"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and (os.path.exists(out_file))
@pytest.mark.skipif(
(not gdal2tiles_cmd_avail) or on_windows,
reason="Command not tested on Windows or gdal2tiles.py command not available.",
)
def test_rsgisimg2webtiles(tmp_path):
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisimg2webtiles.py", "-i", img, "-o", tmp_path, "-b", "3,2,1"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert rtn_info.returncode == 0
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisimginfo():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisimginfo.py", "-i", img], capture_output=True, text=True, check=True
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisimginfo_rat():
img = os.path.join(RASTERGIS_DATA_DIR, "sen2_20210527_aber_clumps_attref.kea")
rtn_info = subprocess.run(
["rsgisimginfo.py", "-i", img], capture_output=True, text=True, check=True
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisproj_img_epsg():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisproj.py", "--image", img, "-o", "EPSG"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisproj_img_wkt():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisproj.py", "--image", img, "-o", "WKT"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisproj_img_wktpretty():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisproj.py", "--image", img, "-o", "WKTPretty"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisproj_img_proj4():
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
rtn_info = subprocess.run(
["rsgisproj.py", "--image", img, "-o", "PROJ4"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisproj_utm_36n_epsg():
rtn_info = subprocess.run(
["rsgisproj.py", "--utm", "36N", "-o", "EPSG"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisproj_utm_01n_epsg():
rtn_info = subprocess.run(
["rsgisproj.py", "--utm", "01N", "-o", "EPSG"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisproj_utm_55s_epsg():
rtn_info = subprocess.run(
["rsgisproj.py", "--utm", "55S", "-o", "EPSG"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisproj_wkt_epsg():
file_path = os.path.join(IMGUTILS_DATA_DIR, "utm30n.wkt")
rtn_info = subprocess.run(
["rsgisproj.py", "--wktfile", file_path, "-o", "EPSG"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisproj_epsg_wkt():
rtn_info = subprocess.run(
["rsgisproj.py", "--epsg", "27700", "-o", "WKT"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(
((not gdal_translate_cmd_avail) or on_windows),
reason="Command not tested on Windows or gdal_translate is not available",
)
def test_rsgistranslate2tif(tmp_path):
img = os.path.join(DATA_DIR, "sen2_20210527_aber.kea")
out_img = os.path.join(tmp_path, "out_img.tif")
rtn_info = subprocess.run(
["rsgistranslate2tif.py", "-i", img, "-o", out_img],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and os.path.exists(out_img)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisvectools_lyrs():
vec_file = os.path.join(DATA_DIR, "aber_osgb_multi_polys.geojson")
rtn_info = subprocess.run(
["rsgisvectools.py", "--vecfile", vec_file, "--lyrs"],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisvectools_cols():
vec_file = os.path.join(DATA_DIR, "aber_osgb_multi_polys.geojson")
rtn_info = subprocess.run(
[
"rsgisvectools.py",
"--vecfile",
vec_file,
"--veclyr",
"aber_osgb_multi_polys",
"--cols",
],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisvectools_nfeats():
vec_file = os.path.join(DATA_DIR, "aber_osgb_multi_polys.geojson")
rtn_info = subprocess.run(
[
"rsgisvectools.py",
"--vecfile",
vec_file,
"--veclyr",
"aber_osgb_multi_polys",
"--nfeats",
],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)
@pytest.mark.skipif(on_windows, reason="Command not tested on Windows")
def test_rsgisvectools_proj():
vec_file = os.path.join(DATA_DIR, "aber_osgb_multi_polys.geojson")
rtn_info = subprocess.run(
[
"rsgisvectools.py",
"--vecfile",
vec_file,
"--veclyr",
"aber_osgb_multi_polys",
"--proj",
],
capture_output=True,
text=True,
check=True,
)
pprint.pprint(rtn_info)
assert (rtn_info.returncode == 0) and ("" != rtn_info.stdout)