示例#1
0
    def test_interpolate_value_invalid_key(self):
        """Test interpolate_value with an invalid key."""
        class MySchema(Schema):
            foo = TupleOption(2)
        config = StringIO("[other]\nbar=4\n[__main__]\nfoo=%(bar)s,%(bar)s")
        expected_value = None

        parser = SchemaConfigParser(MySchema())
        parser.readfp(config)
        value = parser._interpolate_value('__main__', 'foo')
        self.assertEqual(value, expected_value)
    def test_interpolate_value_invalid_key(self):
        """Test interpolate_value with an invalid key."""
        class MySchema(Schema):
            foo = TupleOption(2)
        config = StringIO("[other]\nbar=4\n[__main__]\nfoo=%(bar)s,%(bar)s")
        expected_value = None

        parser = SchemaConfigParser(MySchema())
        parser.readfp(config)
        value = parser._interpolate_value('__main__', 'foo')
        self.assertEqual(value, expected_value)
示例#3
0
    def test_interpolate_value_duplicate_key(self):
        """Test interpolate_value for a duplicate key."""
        class MySchema(Schema):
            foo = TupleOption(2)
        config = StringIO(
            "[__noschema__]\nbar=4\n[__main__]\nfoo=%(bar)s,%(bar)s")
        expected_value = '4,4'

        parser = SchemaConfigParser(MySchema())
        parser.readfp(config)
        value = parser._interpolate_value('__main__', 'foo')
        self.assertEqual(value, expected_value)
    def test_interpolate_value_duplicate_key(self):
        """Test interpolate_value for a duplicate key."""
        class MySchema(Schema):
            foo = TupleOption(2)
        config = StringIO(
            "[__noschema__]\nbar=4\n[__main__]\nfoo=%(bar)s,%(bar)s")
        expected_value = '4,4'

        parser = SchemaConfigParser(MySchema())
        parser.readfp(config)
        value = parser._interpolate_value('__main__', 'foo')
        self.assertEqual(value, expected_value)
示例#5
0
    def test_interpolate_value_no_keys(self):
        """Test interpolate_value with no keys."""
        class MySchema(Schema):
            foo = TupleOption(2)
        config = StringIO("[__main__]\nfoo=%(bar)s,%(bar)s")

        mock_get_interpolation_keys = Mock(return_value=('%(bar)s', None))

        parser = SchemaConfigParser(MySchema())
        parser.readfp(config)
        with patch.object(parser, '_get_interpolation_keys',
                mock_get_interpolation_keys):

            value = parser._interpolate_value('__main__', 'foo')
            self.assertEqual(value, None)
    def test_interpolate_value_no_keys(self):
        """Test interpolate_value with no keys."""
        class MySchema(Schema):
            foo = TupleOption(2)
        config = StringIO("[__main__]\nfoo=%(bar)s,%(bar)s")

        mock_get_interpolation_keys = Mock(return_value=('%(bar)s', None))

        parser = SchemaConfigParser(MySchema())
        parser.readfp(config)
        with patch.object(parser, '_get_interpolation_keys',
                mock_get_interpolation_keys):

            value = parser._interpolate_value('__main__', 'foo')
            self.assertEqual(value, None)