-
Notifications
You must be signed in to change notification settings - Fork 0
/
cap_parse_mem_test.py
executable file
·90 lines (69 loc) · 2.82 KB
/
cap_parse_mem_test.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
#!/usr/bin/python2.4
#
# Copyright 2009 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for cap_parse_mem."""
__author__ = '[email protected] (Matt Frantz)'
import os.path
import google3
import cap as caplib
from google3.pyglib import app
from google3.pyglib import resources
from google3.testing.pybase import googletest
from google3.dotorg.gongo.appengine_cap2kml import cap_parse_mem
class CapParseMemTest(googletest.TestCase):
def setUp(self):
self.parser = cap_parse_mem.MemoryCapParser()
self.new_alert_model = lambda: caplib.Alert()
def _ReadTestData(self, basename):
"""Returns the contents of the specified test data file.
Args:
basename: Name of a file in the testdata directory.
Returns:
Contents of the file (str)
"""
return resources.GetResource(os.path.join(
'google3', 'dotorg', 'gongo', 'appengine_cap2kml', 'testdata',
basename))
def testAquilaCap2(self):
alert, errors = self.parser.MakeAlert(self.new_alert_model,
self._ReadTestData('aquila_cap2.xml'))
self.assertListEqual(errors, [])
self.assertEquals(alert.identifier, 'DIPVVF-20090409-1001-3')
self.assertEquals(alert.sender, 'dipartimento-vigilifuoco.it')
self.assertEquals(len(alert.info), 1)
info = list(alert.info)[0]
self.assertListEqual(list(info.category), ['Infra'])
self.assertEquals(info.urgency, 'Unknown')
self.assertEquals(info.severity, 'Unknown')
self.assertEquals(info.certainty, 'Observed')
self.assertEquals(info.audience, 'original')
self.assertEquals(info.senderName, 'Dipartimento Vigili del Fuoco')
self.assertEquals(info.headline, 'TEST 2')
self.assertEquals(info.description, 'Test 2 description')
self.assertEquals(info.web, 'http://www.vigilfuoco.it/')
self.assertEquals(len(info.area), 1)
area = list(info.area)[0]
self.assertEquals(area.description,
'Via Pietro Aldi, 21, 00125 Roma, Italia')
self.assertListEqual(
list(area.circle),
[caplib.Circle(caplib.Point(41.7806015, 12.3580999), 0.01)])
# TODO(Matt Frantz): Test more of the sample CAP files that we have
# accumulated.
# TODO(Matt Frantz): Write unit tests for cap_parse_mem.
def main(unused_argv):
googletest.main()
if __name__ == '__main__':
app.run()