-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Conversation
5fca09e
to
1e3b6a0
Compare
@@ -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).""" |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 TrainingDataImporter
s
rasa/core/test.py
Outdated
|
||
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 |
There was a problem hiding this comment.
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.
rasa/core/test.py
Outdated
@@ -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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
if args.e2e: | ||
stories = rasa.shared.data.get_test_directory(stories) | ||
else: | ||
stories = rasa.shared.data.get_core_directory(stories) |
There was a problem hiding this comment.
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
There was a problem hiding this 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?
rasa/core/test.py
Outdated
@@ -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: |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).""" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
)
I gave it a manual testing by putting a story with an invalid schema in the |
de10a14
to
64856b0
Compare
test_dir = temporary_directory / DEFAULT_CONVERSATION_TEST_PATH | ||
test_dir.mkdir() | ||
test_file = test_dir / f"tests{suffix}" | ||
test_file.write_bytes(request.body) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Proposed changes:
TrainingDataImporter.get_conversation_tests
which only retrieves conversation test filestests
directory for Markdown,test_
prefix for YAML)TrainingDataImporter
to load data instead of moving eligble files to a separate temporary directoryimporter
packagetest_
prefix for YAML)Status (please check what you already did):
black
(please check Readme for instructions)