Skip to content

Commit

Permalink
Add docstring style: Accessible
Browse files Browse the repository at this point in the history
Closes #340 & #342
  • Loading branch information
tefra committed Dec 9, 2020
1 parent 390b244 commit c0f6b52
Show file tree
Hide file tree
Showing 48 changed files with 863 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
with:
python-version: ${{ matrix.python }}
- name: Install libxml2
if: matrix.python == '3.9-dev' || matrix.python == 'pypy3'
if: matrix.python == 'pypy3'
run: |
sudo apt-get install libxml2-dev libxslt-dev
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion docs/scripts/generate_data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}


for tp, data_types in group_by(list(DataType), key=lambda x: x.local_name).items():
for tp, data_types in group_by(list(DataType), key=lambda x: x.type.__name__).items():
output.append(f" * - :class:`{custom_classes.get(tp, tp)}`")

count = 0
Expand Down
12 changes: 6 additions & 6 deletions tests/codegen/mappers/test_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ def test_map_binding_operation(
ns_map={"foo": "bar"},
attrs=[
DefinitionsMapper.build_attr(
"a", DataType.STRING.qname, native=True, default="one"
"a", str(DataType.STRING), native=True, default="one"
),
DefinitionsMapper.build_attr(
"b", DataType.STRING.qname, native=True, default="two"
"b", str(DataType.STRING), native=True, default="two"
),
DefinitionsMapper.build_attr(
"style", DataType.STRING.qname, native=True, default="rpc"
"style", str(DataType.STRING), native=True, default="rpc"
),
DefinitionsMapper.build_attr("first", first.qname),
DefinitionsMapper.build_attr("second", second.qname),
Expand Down Expand Up @@ -472,7 +472,7 @@ def test_build_envelope_fault(self):
expected_fault_attr = DefinitionsMapper.build_attr(
"Fault", body.inner[0].qname, forward=True, namespace=target.namespace
)
str_qname = DataType.STRING.qname
str_qname = str(DataType.STRING)
expected_fault_attrs = [
DefinitionsMapper.build_attr(name, str_qname, native=True, namespace="")
for name in ["faultcode", "faultstring", "faultactor", "detail"]
Expand All @@ -499,7 +499,7 @@ def test_build_envelope_fault_with_detail_messages(self):
expected_fault_attr = DefinitionsMapper.build_attr(
"Fault", body.inner[0].qname, forward=True, namespace=target.namespace
)
str_qname = DataType.STRING.qname
str_qname = str(DataType.STRING)
expected_fault_attrs = [
DefinitionsMapper.build_attr(name, str_qname, native=True, namespace="")
for name in ["faultcode", "faultstring", "faultactor"]
Expand Down Expand Up @@ -672,7 +672,7 @@ def test_build_parts_attributes(self, mock_warning):
"bar", build_qname("great", "bar"), namespace="great", native=False
),
DefinitionsMapper.build_attr(
"arg0", DataType.STRING.qname, namespace="", native=True
"arg0", str(DataType.STRING), namespace="", native=True
),
DefinitionsMapper.build_attr(
"arg1", build_qname("boo", "cafe"), namespace="", native=False
Expand Down
22 changes: 11 additions & 11 deletions tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def create(
qname = build_qname("xsdata", f"attr_{cls.next_letter()}")

return cls.model(
qname=qname,
qname=str(qname),
alias=alias,
native=native,
circular=circular,
Expand All @@ -185,43 +185,43 @@ def create(

@classmethod
def xs_string(cls):
return cls.create(qname=DataType.STRING.qname, native=True)
return cls.create(qname=DataType.STRING, native=True)

@classmethod
def xs_int(cls):
return cls.create(qname=DataType.INTEGER.qname, native=True)
return cls.create(qname=DataType.INTEGER, native=True)

@classmethod
def xs_positive_int(cls):
return cls.create(qname=DataType.POSITIVE_INTEGER.qname, native=True)
return cls.create(qname=DataType.POSITIVE_INTEGER, native=True)

@classmethod
def xs_float(cls):
return cls.create(qname=DataType.FLOAT.qname, native=True)
return cls.create(qname=DataType.FLOAT, native=True)

@classmethod
def xs_decimal(cls):
return cls.create(qname=DataType.DECIMAL.qname, native=True)
return cls.create(qname=DataType.DECIMAL, native=True)

@classmethod
def xs_bool(cls):
return cls.create(qname=DataType.BOOLEAN.qname, native=True)
return cls.create(qname=DataType.BOOLEAN, native=True)

@classmethod
def xs_any(cls):
return cls.create(qname=DataType.ANY_TYPE.qname, native=True)
return cls.create(qname=DataType.ANY_TYPE, native=True)

@classmethod
def xs_qname(cls):
return cls.create(qname=DataType.QNAME.qname, native=True)
return cls.create(qname=DataType.QNAME, native=True)

@classmethod
def xs_tokens(cls):
return cls.create(qname=DataType.NMTOKENS.qname, native=True)
return cls.create(qname=DataType.NMTOKENS, native=True)

@classmethod
def xs_error(cls):
return cls.create(qname=DataType.ERROR.qname, native=True)
return cls.create(qname=DataType.ERROR, native=True)


class AttrFactory(Factory):
Expand Down
7 changes: 5 additions & 2 deletions tests/fixtures/books/books.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

@dataclass
class BookForm:
"""Book Definition.
"""
Book Definition.
Attributes
author: Writer's name
Expand Down Expand Up @@ -94,7 +95,9 @@ class BooksForm:

@dataclass
class Books(BooksForm):
"""Το βιβλίο."""
"""
Το βιβλίο.
"""
class Meta:
name = "books"
namespace = "urn:books"
Empty file.
4 changes: 4 additions & 0 deletions tests/fixtures/docstrings/accessible/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from tests.fixtures.docstrings.accessible.schema import (
Root,
RootEnum,
)
99 changes: 99 additions & 0 deletions tests/fixtures/docstrings/accessible/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
from dataclasses import dataclass, field
from enum import Enum
from typing import Optional

__NAMESPACE__ = "urn:books"


class RootEnum(Enum):
A = "A"
B = "B"


RootEnum.A.__doc__ = "Lorem ipsum dolor"
RootEnum.B.__doc__ = (
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi dapibus."
)


@dataclass
class Root:
"""This is the root type documentation. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Morbi dapibus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec
imperdiet lacus sed sagittis scelerisque. Ut sodales metus: "sit",
"amet", "lectus"
"""
class Meta:
namespace = "urn:books"

a: Optional["Root.A"] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
"doc": (
"This is an inner type field documentation.\nLorem ipsum dolor"
" sit amet, consectetur adipiscing elit. Aliquam nec."
),
}
)
b: Optional["Root.B"] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
"doc": "This is a second root type field documentation.",
}
)
c: Optional[RootEnum] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
d: Optional["Root.D"] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)

@dataclass
class A:
"""
This is an inner type documentation.
"""
sub_a: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
"doc": (
"This is an inner type field documentation.\nLorem ipsum dolor"
" sit amet, consectetur adipiscing elit. Vivamus efficitur."
),
}
)

