Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix temporary files in 'rasa test' #8217

Merged
merged 14 commits into from
Mar 25, 2021
Merged

fix temporary files in 'rasa test' #8217

merged 14 commits into from
Mar 25, 2021

Conversation

wochinge
Copy link
Contributor

@wochinge wochinge commented Mar 16, 2021

Proposed changes:

  • fix During rasa test, YamlValidationException shows temp path #7640
  • introduce a new method TrainingDataImporter.get_conversation_tests which only retrieves conversation test files
  • change server to store test data in the expected format (tests directory for Markdown, test_ prefix for YAML)
  • use TrainingDataImporter to load data instead of moving eligble files to a separate temporary directory
  • added docstrings for importer package
  • renamed conversation test files to match expections (test_ prefix for YAML)

Status (please check what you already did):

  • added some tests for the functionality
  • updated the documentation
  • updated the changelog (please check changelog for instructions)
  • reformat files using black (please check Readme for instructions)

@wochinge wochinge force-pushed the temp-filepaths-testing branch 6 times, most recently from 5fca09e to 1e3b6a0 Compare March 16, 2021 18:31
@@ -54,10 +58,18 @@ async def get_stories(
exclusion_percentage,
)

async def get_conversation_tests(self) -> StoryGraph:
"""Retrieves conversation test stories (see parent class for full docstring)."""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the alternative is to filter in get_stories based on use_e2e. Considering this and also to avoid anything breaking I decided to go for the explict extra method

@@ -138,7 +138,7 @@ def incorrect_nlu_data_path() -> Text:

@pytest.fixture(scope="session")
def end_to_end_story_path() -> Text:
return "data/test_evaluations/end_to_end_story.yml"
return "data/test_evaluations/test_end_to_end_story.yml"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test stories need to include the test_ prefix. Our tests were violating this.

@wochinge wochinge marked this pull request as ready for review March 17, 2021 12:50
@wochinge wochinge requested review from a team and joejuzl and removed request for a team March 17, 2021 12:50
Copy link
Contributor

@joejuzl joejuzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you pinpoint for me the line which used to move the files to the temporary directory?

Returns:
`StoryGraph` containing all loaded stories.
"""
return await self.get_stories(use_e2e=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this implemented in the interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is implemented as fallback. Ideally they override this when they have a custom TrainingDataImporter class. We cannot let it raise in case it's not implemented as this might break existing implementations of custom TrainingDataImporters


Args:
model_dir: path to directory that contains the models to evaluate
stories_file: path to the story file
output: output directory to store results to
use_e2e: `True` if markdown story files should be parsed as end-to-end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not all it's doing right? It's also determining which files to load.

@@ -352,7 +352,11 @@ async def _create_data_generator(
test_data_importer = TrainingDataImporter.load_from_dict(
training_data_paths=[resource_name]
)
story_graph = await test_data_importer.get_stories(use_e2e=use_e2e)
if use_e2e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this branching is confusing, as we are also passing in a variable resource_name into the importer. It's hard to know how those two different things interplay. Would it not be clearer if we do this resource selection up higher when we start the test process, and then use_e2e could remain solely for determining how to read the file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point. The TrainingDataImporter is already categorizing files (e.g. into nlu and stories) and hence I think this should be part of the TrainingDataImporter. As this function _create_data_generator is called from different entrypoints I found it preferable to handle this in one place instead of multiple ones. Otherwise we might run into situations as we had it before where e.g. tests or also the server weren't respecting the conditions we have on these test files (e.g. the test_ prefix).

I agree that this is all confusing though 🙈 This still seemed the somewhat clearest approach to me though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use a different name than use_e2e then? As it normally dictates what reader to use.
e.g. conversation_test_stories?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean renaming it within _create_data_generator or in general in the entire module? I'd be open to rename it for _create_data_generator but unfortunately use_e2e has multiple other implications on the testing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but unfortunately use_e2e has multiple other implications on the testing

This is why it might make sense to rename. You've added it to lots of methods in this PR with the sole aim of selecting different files in this method. Whereas it normally has the meaning of how a markdown file is read. When we remove markdown, and hopefully a lot of usages of use_e2e, we will still need this one to select conversation tests.

@@ -154,8 +152,12 @@ async def run_nlu_test_async(
test_nlu,
)

nlu_data = rasa.cli.utils.get_validated_path(data_path, "nlu", DEFAULT_DATA_PATH)
nlu_data = rasa.shared.data.get_nlu_directory(nlu_data)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joejuzl This was moving NLU files to temporary directories

Comment on lines -81 to -84
if args.e2e:
stories = rasa.shared.data.get_test_directory(stories)
else:
stories = rasa.shared.data.get_core_directory(stories)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joejuzl This was moving Core files to temporary directories

Copy link
Contributor

@joejuzl joejuzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reasonable way to test we are no longer creating the temp directories?

@@ -352,7 +352,11 @@ async def _create_data_generator(
test_data_importer = TrainingDataImporter.load_from_dict(
training_data_paths=[resource_name]
)
story_graph = await test_data_importer.get_stories(use_e2e=use_e2e)
if use_e2e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use a different name than use_e2e then? As it normally dictates what reader to use.
e.g. conversation_test_stories?

@@ -48,16 +48,23 @@ async def get_stories(
Returns:
`StoryGraph` containing all loaded stories.
"""

# TODO: Drop `use_e2e` in Rasa Open Source 3.0.0 when removing Markdown support
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing now that use_e2e also determines which files are loaded right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope the renamed parameters make this less confusing. The importer only uses use_e2e for configuring the markdown reading. Means we no longer need it when Markdown is removed.

return self.config

async def get_nlu_data(self, language: Optional[Text] = "en") -> TrainingData:
"""Retrieves NLU training data (see parent class for full docstring)."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a convention for docstrings on subclasses?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not specifically. It's somewhat my personal preference to write a proper docstring in one place and then link to it (ideally I'd just omit but that doesn't work with pydocstyle)

@wochinge
Copy link
Contributor Author

Is there a reasonable way to test we are no longer creating the temp directories?

I gave it a manual testing by putting a story with an invalid schema in the tests directory. I don't really fancy testing specific log message so opted for not testing this.

@wochinge wochinge force-pushed the temp-filepaths-testing branch from de10a14 to 64856b0 Compare March 24, 2021 10:47
@wochinge wochinge requested a review from joejuzl March 24, 2021 10:47
test_dir = temporary_directory / DEFAULT_CONVERSATION_TEST_PATH
test_dir.mkdir()
test_file = test_dir / f"tests{suffix}"
test_file.write_bytes(request.body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this close the file after?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

@wochinge wochinge requested a review from joejuzl March 24, 2021 16:56
Copy link
Contributor

@joejuzl joejuzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@wochinge wochinge enabled auto-merge March 24, 2021 17:07
@wochinge wochinge merged commit 4b8f745 into main Mar 25, 2021
@wochinge wochinge deleted the temp-filepaths-testing branch March 25, 2021 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

During rasa test, YamlValidationException shows temp path
2 participants