def test_get_exploration_components_from_dir_with_multiple_yaml_files( self): with self.assertRaisesRegexp( Exception, 'More than one non-asset file specified for ' 'core/tests/data/dummy_assets/assets'): utils.get_exploration_components_from_dir( 'core/tests/data/dummy_assets/assets/')
def test_get_exploration_components_from_dir_with_no_yaml_file(self): # type: () -> None with self.assertRaisesRegexp( # type: ignore[no-untyped-call] Exception, 'No yaml file specifed for core/tests/data/dummy_assets'): utils.get_exploration_components_from_dir( 'core/tests/data/dummy_assets/')
def test_get_exploration_components_from_dir_with_multiple_yaml_files( self): # type: () -> None with self.assertRaisesRegexp( # type: ignore[no-untyped-call] Exception, 'More than one non-asset file specified for ' 'core/tests/data/dummy_assets/assets'): utils.get_exploration_components_from_dir( 'core/tests/data/dummy_assets/assets/')
def test_get_exploration_components_from_dir_with_invalid_path_raises_error( self): with self.assertRaisesRegexp( Exception, 'Found invalid non-asset file .+' 'There should only be a single non-asset file, and it should have ' 'a .yaml suffix.'): utils.get_exploration_components_from_dir('core/tests/load_tests') with self.assertRaisesRegexp( Exception, 'The only directory in . should be assets/'): utils.get_exploration_components_from_dir('.')
def get_demo_exploration_components(demo_path): """Gets the content of `demo_path` in the sample explorations folder. Args: demo_path: the file or folder path for the content of an exploration in SAMPLE_EXPLORATIONS_DIR. E.g.: 'adventure.yaml' or 'tar/'. Returns: a 2-tuple, the first element of which is a yaml string, and the second element of which is a list of (filepath, content) 2-tuples. The filepath does not include the assets/ prefix. """ demo_filepath = os.path.join(feconf.SAMPLE_EXPLORATIONS_DIR, demo_path) if demo_filepath.endswith('yaml'): file_contents = utils.get_file_contents(demo_filepath) return file_contents, [] elif os.path.isdir(demo_filepath): return utils.get_exploration_components_from_dir(demo_filepath) else: raise Exception('Unrecognized file path: %s' % demo_path)
def get_demo_exploration_components(demo_path): """Gets the content of `demo_path` in the sample explorations folder. Args: demo_path: the file or folder path for the content of an exploration in SAMPLE_EXPLORATIONS_DIR. E.g.: 'adventure.yaml' or 'tar/'. Returns: a 2-tuple, the first element of which is a yaml string, and the second element of which is a list of (filepath, content) 2-tuples. The filepath does not include the assets/ prefix. """ demo_filepath = os.path.join(feconf.SAMPLE_EXPLORATIONS_DIR, demo_path) if demo_filepath.endswith('yaml'): file_contents = utils.get_file_contents(demo_filepath) return file_contents, [] elif os.path.isdir(demo_filepath): return utils.get_exploration_components_from_dir(demo_filepath) else: raise Exception('Unrecognized file path: %s' % demo_path)
def test_get_exploration_components_from_dir_with_no_yaml_file(self): with self.assertRaisesRegexp( Exception, 'No yaml file specifed for core/tests/data/dummy_assets'): utils.get_exploration_components_from_dir( 'core/tests/data/dummy_assets/')