-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
72 lines (50 loc) · 2.22 KB
/
tests.py
File metadata and controls
72 lines (50 loc) · 2.22 KB
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
"""Unittest test suite."""
import unittest
from FMHash import escape, hash, unescape
class TestInputEscape(unittest.TestCase):
"""Test escaping FMHash inputs."""
def test_escape_equal(self):
"""Test escaping string with an equal sign."""
self.assertEqual(escape('a=b'), 'a/=b')
def test_escape_escaped_equal(self):
"""Test escaping string with and already-escapred equal sign."""
self.assertEqual(escape('a/=b'), 'a//=b')
def test_escape_colon(self):
"""Test escaping string with and a colon."""
self.assertEqual(escape('a:b'), 'a/:b')
def test_escape_dict_open(self):
"""Test escaping string with less-than sign."""
self.assertEqual(escape('a<b'), 'a/<b')
def test_escape_dict_close(self):
"""Test escaping string with greater-than sign."""
self.assertEqual(escape('a>b'), 'a/>b')
def test_escape_empty_input(self):
"""Test escaping empty string."""
self.assertEqual(escape(''), '')
class TestInputUnescape(unittest.TestCase):
"""Test unescaping FMHash inputs."""
def test_unescape_equal(self):
"""Test unescaping string with equal sign."""
self.assertEqual(unescape('a/=b'), 'a=b')
def test_unescape_escaped_equal(self):
"""Test unescaping double-escaped equal sign."""
self.assertEqual(unescape('a//=b'), 'a/=b')
def test_unescape_colon(self):
"""Test unescaping string with an escaped colon."""
self.assertEqual(unescape('a/:b'), 'a:b')
def test_unescape_dict_open(self):
"""Test unescaping string with an escaped less-than sign."""
self.assertEqual(unescape('a/<b'), 'a<b')
def test_unescape_dict_close(self):
"""Test unescaping string with an escaped greater-than sign."""
self.assertEqual(unescape('a/>b'), 'a>b')
def test_escape_empty_input(self):
"""Test unescaping string an empty string."""
self.assertEqual(unescape(''), '')
class TestHashKeyValuePairs(unittest.TestCase):
"""Test FMHash hash function."""
def test_hash_key_value_pair(self):
"""Test hash function."""
self.assertEqual(hash('name', 'bob'), '<:name:=bob:>')
if __name__ == '__main__':
unittest.main()