File: test_wrapper.py

package info (click to toggle)
nmap 6.47-3%2Bdeb8u2
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 44,788 kB
  • ctags: 25,108
  • sloc: ansic: 89,741; cpp: 62,412; sh: 19,492; python: 17,323; xml: 11,413; perl: 2,529; makefile: 2,503; yacc: 608; lex: 469; asm: 372; java: 45
file content (32 lines) | stat: -rwxr-xr-x 984 bytes parent folder | download | duplicates (4)
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()