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
|
#!/usr/bin/env python
# This is a test class for the non-trivial escaping done by zenmap_wrapper.py.
import unittest
import zenmap_wrapper
class test_key_file(unittest.TestCase):
def test_escape(self):
TESTS = (
("", ""),
("a", "a"),
("a\nb\tc\rd\\e", "a\\nb\\tc\\rd\\\\e"),
("a\"b", "a\"b")
)
for test_line, expected in TESTS:
actual = zenmap_wrapper.escape_key_file_value(test_line)
self.assertEqual(expected, actual)
def test_escape_first_space(self):
# Check first-character space escaping.
self.assert_(zenmap_wrapper.escape_key_file_value(" abc").startswith("\\s"))
def test_substitute(self):
original = "abc"
replacements = {"b": "\"\\\t\r\ndef"}
expected = "a\"\\\\\\t\\r\\ndefc"
actual = zenmap_wrapper.substitute_key_file_line(original, replacements)
self.assertEqual(expected, actual)
unittest.main()
|