-
Notifications
You must be signed in to change notification settings - Fork 14
/
basic_mer_tests.py
63 lines (52 loc) · 1.74 KB
/
basic_mer_tests.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
#!/usr/bin/env python2.6
# vim: set noexpandtab
# encoding: utf-8
"""
basic_mer_tests.py
Created by Austin Godber - 2013-01-12.
Copyright (c) 2013 Austin Godber. All rights reserved.
"""
import os
import unittest
from pds.core.common import open_pds
from pds.core.parser import Parser
from pds.imageextractor import ImageExtractor
class untitledTests(unittest.TestCase):
def setUp(self):
self.parser = Parser()
self.imageExtractor = ImageExtractor()
self.testDataPath = "../test_data/MER"
self.testImages = ["1F345867992EFFB0J3P1212L0M1.IMG",
"1N345854840EFFB0IEP1994L0M1.IMG",
"1P345688456EFFB0EJP2363L2C1.IMG"]
self.testImagePath = self.testDataPath + "/" + self.testImages[0]
def test_existence(self):
assert os.path.exists(self.testImagePath)
def test_open_pds(self):
"""Opening a single image without an exception"""
p = self.parser
try:
f = open_pds(self.testImagePath)
p.parse(f)
except:
raise
def test_get_labels(self):
"""Parsing labels returns something other than None"""
p = self.parser
labels = p.parse(open_pds(self.testImagePath))
self.assertNotEqual(None, labels)
def test_get_image(self):
"""Verify that the extracted image dimensions match those in the label"""
ie = self.imageExtractor
img, labels = ie.extract(open_pds(self.testImagePath))
self.assertNotEqual(None, img)
imageSize = map(int, (labels["IMAGE"]["LINE_SAMPLES"], labels["IMAGE"]["LINES"]))
self.assertEqual(tuple(imageSize), img.size)
def test_write_images(self):
"""docstring for test_write_image"""
ie = self.imageExtractor
for image in self.testImages:
img, labels = ie.extract(open_pds(self.testDataPath + '/' + image))
img.save(image + '.jpg')
if __name__ == '__main__':
unittest.main()