-
Notifications
You must be signed in to change notification settings - Fork 120
/
test_formats.py
122 lines (90 loc) · 3.62 KB
/
test_formats.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
"""Unit tests for Formats
"""
##################################################################
# Copyright 2018 Open Source Geospatial Foundation and others #
# licensed under MIT, Please consult LICENSE.txt for details #
##################################################################
import unittest
from pywps.inout.formats import Format, get_format, FORMATS
from pywps.app.basic import get_xpath_ns
xpath_ns = get_xpath_ns("1.0.0")
class FormatsTest(unittest.TestCase):
"""Formats test cases"""
def setUp(self):
def validate(self, inpt, level=None):
"""fake validate method
"""
return True
self.validate = validate
def tearDown(self):
pass
def test_format_class(self):
"""Test pywps.formats.Format class
"""
frmt = Format('mimetype', schema='halloworld', encoding='asdf',
validate=self.validate)
self.assertEqual(frmt.mime_type, 'mimetype')
self.assertEqual(frmt.schema, 'halloworld')
self.assertEqual(frmt.encoding, 'asdf')
self.assertTrue(frmt.validate('the input', 1))
describeel = frmt.json
self.assertEqual(describeel["mime_type"], 'mimetype')
self.assertEqual(describeel["encoding"], 'asdf')
self.assertEqual(describeel["schema"], 'halloworld')
frmt2 = get_format('GML')
self.assertFalse(frmt.same_as(frmt2))
def test_getformat(self):
"""test for pypws.inout.formats.get_format function
"""
frmt = get_format('GML', self.validate)
self.assertTrue(frmt.mime_type, FORMATS.GML.mime_type)
self.assertTrue(frmt.validate('ahoj', 1))
frmt2 = get_format('GML')
self.assertTrue(frmt.same_as(frmt2))
def test_format_equal_types(self):
"""Test that equality check returns the expected bool and doesn't raise
when types mismatch.
"""
frmt = get_format('GML')
self.assertTrue(isinstance(frmt, Format))
try:
res = frmt.same_as("GML") # not a Format type
except AssertionError:
self.fail("Comparing a format to another type should not raise")
except Exception:
self.fail("Unexpected error, test failed for unknown reason")
self.assertFalse(res, "Equality check with other type should be False")
frmt_other = get_format('GML')
self.assertTrue(frmt == frmt_other, "Same formats should return True")
def test_json_out(self):
"""Test json export
"""
frmt = get_format('GML')
outjson = frmt.json
self.assertEqual(outjson['schema'], '')
self.assertEqual(outjson['extension'], '.gml')
self.assertEqual(outjson['mime_type'], 'application/gml+xml')
self.assertEqual(outjson['encoding'], '')
def test_json_in(self):
"""Test json import
"""
injson = {}
injson['schema'] = 'elcepelce'
injson['extension'] = '.gml'
injson['mime_type'] = 'application/gml+xml'
injson['encoding'] = 'utf-8'
frmt = Format(injson['mime_type'])
frmt.json = injson
self.assertEqual(injson['schema'], frmt.schema)
self.assertEqual(injson['extension'], frmt.extension)
self.assertEqual(injson['mime_type'], frmt.mime_type)
self.assertEqual(injson['encoding'], frmt.encoding)
def load_tests(loader=None, tests=None, pattern=None):
"""Load local tests
"""
if not loader:
loader = unittest.TestLoader()
suite_list = [
loader.loadTestsFromTestCase(FormatsTest)
]
return unittest.TestSuite(suite_list)