Ejemplo n.º 1
0
 def parse(self):
     p = Parser(self.path, True)
     p.parse()
     p.check_required_fields(ClientParser.req_fields)
     return p.config
Ejemplo n.º 2
0
Archivo: parser.py Proyecto: Frky/fspi
    def test_check(self):
        # Check a file with a depth of one
        p = Parser("test/config/depth_one.yaml")
        p.parse()
        # Positive tests
        # All fields required
        try:
            p.check_required_fields({ "foo": "", "bar": "", "foobar": ""})
            self.ok("depth one -- all fields required")
        except ConfigFileException:
            self.ko("depth one -- all fields required")
        # Only one field required
        try:
            p.check_required_fields({ "foo": ""})
            p.check_required_fields({ "bar": ""})
            p.check_required_fields({ "foobar": ""})
            self.ok("depth one -- one field required")
        except ConfigFileException:
            self.ko("depth one -- one field required")
        # Several fields required
        try:
            p.check_required_fields({ "foo": "", "bar": ""})
            p.check_required_fields({ "foo": "", "foobar": ""})
            p.check_required_fields({ "bar": "", "foobar": ""})
            self.ok("depth one -- two fields required")
        except ConfigFileException:
            self.ko("depth one -- two fields required")

        # Negative tests
        # One field required not present, zero present
        try:
            p.check_required_fields({ "FOO": ""})
            self.ko("depth one -- one required field missing")
        except ConfigFileException:
            self.ok("depth one -- one required field missing")
        # One field required not present, one present
        try:
            p.check_required_fields({ "FOO": "", "bar": ""})
            self.ko("depth one -- one required field missing, one present")
        except ConfigFileException:
            self.ok("depth one -- one required field missing, one present")
        # One field required not present, two present
        try:
            p.check_required_fields({ "FOO": "", "bar": "", "foobar": ""})
            self.ko("depth one -- one required field missing, two present")
        except ConfigFileException:
            self.ok("depth one -- one required field missing, two present")
        # Two fields required not present, zero present
        try:
            p.check_required_fields({ "FOO": "", "BAR": "", "foobar": ""})
            self.ko("depth one -- two required fields missing")
        except ConfigFileException:
            self.ok("depth one -- two required fields missing")
        # Two fields required not present, one present
        try:
            p.check_required_fields({ "FOO": "", "BAR": "", "foobar": ""})
            self.ko("depth one -- two required fields missing, one present")
        except ConfigFileException:
            self.ok("depth one -- two required fields missing, one present")
        # Three fields required not present
        try:
            p.check_required_fields({ "FOO": "", "BAR": "", "FOOBAR": ""})
            self.ko("depth one -- all required fields missing")
        except ConfigFileException:
            self.ok("depth one -- all required fields missing")
Ejemplo n.º 3
0
    def test_check(self):
        # Check a file with a depth of one
        p = Parser("test/config/depth_one.yaml")
        p.parse()
        # Positive tests
        # All fields required
        try:
            p.check_required_fields({"foo": "", "bar": "", "foobar": ""})
            self.ok("depth one -- all fields required")
        except ConfigFileException:
            self.ko("depth one -- all fields required")
        # Only one field required
        try:
            p.check_required_fields({"foo": ""})
            p.check_required_fields({"bar": ""})
            p.check_required_fields({"foobar": ""})
            self.ok("depth one -- one field required")
        except ConfigFileException:
            self.ko("depth one -- one field required")
        # Several fields required
        try:
            p.check_required_fields({"foo": "", "bar": ""})
            p.check_required_fields({"foo": "", "foobar": ""})
            p.check_required_fields({"bar": "", "foobar": ""})
            self.ok("depth one -- two fields required")
        except ConfigFileException:
            self.ko("depth one -- two fields required")

        # Negative tests
        # One field required not present, zero present
        try:
            p.check_required_fields({"FOO": ""})
            self.ko("depth one -- one required field missing")
        except ConfigFileException:
            self.ok("depth one -- one required field missing")
        # One field required not present, one present
        try:
            p.check_required_fields({"FOO": "", "bar": ""})
            self.ko("depth one -- one required field missing, one present")
        except ConfigFileException:
            self.ok("depth one -- one required field missing, one present")
        # One field required not present, two present
        try:
            p.check_required_fields({"FOO": "", "bar": "", "foobar": ""})
            self.ko("depth one -- one required field missing, two present")
        except ConfigFileException:
            self.ok("depth one -- one required field missing, two present")
        # Two fields required not present, zero present
        try:
            p.check_required_fields({"FOO": "", "BAR": "", "foobar": ""})
            self.ko("depth one -- two required fields missing")
        except ConfigFileException:
            self.ok("depth one -- two required fields missing")
        # Two fields required not present, one present
        try:
            p.check_required_fields({"FOO": "", "BAR": "", "foobar": ""})
            self.ko("depth one -- two required fields missing, one present")
        except ConfigFileException:
            self.ok("depth one -- two required fields missing, one present")
        # Three fields required not present
        try:
            p.check_required_fields({"FOO": "", "BAR": "", "FOOBAR": ""})
            self.ko("depth one -- all required fields missing")
        except ConfigFileException:
            self.ok("depth one -- all required fields missing")
Ejemplo n.º 4
0
 def parse(self):
     p = Parser(self.path, True)
     p.parse()
     p.check_required_fields(ClientParser.req_fields)
     return p.config