Skip to content

Commit

Permalink
Merge pull request #34 from Safe/fix_test
Browse files Browse the repository at this point in the history
Update tests to avoid failing due to order of categories
  • Loading branch information
hhtong authored and GitHub Enterprise committed Aug 7, 2024
2 parents 21fec95 + 56f60a9 commit 1bcb40a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions fme_packager/summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import tempfile
from collections import namedtuple
from pathlib import Path
from typing import Iterable, Set
from typing import Iterable, List

import yaml
from jsonschema import validate
Expand Down Expand Up @@ -161,12 +161,12 @@ def _content_description(readme_filename: str) -> dict:
}


def _get_all_categories(transformers: Iterable[dict], formats: Iterable[dict]) -> Set[str]:
def _get_all_categories(transformers: Iterable[dict], formats: Iterable[dict]) -> List[str]:
"""
Get the union of all the categories from the transformers.
:param transformers: An iterable of transformer dicts
:return: A set of all categories from the transformers.
:return: An alphabetically sorted list of all categories from the transformers.
"""
all_categories = set()
for transformer in transformers:
Expand All @@ -183,7 +183,10 @@ def _get_all_categories(transformers: Iterable[dict], formats: Iterable[dict]) -
if not format.get("categories", None):
continue
all_categories.update(format["categories"])
return all_categories

all_categories_list = list(all_categories)
all_categories_list.sort()
return all_categories_list


def _enhance_transformer_info(transformers: Iterable[dict]) -> Iterable[dict]:
Expand Down Expand Up @@ -298,7 +301,7 @@ def summarize_fpkg(fpkg_path: str) -> str:
manifest["package_content"]["formats"] = _enhance_format_info(
manifest.get("publisher_uid", ""), manifest.get("uid", ""), formats
)
manifest["categories"] = list(_get_all_categories(transformers, formats))
manifest["categories"] = _get_all_categories(transformers, formats)
try:
validate(manifest, output_schema)
except ValidationError as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"transformers": []
},
"categories": [
"Strings",
"Database"
"Database",
"Strings"
]
}
2 changes: 1 addition & 1 deletion tests/test_summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def mock_formats():

def test__get_all_categories(mock_transformers, mock_formats):
result = summarizer._get_all_categories(mock_transformers, mock_formats)
assert result == {"cat-f1", "cat-f2", "cat1", "cat2", "cat3", "cat4", "cat5"}
assert result == ["cat-f1", "cat-f2", "cat1", "cat2", "cat3", "cat4", "cat5"]


def test__add_content_description(mocker):
Expand Down

0 comments on commit 1bcb40a

Please sign in to comment.