class B(Enum):
YES = "Yes"
NO = "No"

B.YES.__doc__ = (
"This is an inner enum member documentation. Lorem ipsum dolor sit amet, "
"consectetur adipiscing elit. Etiam mollis."
)
B.NO.__doc__ = "Lorem ipsum dolor"

class D(Enum):
TRUE_VALUE = "true"
FALSE_VALUE = "false"
4 changes: 4 additions & 0 deletions tests/fixtures/docstrings/google/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from tests.fixtures.docstrings.google.schema import (
Root,
RootEnum,
)
101 changes: 101 additions & 0 deletions tests/fixtures/docstrings/google/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
from dataclasses import dataclass, field
from enum import Enum
from typing import Optional

__NAMESPACE__ = "urn:books"


class RootEnum(Enum):
"""
Attributes
A: Lorem ipsum dolor
B: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi
dapibus.
"""
A = "A"
B = "B"


@dataclass
class Root:
"""This is the root type documentation. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Morbi dapibus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec
imperdiet lacus sed sagittis scelerisque. Ut sodales metus: "sit",
"amet", "lectus"
Attributes
a: This is an inner type field documentation. Lorem ipsum dolor sit
amet, consectetur adipiscing elit. Aliquam nec.
b: This is a second root type field documentation.
c:
d:
"""
class Meta:
namespace = "urn:books"

a: Optional["Root.A"] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
b: Optional["Root.B"] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
c: Optional[RootEnum] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)
d: Optional["Root.D"] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)

@dataclass
class A:
"""
This is an inner type documentation.
Attributes
sub_a: This is an inner type field documentation. Lorem ipsum dolor
sit amet, consectetur adipiscing elit. Vivamus efficitur.
"""
sub_a: Optional[str] = field(
default=None,
metadata={
"type": "Element",
"namespace": "",
"required": True,
}
)

class B(Enum):
"""
Attributes
YES: This is an inner enum member documentation. Lorem ipsum dolor
sit amet, consectetur adipiscing elit. Etiam mollis.
NO: Lorem ipsum dolor
"""
YES = "Yes"
NO = "No"

class D(Enum):
TRUE_VALUE = "true"
FALSE_VALUE = "false"
4 changes: 4 additions & 0 deletions tests/fixtures/docstrings/numpy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from tests.fixtures.docstrings.numpy.schema import (
Root,
RootEnum,
)
Loading

0 comments on commit c0f6b52

Please sign in to comment.