示例#1
0
    def test_load_rule(self):
        buf = "[some-rule]\n"

        parser = configparser.RawConfigParser()
        parser.read_file(StringIO(buf))

        with self.assertRaises(fzsl.NoTypeError):
            fzsl.scanner_from_configparser('some-rule', parser)

        buf += "type: junk\n"
        parser.read_file(StringIO(buf))
        with self.assertRaises(fzsl.UnknownTypeError):
            fzsl.scanner_from_configparser('some-rule', parser)

        buf = "[some-rule]\ntype = simple\n"
        parser.read_file(StringIO(buf))
        with self.assertRaises(configparser.NoOptionError):
            fzsl.scanner_from_configparser('some-rule', parser)

        buf += "cmd = echo\n"
        parser.read_file(StringIO(buf))
        r = fzsl.scanner_from_configparser('some-rule', parser)
        self.assertIsInstance(r, fzsl.Scanner)
示例#2
0
def test_load_rule():
    buf = "[some-rule]\n"

    parser = configparser.RawConfigParser()
    parser.read_file(io.StringIO(buf))

    with pytest.raises(fzsl.NoTypeError):
        fzsl.scanner_from_configparser("some-rule", parser)

    buf += "type: junk\n"
    parser.read_file(io.StringIO(buf))
    with pytest.raises(fzsl.UnknownTypeError):
        fzsl.scanner_from_configparser("some-rule", parser)

    buf = "[some-rule]\ntype = simple\n"
    parser.read_file(io.StringIO(buf))
    with pytest.raises(configparser.NoOptionError):
        fzsl.scanner_from_configparser("some-rule", parser)

    buf += "cmd = echo\n"
    parser.read_file(io.StringIO(buf))
    r = fzsl.scanner_from_configparser("some-rule", parser)
    assert isinstance(r, fzsl.Scanner)
示例#3
0
    def test_load_rule(self):
        buf = "[some-rule]\n"

        parser = configparser.RawConfigParser()
        parser.read_file(StringIO(buf))

        with self.assertRaises(fzsl.NoTypeError):
            fzsl.scanner_from_configparser('some-rule', parser)

        buf += "type: junk\n"
        parser.read_file(StringIO(buf))
        with self.assertRaises(fzsl.UnknownTypeError):
            fzsl.scanner_from_configparser('some-rule', parser)

        buf = "[some-rule]\ntype = simple\n"
        parser.read_file(StringIO(buf))
        with self.assertRaises(configparser.NoOptionError):
            fzsl.scanner_from_configparser('some-rule', parser)

        buf += "cmd = echo\n"
        parser.read_file(StringIO(buf))
        r = fzsl.scanner_from_configparser('some-rule', parser)
        self.assertIsInstance(r, fzsl.Scanner)
示例#4
0
    def test_load_plugin(self):
        buf = '[rule]\ntype=python\npath=%s/plugins/test_plugin.py\n' % (
            TESTDIR, )

        parser = configparser.RawConfigParser()

        parser.read_file(StringIO(buf + "object=UnsuitableScanner\n"))
        scanner = fzsl.scanner_from_configparser('rule', parser)
        self.assertFalse(scanner.is_suitable(''))

        parser = configparser.RawConfigParser()
        parser.read_file(StringIO(buf + "object=ABCScanner\n"))
        scanner = fzsl.scanner_from_configparser('rule', parser)
        self.assertTrue(scanner.is_suitable(''))
        self.assertEqual(scanner.scan(''), ['a', 'b', 'c'])

        b = buf + "object=KwdsScanner\n"
        b += 'arg1=1\narg2=abc\narg3=some string\n'
        parser = configparser.RawConfigParser()
        parser.read_file(StringIO(b))
        scanner = fzsl.scanner_from_configparser('rule', parser)
        self.assertEqual(scanner.scan(''), ['1', 'abc', 'some string'])

        with self.assertRaises(fzsl.ConfigError):
            parser = configparser.RawConfigParser()
            parser.read_file(StringIO(buf + "object=BrokenScanner1\n"))
            scanner = fzsl.scanner_from_configparser('rule', parser)

        with self.assertRaises(fzsl.ConfigError):
            parser = configparser.RawConfigParser()
            parser.read_file(StringIO(buf + "object=BrokenScanner2\n"))
            scanner = fzsl.scanner_from_configparser('rule', parser)

        with self.assertRaises(fzsl.ConfigError):
            parser = configparser.RawConfigParser()
            parser.read_file(StringIO(buf + "object=BrokenScanner3\n"))
            scanner = fzsl.scanner_from_configparser('rule', parser)
