mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-23 04:36:17 +01:00
Merge branch 'ebassi/issue-2601' into 'main'
Fix the DocBook codegen Closes #2601 See merge request GNOME/glib!2489
This commit is contained in:
commit
c39c2a2821
4
gio/gdbus-2.0/codegen/.flake8
Normal file
4
gio/gdbus-2.0/codegen/.flake8
Normal file
@ -0,0 +1,4 @@
|
||||
[flake8]
|
||||
# We are generating long lines through templates
|
||||
max-line-length = 120
|
||||
exclude = __pycache__
|
@ -25,10 +25,6 @@ from os import path
|
||||
from . import utils
|
||||
|
||||
|
||||
# Disable line length warnings as wrapping the Docbook templates would be hard
|
||||
# flake8: noqa: E501
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -346,7 +342,7 @@ class DocbookCodeGenerator:
|
||||
def expand_paras(self, s, expandParamsAndConstants):
|
||||
s = self.expand(s, expandParamsAndConstants).strip()
|
||||
res = []
|
||||
if not s.startswith("<para"):
|
||||
if not s.startswith("<para>"):
|
||||
res.append("<para>")
|
||||
for line in s.split("\n"):
|
||||
line = line.strip()
|
||||
|
@ -77,13 +77,13 @@ class DBusXMLParser:
|
||||
colon_index = line.find(": ")
|
||||
if colon_index == -1:
|
||||
if line.endswith(":"):
|
||||
symbol = line[0 : len(line) - 1]
|
||||
symbol = line[0:len(line) - 1]
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_PARAMS
|
||||
else:
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_SKIP
|
||||
else:
|
||||
symbol = line[0:colon_index]
|
||||
rest_of_line = line[colon_index + 2 :].strip()
|
||||
rest_of_line = line[colon_index + 2:].strip()
|
||||
if len(rest_of_line) > 0:
|
||||
body += f"{rest_of_line}\n"
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_PARAMS
|
||||
@ -98,7 +98,7 @@ class DBusXMLParser:
|
||||
body += f"{orig_line}\n"
|
||||
else:
|
||||
param = line[1:colon_index]
|
||||
docs = line[colon_index + 2 :]
|
||||
docs = line[colon_index + 2:]
|
||||
params[param] = docs
|
||||
else:
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_BODY
|
||||
|
@ -27,10 +27,10 @@ import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
import taptestrunner
|
||||
|
||||
|
||||
# Disable line length warnings as wrapping the C code templates would be hard
|
||||
# flake8: noqa: E501
|
||||
|
||||
@ -625,6 +625,40 @@ G_END_DECLS
|
||||
self.assertEqual(result.out.strip().count("GDBusCallFlags call_flags,"), 2)
|
||||
self.assertEqual(result.out.strip().count("gint timeout_msec,"), 2)
|
||||
|
||||
def test_generate_valid_docbook(self):
|
||||
"""Test the basic functionality of the docbook generator."""
|
||||
xml_contents = """
|
||||
<node>
|
||||
<interface name="org.project.Bar.Frobnicator">
|
||||
<!-- Resize:
|
||||
@size: New partition size in bytes, 0 for maximal size.
|
||||
@options: Options.
|
||||
@since 2.7.2
|
||||
|
||||
Resizes the partition.
|
||||
|
||||
The partition will not change its position but might be slightly bigger
|
||||
than requested due to sector counts and alignment (e.g. 1MiB).
|
||||
If the requested size can't be allocated it results in an error.
|
||||
The maximal size can automatically be set by using 0 as size.
|
||||
-->
|
||||
<method name="Resize">
|
||||
<arg name="size" direction="in" type="t"/>
|
||||
<arg name="options" direction="in" type="a{sv}"/>
|
||||
</method>
|
||||
</interface>
|
||||
</node>
|
||||
"""
|
||||
res = self.runCodegenWithInterface(
|
||||
xml_contents,
|
||||
"--generate-docbook",
|
||||
"test",
|
||||
)
|
||||
self.assertEqual("", res.err)
|
||||
self.assertEqual("", res.out)
|
||||
with open("test-org.project.Bar.Frobnicator.xml", "r") as f:
|
||||
self.assertTrue(ET.parse(f) is not None)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(testRunner=taptestrunner.TAPTestRunner())
|
||||
|
Loading…
Reference in New Issue
Block a user