def test_is_nlu_file_with_json(): test = { "rasa_nlu_data": { "lookup_tables": [ {"name": "plates", "elements": ["beans", "rice", "tacos", "cheese"]} ] } } directory = tempfile.mkdtemp() file = os.path.join(directory, "test.json") with open(file, "w", encoding="utf-8") as f: f.write(json_to_string(test)) assert data.is_nlu_file(file)
def test_is_nlu_file_with_json(): test = { "rasa_nlu_data": { "lookup_tables": [ {"name": "plates", "elements": ["beans", "rice", "tacos", "cheese"]} ] } } directory = tempfile.mkdtemp() file = os.path.join(directory, "test.json") io.write_text_file(json_to_string(test), file) assert data.is_nlu_file(file)
def _init_from_directory(self, path: Text): for parent, _, files in os.walk(path): for file in files: full_path = os.path.join(parent, file) if not self.is_imported(full_path): # Check next file continue if data.is_domain_file(full_path): self._domain_paths.append(full_path) elif data.is_nlu_file(full_path): self._nlu_paths.append(full_path) elif data.is_story_file(full_path): self._story_paths.append(full_path) elif data.is_config_file(full_path): self._init_from_file(full_path)
def _init_from_directory(self, path: Text): 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 data.is_end_to_end_conversation_test_file(full_path): self._e2e_story_paths.append(full_path) elif Domain.is_domain_file(full_path): self._domain_paths.append(full_path) elif data.is_nlu_file(full_path): self._nlu_paths.append(full_path) elif data.is_story_file(full_path): self._story_paths.append(full_path) elif data.is_config_file(full_path): self._init_from_file(full_path)
def test_is_not_nlu_file_with_json(): directory = tempfile.mkdtemp() file = os.path.join(directory, "test.json") io.write_text_file('{"test": "a"}', file) assert not data.is_nlu_file(file)