示例#5
0
    def test_load_plugin(self):
        buf = '[rule]\ntype=python\npath=%s/plugins/test_plugin.py\n' % (
                TESTDIR,)

        parser = configparser.RawConfigParser()

        parser.read_file(StringIO(buf + "object=UnsuitableScanner\n"))
        scanner = fzsl.scanner_from_configparser('rule', parser)
        self.assertFalse(scanner.is_suitable(''))

        parser = configparser.RawConfigParser()
        parser.read_file(StringIO(buf + "object=ABCScanner\n"))
        scanner = fzsl.scanner_from_configparser('rule', parser)
        self.assertTrue(scanner.is_suitable(''))
        self.assertEqual(scanner.scan(''), ['a', 'b', 'c'])

        b = buf + "object=KwdsScanner\n"
        b += 'arg1=1\narg2=abc\narg3=some string\n'
        parser = configparser.RawConfigParser()
        parser.read_file(StringIO(b))
        scanner = fzsl.scanner_from_configparser('rule', parser)
        self.assertEqual(scanner.scan(''), ['1', 'abc', 'some string'])

        with self.assertRaises(fzsl.ConfigError):
            parser = configparser.RawConfigParser()
            parser.read_file(StringIO(buf + "object=BrokenScanner1\n"))
            scanner = fzsl.scanner_from_configparser('rule', parser)
                
        with self.assertRaises(fzsl.ConfigError):
            parser = configparser.RawConfigParser()
            parser.read_file(StringIO(buf + "object=BrokenScanner2\n"))
            scanner = fzsl.scanner_from_configparser('rule', parser)

        with self.assertRaises(fzsl.ConfigError):
            parser = configparser.RawConfigParser()
            parser.read_file(StringIO(buf + "object=BrokenScanner3\n"))
            scanner = fzsl.scanner_from_configparser('rule', parser)
示例#6
0
def test_load_plugin(testdir):
    buf = "[rule]\ntype=python\npath=%s/plugins/test_plugin.py\n" % (testdir,)

    parser = configparser.RawConfigParser()

    parser.read_file(io.StringIO(buf + "object=UnsuitableScanner\n"))
    scanner = fzsl.scanner_from_configparser("rule", parser)
    assert not scanner.is_suitable("")

    parser = configparser.RawConfigParser()
    parser.read_file(io.StringIO(buf + "object=ABCScanner\n"))
    scanner = fzsl.scanner_from_configparser("rule", parser)
    assert scanner.is_suitable("")
    assert scanner.scan("") == ["a", "b", "c"]

    b = buf + "object=KwdsScanner\n"
    b += "arg1=1\narg2=abc\narg3=some string\n"
    parser = configparser.RawConfigParser()
    parser.read_file(io.StringIO(b))
    scanner = fzsl.scanner_from_configparser("rule", parser)
    assert scanner.scan("") == ["1", "abc", "some string"]

    with pytest.raises(fzsl.ConfigError):
        parser = configparser.RawConfigParser()
        parser.read_file(io.StringIO(buf + "object=BrokenScanner1\n"))
        scanner = fzsl.scanner_from_configparser("rule", parser)

    with pytest.raises(fzsl.ConfigError):
        parser = configparser.RawConfigParser()
        parser.read_file(io.StringIO(buf + "object=BrokenScanner2\n"))
        scanner = fzsl.scanner_from_configparser("rule", parser)

    with pytest.raises(fzsl.ConfigError):
        parser = configparser.RawConfigParser()
        parser.read_file(io.StringIO(buf + "object=BrokenScanner3\n"))
        scanner = fzsl.scanner_from_configparser("rule", parser)