|
1 | 1 | """Tests for utils.py""" |
2 | 2 | import os |
3 | 3 | from os import path as op, makedirs |
| 4 | +import shutil |
| 5 | +import tempfile |
4 | 6 | import unittest |
5 | 7 | import numpy as np |
6 | 8 | from PIL import Image |
7 | 9 |
|
8 | | -from label_maker.utils import url, class_match, get_tile_tif, get_tile_wms |
| 10 | +from label_maker.utils import url, class_match, get_tile_tif, get_tile_wms, is_tif |
9 | 11 |
|
10 | 12 | class TestUtils(unittest.TestCase): |
11 | 13 | """Tests for utility functions""" |
@@ -43,6 +45,33 @@ def test_class_match_segmentation(self): |
43 | 45 | self.assertTrue(class_match(ml_type, passing, class_index)) |
44 | 46 | self.assertFalse(class_match(ml_type, failing, class_index)) |
45 | 47 |
|
| 48 | + def test_is_tif(self): |
| 49 | + """Test identifying tif or vrt files as tif""" |
| 50 | + img_dir = op.join('test', 'fixtures') |
| 51 | + |
| 52 | + # tif with .tif extension identified as tif |
| 53 | + test_tif = op.join(img_dir, 'drone.tif') |
| 54 | + self.assertTrue(is_tif(test_tif)) |
| 55 | + |
| 56 | + # vrt with .vrt extension identified as tif |
| 57 | + test_vrt = op.join(img_dir, 'drone.vrt') |
| 58 | + self.assertTrue(is_tif(test_vrt)) |
| 59 | + |
| 60 | + |
| 61 | + # tif with no extension identified as tif |
| 62 | + with tempfile.TemporaryDirectory() as tmpdirname: |
| 63 | + test_tif_no_ext = op.join(tmpdirname, 'drone') |
| 64 | + shutil.copy(test_tif, test_tif_no_ext) |
| 65 | + self.assertTrue(is_tif(test_tif_no_ext)) |
| 66 | + |
| 67 | + # vrt with no extension identified as tif |
| 68 | + with tempfile.TemporaryDirectory() as tmpdirname: |
| 69 | + test_vrt_no_ext = op.join(tmpdirname, 'drone') |
| 70 | + shutil.copy(test_vrt, test_vrt_no_ext) |
| 71 | + self.assertTrue(is_tif(test_vrt_no_ext)) |
| 72 | + |
| 73 | + |
| 74 | + |
46 | 75 | def test_get_tile_tif(self): |
47 | 76 | """Test reading of tile from geotiff""" |
48 | 77 | tile = '1087767-1046604-21' |
|
0 commit comments