Debian Codegraph @

tests/test_rdtypeanyloc.py

raw
1 # Copyright (C) 2014 Red Hat, Inc.
2 # Author: Petr Spacek <[email protected]>
3 #
4 # Permission to use, copy, modify, and distribute this software and its
5 # documentation for any purpose with or without fee is hereby granted,
6 # provided that the above copyright notice and this permission notice
7 # appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED 'AS IS' AND RED HAT DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17 import unittest
18
19 import dns.rrset
20 import dns.rdtypes.ANY.LOC
21
22
23 class RdtypeAnyLocTestCase(unittest.TestCase):
24 def testEqual1(self):
25 """Test default values for size, horizontal and vertical precision."""
26 r1 = dns.rrset.from_text(
27 "foo", 300, "IN", "LOC", "49 11 42.400 N 16 36 29.600 E 227.64m"
28 )
29 r2 = dns.rrset.from_text(
30 "FOO",
31 600,
32 "in",
33 "loc",
34 "49 11 42.400 N 16 36 29.600 E 227.64m " "1.00m 10000.00m 10.00m",
35 )
36 self.assertEqual(r1, r2, '"{}" != "{}"'.format(r1, r2))
37
38 def testEqual2(self):
39 """Test default values for size, horizontal and vertical precision."""
40 r1 = dns.rdtypes.ANY.LOC.LOC(
41 1, 29, (49, 11, 42, 400, 1), (16, 36, 29, 600, 1), 22764.0
42 ) # centimeters
43 r2 = dns.rdtypes.ANY.LOC.LOC(
44 1,
45 29,
46 (49, 11, 42, 400, 1),
47 (16, 36, 29, 600, 1),
48 22764.0, # centimeters
49 100.0,
50 1000000.00,
51 1000.0,
52 ) # centimeters
53 self.assertEqual(r1, r2, '"{}" != "{}"'.format(r1, r2))
54
55 def testEqual3(self):
56 """Test size, horizontal and vertical precision parsers: 100 cm == 1 m.
57
58 Parsers in from_text() and __init__() have to produce equal results."""
59 r1 = dns.rdtypes.ANY.LOC.LOC(
60 1,
61 29,
62 (49, 11, 42, 400, 1),
63 (16, 36, 29, 600, 1),
64 22764.0,
65 200.0,
66 1000.00,
67 200.0,
68 ) # centimeters
69 r2 = dns.rrset.from_text(
70 "FOO",
71 600,
72 "in",
73 "loc",
74 "49 11 42.400 N 16 36 29.600 E 227.64m " "2.00m 10.00m 2.00m",
75 )[0]
76 self.assertEqual(r1, r2, '"{}" != "{}"'.format(r1, r2))
77
78 def testEqual4(self):
79 """Test size, horizontal and vertical precision parsers without unit.
80
81 Parsers in from_text() and __init__() have produce equal result
82 for values with and without trailing "m"."""
83 r1 = dns.rdtypes.ANY.LOC.LOC(
84 1,
85 29,
86 (49, 11, 42, 400, 1),
87 (16, 36, 29, 600, 1),
88 22764.0,
89 200.0,
90 1000.00,
91 200.0,
92 ) # centimeters
93 r2 = dns.rrset.from_text(
94 "FOO", 600, "in", "loc", "49 11 42.400 N 16 36 29.600 E 227.64 " "2 10 2"
95 )[
96 0
97 ] # meters without explicit unit
98 self.assertEqual(r1, r2, '"{}" != "{}"'.format(r1, r2))
99
100
101 if __name__ == "__main__":
102 unittest.main()