Skip to content

Commit

Permalink
Refactor Services expanded forms to match sdks.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpyle0819 committed Mar 11, 2024
1 parent d2a149b commit 0c5e904
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 33 deletions.
27 changes: 15 additions & 12 deletions aws_doc_sdk_examples_tools/metadata_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)
from aws_doc_sdk_examples_tools.doc_gen import DocGen
from aws_doc_sdk_examples_tools.sdks import Sdk
from aws_doc_sdk_examples_tools.services import Service
from aws_doc_sdk_examples_tools.services import Service, ServiceExpanded


def load(
Expand All @@ -38,41 +38,44 @@ def load(
SERVICES = {
"ses": Service(
long="&SESlong;",
expanded_long="Amazon Simple Email Service (Amazon SES)",
short="&SES;",
expanded_short="Amazon SES",
expanded=ServiceExpanded(
long="Amazon Simple Email Service (Amazon SES)", short="Amazon SES"
),
sort="ses",
version=1,
),
"sns": Service(
long="&SNSlong;",
expanded_long="Amazon Simple Notification Service (Amazon SNS)",
short="&SNS;",
expanded_short="Amazon SNS",
expanded=ServiceExpanded(
long="Amazon Simple Notification Service (Amazon SNS)", short="Amazon SNS"
),
sort="sns",
version=1,
),
"sqs": Service(
long="&SQSlong;",
expanded_long="Amazon Simple Queue Service (Amazon SQS)",
short="&SQS;",
expanded_short="Amazon SQS",
expanded=ServiceExpanded(
long="Amazon Simple Queue Service (Amazon SQS)", short="Amazon SQS"
),
sort="sqs",
version=1,
),
"s3": Service(
long="&S3long;",
expanded_long="Amazon Simple Storage Service (Amazon S3)",
short="&S3;",
expanded_short="Amazon S3",
expanded=ServiceExpanded(
long="Amazon Simple Storage Service (Amazon S3)", short="Amazon S3"
),
sort="s3",
version=1,
),
"autogluon": Service(
long="AutoGluon Test",
expanded_long="AutoGluon Test",
short="AG Test",
expanded_short="AutoGluon Test",
expanded=ServiceExpanded(long="AutoGluon Test", short="AutoGluon Test"),
sort="autogluon",
version=1,
),
Expand Down Expand Up @@ -447,7 +450,7 @@ def test_common_errors(
assert expected_errors == [*actual]


TEST_SERVICES = {"test": Service("test", "test", "test", "test", "test", "1")}
TEST_SERVICES = {"test": Service("test", "test", "test", "1")}


def test_idFormat():
Expand Down
31 changes: 19 additions & 12 deletions aws_doc_sdk_examples_tools/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
from aws_doc_sdk_examples_tools.metadata_errors import MetadataErrors, check_mapping


@dataclass
class ServiceExpanded:
long: str
short: str


@dataclass
class ServiceGuide:
subtitle: str
Expand All @@ -18,11 +24,10 @@ class ServiceGuide:
@dataclass
class Service:
long: str
expanded_long: str
short: str
expanded_short: str
sort: str
version: Union[int, str]
expanded: Optional[ServiceExpanded] = field(default=None)
api_ref: Optional[str] = field(default=None)
blurb: Optional[str] = field(default=None)
bundle: Optional[str] = field(default=None)
Expand All @@ -37,9 +42,8 @@ def from_yaml(
errors = MetadataErrors()

long = check_mapping(yaml.get("long"), "long")
expanded_long = yaml.get("expanded", {}).get("long")
expanded = yaml.get("expanded")
short = check_mapping(yaml.get("short"), "short")
expanded_short = yaml.get("expanded", {}).get("short")
sort = yaml.get("sort")
version = yaml.get("version")

Expand All @@ -49,12 +53,16 @@ def from_yaml(
if isinstance(short, metadata_errors.MetadataParseError):
errors.append(short)
short = ""
if expanded_long is None:
errors.append(metadata_errors.MissingField(field="expanded_long"))
expanded_long = ""
if expanded_short is None:
errors.append(metadata_errors.MissingField(field="expanded_short"))
expanded_short = ""
if expanded is None:
errors.append(metadata_errors.MissingField(field="expanded"))
else:
long_expanded = expanded.get("long")
short_expanded = expanded.get("short")
if not long_expanded:
errors.append(metadata_errors.MissingField(field="expanded.long"))
if not short_expanded:
errors.append(metadata_errors.MissingField(field="expanded.short"))
expanded = ServiceExpanded(long=long_expanded, short=short_expanded)
if sort is None:
errors.append(metadata_errors.MissingField(field="sort"))
sort = ""
Expand Down Expand Up @@ -87,9 +95,8 @@ def from_yaml(
return (
cls(
long=long,
expanded_long=expanded_long,
short=short,
expanded_short=expanded_short,
expanded=expanded,
sort=sort,
api_ref=api_ref,
blurb=blurb,
Expand Down
26 changes: 17 additions & 9 deletions aws_doc_sdk_examples_tools/services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import yaml

from aws_doc_sdk_examples_tools import metadata_errors
from aws_doc_sdk_examples_tools.services import parse, Service, ServiceGuide
from aws_doc_sdk_examples_tools.services import (
parse,
Service,
ServiceGuide,
ServiceExpanded,
)


def load(path: str) -> Tuple[Dict[str, Service], metadata_errors.MetadataErrors]:
Expand Down Expand Up @@ -47,9 +52,10 @@ def test_services():
assert examples == {
"s3": Service(
short="&S3;",
expanded_short="Amazon S3",
expanded=ServiceExpanded(
long="Amazon Simple Storage Service (Amazon S3)", short="Amazon S3"
),
long="&S3long;",
expanded_long="Amazon Simple Storage Service (Amazon S3)",
sort="S3",
version="s3-2006-03-01",
caveat="The examples in this section are pretty neat, and we recommend you print them out so you can read them in bed with a good glass of wine.",
Expand All @@ -62,18 +68,21 @@ def test_services():
),
"sns": Service(
short="&SNS;",
expanded_short="Amazon SNS",
long="&SNSlong;",
expanded_long="Amazon Simple Notification Service (Amazon SNS)",
expanded=ServiceExpanded(
long="Amazon Simple Notification Service (Amazon SNS)",
short="Amazon SNS",
),
sort="SNS",
version="sns-2010-03-31",
bundle="sqs",
),
"sqs": Service(
short="&SQS;",
expanded_short="Amazon SQS",
long="&SQSlong;",
expanded_long="Amazon Simple Queue Service (Amazon SQS)",
expanded=ServiceExpanded(
long="Amazon Simple Queue Service (Amazon SQS)", short="Amazon SQS"
),
sort="SQS",
tags={
"product_categories": set(["Category 1", "Category 2"]),
Expand All @@ -83,9 +92,8 @@ def test_services():
),
"textract": Service(
short="&TEXTRACT;",
expanded_short="Amazon Textract",
long="&TEXTRACTlong;",
expanded_long="Amazon Textract",
expanded=ServiceExpanded(long="Amazon Textract", short="Amazon Textract"),
sort="Textract",
tags={"product_categories": set(["Category 1"])},
version="textract-2018-06-27",
Expand Down

0 comments on commit 0c5e904

Please sign in to comment.