예제 #1
0
    def test_write_prefill_parser(self):
        """Test parser write config to a file."""
        class MySchema(Schema):
            foo = IntOption()

        parser = SchemaConfigParser(MySchema())
        expected = u"[__main__]\nfoo = 0"

        # create config file
        fp, filename = tempfile.mkstemp()
        try:
            parser.write(open(filename, 'w'))
            result = open(filename, 'r').read().strip()
            self.assertEqual(result, expected)
        finally:
            # remove the file
            os.unlink(filename)
    def test_write_prefill_parser(self):
        """Test parser write config to a file."""
        class MySchema(Schema):
            foo = IntOption()

        parser = SchemaConfigParser(MySchema())
        expected = u"[__main__]\nfoo = 0"

        # create config file
        fp, filename = tempfile.mkstemp()
        try:
            parser.write(open(filename, 'w'))
            result = open(filename, 'r').read().strip()
            self.assertEqual(result, expected)
        finally:
            # remove the file
            os.unlink(filename)
예제 #3
0
    def test_write(self):
        """Test parser write config to a file."""
        class MySchema(Schema):
            foo = StringOption()

            class DEFAULTSECT(Section):
                pass

        parser = SchemaConfigParser(MySchema())
        expected = u"[{0}]\nbaz = 2\n\n[__main__]\nfoo = bar".format(
            DEFAULTSECT)
        config = StringIO(expected)
        parser.readfp(config)

        # create config file
        fp, filename = tempfile.mkstemp()
        try:
            parser.write(open(filename, 'w'))
            result = open(filename, 'r').read().strip()
            self.assertEqual(result, expected)
        finally:
            # remove the file
            os.unlink(filename)
    def test_write(self):
        """Test parser write config to a file."""
        class MySchema(Schema):
            foo = StringOption()

            class DEFAULTSECT(Section):
                pass

        parser = SchemaConfigParser(MySchema())
        expected = u"[{0}]\nbaz = 2\n\n[__main__]\nfoo = bar".format(
            DEFAULTSECT)
        config = StringIO(expected)
        parser.readfp(config)

        # create config file
        fp, filename = tempfile.mkstemp()
        try:
            parser.write(open(filename, 'w'))
            result = open(filename, 'r').read().strip()
            self.assertEqual(result, expected)
        finally:
            # remove the file
            os.unlink(filename)