Beispiel #1
0
class CleanerParserTests(unittest.TestCase):
    def setUp(self):
        self.ip_parser = SoSIPParser(config={})
        self.mac_parser = SoSMacParser(config={})
        self.host_parser = SoSHostnameParser(config={},
                                             opt_domains='foobar.com')
        self.kw_parser = SoSKeywordParser(config={}, keywords=['foobar'])
        self.kw_parser_none = SoSKeywordParser(config={})

    def test_ip_parser_valid_ipv4_line(self):
        line = 'foobar foo 10.0.0.1/24 barfoo bar'
        _test = self.ip_parser.parse_line(line)[0]
        self.assertNotEqual(line, _test)

    def test_ip_parser_invalid_ipv4_line(self):
        line = 'foobar foo 10.1.2.350 barfoo bar'
        self.assertRaises(ValueError, self.ip_parser.parse_line, line)

    def test_ip_parser_package_version_line(self):
        line = 'mycoolpackage-1.2.3.4.5'
        _test = self.ip_parser.parse_line(line)[0]
        self.assertEqual(line, _test)

    def test_mac_parser_valid_ipv4_line(self):
        line = 'foobar foo 13:24:35:46:57:68 bar barfoo'
        _test = self.mac_parser.parse_line(line)[0]
        self.assertNotEqual(line, _test)

    def test_mac_parser_valid_ipv6_line(self):
        line = 'foobar foo AA:BB:CC:FF:FE:DD:EE:FF bar barfoo'
        _test = self.mac_parser.parse_line(line)[0]
        self.assertNotEqual(line, _test)

    def test_hostname_load_hostname_string(self):
        fqdn = 'myhost.subnet.example.com'
        self.host_parser.load_hostname_into_map(fqdn)

    def test_hostname_valid_domain_line(self):
        self.host_parser.load_hostname_into_map('myhost.subnet.example.com')
        line = 'testing myhost.subnet.example.com in a string'
        _test = self.host_parser.parse_line(line)[0]
        self.assertNotEqual(line, _test)

    def test_hostname_short_name_in_line(self):
        self.host_parser.load_hostname_into_map('myhost.subnet.example.com')
        line = 'testing just myhost in a line'
        _test = self.host_parser.parse_line(line)[0]
        self.assertNotEqual(line, _test)

    def test_keyword_parser_valid_line(self):
        line = 'this is my foobar test line'
        _test = self.kw_parser.parse_line(line)[0]
        self.assertNotEqual(line, _test)

    def test_keyword_parser_no_change_by_default(self):
        line = 'this is my foobar test line'
        _test = self.kw_parser_none.parse_line(line)[0]
        self.assertEqual(line, _test)
Beispiel #2
0
class CleanerParserTests(unittest.TestCase):

    def setUp(self):
        self.ip_parser = SoSIPParser(config={})
        self.mac_parser = SoSMacParser(config={})
        self.host_parser = SoSHostnameParser(config={}, opt_domains='foobar.com')
        self.kw_parser = SoSKeywordParser(config={}, keywords=['foobar'])
        self.kw_parser_none = SoSKeywordParser(config={})
        self.kw_parser.generate_item_regexes()

    def test_ip_parser_valid_ipv4_line(self):
        line = 'foobar foo 10.0.0.1/24 barfoo bar'
        _test = self.ip_parser.parse_line(line)[0]
        self.assertNotEqual(line, _test)

    def test_ip_parser_invalid_ipv4_line(self):
        line = 'foobar foo 10.1.2.350 barfoo bar'
        self.assertRaises(ValueError, self.ip_parser.parse_line, line)

    def test_ip_parser_package_version_line(self):
        line = 'mycoolpackage-1.2.3.4.5'
        _test = self.ip_parser.parse_line(line)[0]
        self.assertEqual(line, _test)

    def test_mac_parser_valid_ipv4_line(self):
        line = 'foobar foo 13:24:35:46:57:68 bar barfoo'
        _test = self.mac_parser.parse_line(line)[0]
        self.assertNotEqual(line, _test)

    def test_mac_parser_valid_ipv6_line(self):
        line = 'foobar foo AA:BB:CC:FF:FE:DD:EE:FF bar barfoo'
        _test = self.mac_parser.parse_line(line)[0]
        self.assertNotEqual(line, _test)

    def test_mac_parser_with_quotes(self):
        line = "foobar foo '12:34:56:78:90:AA' bar barfoo"
        _test = self.mac_parser.parse_line(line)[0]
        self.assertNotEqual(line, _test)
        dline = 'foobar foo "aa:12:bb:34:cc:56" bar barfoo'
        _dtest = self.mac_parser.parse_line(dline)[0]
        self.assertNotEqual(dline, _dtest)

    def test_mac_parser_with_quotes_ipv6(self):
        line = "foobar foo 'FF:EE:DD:FF:FE:CC:BB:AA' bar barfoo"
        _test = self.mac_parser.parse_line(line)[0]
        self.assertNotEqual(line, _test)
        dline = 'foobar foo "DD:EE:FF:FF:FE:BB:CC:AA" bar barfoo'
        _dtest = self.mac_parser.parse_line(dline)[0]
        self.assertNotEqual(dline, _dtest)

    def test_mac_parser_with_quotes_ipv6_quad(self):
        line = "foobar foo 'AABB:CCDD:EEFF:FFAA' bar barfoo"
        _test = self.mac_parser.parse_line(line)[0]
        self.assertNotEqual(line, _test)
        dline = 'foobar foo "AAFF:FFEE:DDCC:BBAA" bar barfoo'
        _dtest = self.mac_parser.parse_line(dline)[0]
        self.assertNotEqual(dline, _dtest)

    def test_hostname_load_hostname_string(self):
        fqdn = 'myhost.subnet.example.com'
        self.host_parser.load_hostname_into_map(fqdn)

    def test_hostname_valid_domain_line(self):
        self.host_parser.load_hostname_into_map('myhost.subnet.example.com')
        line = 'testing myhost.subnet.example.com in a string'
        _test = self.host_parser.parse_line(line)[0]
        self.assertNotEqual(line, _test)

    def test_hostname_short_name_in_line(self):
        self.host_parser.load_hostname_into_map('myhost.subnet.example.com')
        line = 'testing just myhost in a line'
        _test = self.host_parser.parse_line(line)[0]
        self.assertNotEqual(line, _test)

    def test_keyword_parser_valid_line(self):
        line = 'this is my foobar test line'
        _test = self.kw_parser.parse_line(line)[0]
        self.assertNotEqual(line, _test)

    def test_keyword_parser_no_change_by_default(self):
        line = 'this is my foobar test line'
        _test = self.kw_parser_none.parse_line(line)[0]
        self.assertEqual(line, _test)