There's something kind of odd with styles in OGCServer. In loadXML in BaseWMSFactory you have an if / else branch on style_count, the number of styles for a layer in the xml file. Zero raises an error; after that you distinct between style_count == 1 and style_count > 1.
Ignoring meta styles for now, if a layer has 1 style only, you add this style to both props layer.wmsdefaultstyle and layer.wmsextrastyles, by calling register_layer as follows:
self.register_layer(lyr_, style_name, extrastyles=(style_name,))
When requesting a map, a style must be contained in layer.wmsextrastyles to be a valid candidate for the STYLE WMS parameter (if not, you raise an exception). Since the layer's style has been added to both layer.wmsdefaultstyle and layer.wmsextrastyles, you can add this style to your request's STYLE parameter or not - you always get the same result and no exception.
The problem with these single-style layers comes with the GetCapabilities request. You advertise styles for a layer only, if there are extra styles present. However, you write out the default style and all extra styles. As a result, for single-style layers, the layer's default style occurs twice in the capabilities document. According to OGC, default styles may be omitted from the capabilities response.
With multi-style layers, things go different. You create an xxx_aggregates style, that is used as the layer's default style. The actual styles go into extra styles. As with all layers, both default and extra styles are published in the capabilities document. However, since the advertised xxx_aggregates default style is not part of extra styles, you'll get an exception, if you actually include it in you STYLES parameter.
IMO, only extra styles should be advertised in the capabilities document. Single-style layers should not add their style name to layer.wmsextrastyles. Then, these problems could be fixed with only two modifications: (actually three, since there is wms111 and wms130)
First, change WMS.py, line 128 from
self.register_layer(lyr_, style_name, extrastyles=(style_name,))
to
self.register_layer(lyr_, style_name, extrastyles=())
Then, change in both wms111.py, line 211 and wms130.py, line 234 from
for extrastyle in [layer.wmsdefaultstyle] + list(layer.wmsextrastyles):
to
for extrastyle in list(layer.wmsextrastyles):
However, after that, it is no longer possible to explicitly request the default style through the STYLE parameter for any layer (currently it's possible for single-style layers).
Carsten