def is_test_stories_file(file_path: Text) -> bool: """Checks if a file is a test stories file. Args: file_path: Path of the file which should be checked. Returns: `True` if it's a story file containing tests, otherwise `False`. """ from rasa.shared.core.training_data.story_reader.yaml_story_reader import ( YAMLStoryReader, ) from rasa.shared.core.training_data.story_reader.markdown_story_reader import ( MarkdownStoryReader, ) return YAMLStoryReader.is_test_stories_file( file_path) or MarkdownStoryReader.is_test_stories_file(file_path)
def _init_from_directory(self, path: Text) -> None: for parent, _, files in os.walk(path, followlinks=True): for file in files: full_path = os.path.join(parent, file) if not self.is_imported(full_path): # Check next file continue if YAMLStoryReader.is_test_stories_file(full_path): self._e2e_story_paths.append(full_path) elif Domain.is_domain_file(full_path): self._domain_paths.append(full_path) elif rasa.shared.data.is_nlu_file(full_path): self._nlu_paths.append(full_path) elif YAMLStoryReader.is_stories_file(full_path): self._story_paths.append(full_path) elif rasa.shared.data.is_config_file(full_path): self._init_from_file(full_path)
def test_is_not_test_story_file_without_test_prefix(tmp_path: Path): path = str(tmp_path / "stories.yml") rasa.shared.utils.io.write_yaml({"stories": []}, path) assert not YAMLStoryReader.is_test_stories_file(path)
def test_is_not_test_story_file_raises_if_file_does_not_exist(tmp_path: Path): path = str(tmp_path / "test_stories.yml") with pytest.raises(FileNotFoundException): YAMLStoryReader.is_test_stories_file(path)
def test_is_not_test_story_file_if_it_doesnt_contain_stories(tmp_path: Path): path = str(tmp_path / "test_stories.yml") rasa.shared.utils.io.write_yaml({"nlu": []}, path) assert not YAMLStoryReader.is_test_stories_file(path)
def test_is_not_test_story_file_raises_if_file_does_not_exist(tmp_path: Path): path = str(tmp_path / "test_stories.yml") with pytest.raises(ValueError): YAMLStoryReader.is_test_stories_file(path)
def test_is_not_test_story_file_if_empty(tmp_path: Path): path = str(tmp_path / "test_stories.yml") assert not YAMLStoryReader.is_test_stories_file(path)