This is an automated email from the ASF dual-hosted git repository. damccorm pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push: new 15f3717a43e Fix example checker validation for incomplete multifile examples (#24993) 15f3717a43e is described below commit 15f3717a43eb79910c5ddc6f4bb7c06843c744b1 Author: Oleh Borysevych <oleg.borisev...@akvelon.com> AuthorDate: Fri Jan 13 18:36:59 2023 +0200 Fix example checker validation for incomplete multifile examples (#24993) * fix checker and try to trigger incomplete file validation * restore correct tag * fixing filepath * added parameter type for clarity * fixing error handling --- playground/infrastructure/helper.py | 20 +++++++++++++------- playground/infrastructure/test_helper.py | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/playground/infrastructure/helper.py b/playground/infrastructure/helper.py index c4ed49f78cf..9d63d80f28d 100644 --- a/playground/infrastructure/helper.py +++ b/playground/infrastructure/helper.py @@ -155,7 +155,7 @@ async def get_statuses( await tqdm.gather(*tasks) -def get_tag(filepath) -> Optional[Tag]: +def get_tag(filepath: PurePath) -> Optional[Tag]: """ Parse file by filepath and find beam tag @@ -188,13 +188,19 @@ def get_tag(filepath) -> Optional[Tag]: line[len(tag_prefix) :] for line in lines[line_start:line_finish] ) yml = yaml.load(embdedded_yaml_content, Loader=yaml.SafeLoader) - return Tag( - filepath=filepath, - line_start=line_start, - line_finish=line_finish, - **yml[Config.BEAM_PLAYGROUND], - ) + try: + return Tag( + filepath=str(filepath), + line_start=line_start, + line_finish=line_finish, + **yml[Config.BEAM_PLAYGROUND], + ) + except pydantic.ValidationError as err: + if len(err.errors()) == 1 and err.errors()[0]["msg"] == "multifile is True but no files defined": + logging.warning("incomplete multifile example ignored %s", filepath) + return None + raise def _load_example(filename, filepath, sdk: SdkEnum) -> Optional[Example]: """ diff --git a/playground/infrastructure/test_helper.py b/playground/infrastructure/test_helper.py index e7ec797fd74..164adf588e1 100644 --- a/playground/infrastructure/test_helper.py +++ b/playground/infrastructure/test_helper.py @@ -568,6 +568,33 @@ def test_get_tag_multifile(): }, ) +@mock.patch( + "builtins.open", + mock_open( + read_data=""" + +// beam-playground: +// name: MultifileExample +// description: Test example with imports +// multifile: true +// context_line: 55 +// categories: +// - Filtering +// - Options +// - Quickstart +// complexity: MEDIUM +// tags: +// - filter +// - strings +// - emulator + +""" + ), +) + +def test_get_tag_multifile_incomplete(): + tag = get_tag("../../examples/MOCK_EXAMPLE/main.java") + assert tag is None @mock.patch("os.path.isfile", return_value=True) def test_dataset_path_ok(mock_file_check, create_test_example):