def test_fill_data_library(): """Test :func:`planemo.training.fill_data_library`.""" train = Training(KWDS) train.kwds['tutorial_name'] = None train.kwds['slides'] = False train.kwds['hands_on'] = False train.init_training(CTX) train.kwds['tutorial_name'] = 'existing_tutorial' create_existing_tutorial('existing_tutorial', tuto_wo_zenodo_fp, train.topic) # no Zenodo link train.kwds['zenodo_link'] = None exp_exception = "A Zenodo link should be provided either in the metadata file or as argument of the command" with assert_raises_regexp(Exception, exp_exception): train.fill_data_library(CTX) # with a given Zenodo link and no Zenodo in metadata train.kwds['zenodo_link'] = zenodo_link train.fill_data_library(CTX) assert 'DOI: 10.5281/zenodo.1321885' in open(train.tuto.data_lib_fp, 'r').read() assert 'zenodo_link: %s' % zenodo_link in open(train.tuto.tuto_fp, 'r').read() # with a given Zenodo link and Zenodo in metadata new_z_link = 'https://zenodo.org/record/1324204' train.kwds['zenodo_link'] = new_z_link train.tuto = None train.fill_data_library(CTX) assert 'DOI: 10.5281/zenodo.1324204' in open(train.tuto.data_lib_fp, 'r').read() assert 'zenodo_link: %s' % new_z_link in open(train.tuto.tuto_fp, 'r').read() # with no given Zenodo link train.kwds['zenodo_link'] = None train.fill_data_library(CTX) assert 'DOI: 10.5281/zenodo.1324204' in open(train.tuto.data_lib_fp, 'r').read() assert 'zenodo_link: %s' % new_z_link in open(train.tuto.tuto_fp, 'r').read() # clean after shutil.rmtree(train.topics_dir) shutil.rmtree("metadata")
def test_training_init_training(): """Test :func:`planemo.training.Training.init_training`.""" train = Training(KWDS) # new topic, nothing else train.kwds['tutorial_name'] = None train.kwds['slides'] = None train.kwds['workflow'] = None train.kwds['workflow_id'] = None train.kwds['zenodo_link'] = None train.init_training(CTX) assert os.path.exists(train.topic.dir) assert not os.listdir(os.path.join(train.topic.dir, 'tutorials')) # no new topic, no tutorial name but hands-on train.kwds['slides'] = True exp_exception = "A tutorial name is needed to create the skeleton of a tutorial slide deck" with assert_raises_regexp(Exception, exp_exception): train.init_training(CTX) # no new topic, no tutorial name but workflow train.kwds['workflow'] = WF_FP train.kwds['slides'] = False exp_exception = "A tutorial name is needed to create the skeleton of the tutorial from a workflow" with assert_raises_regexp(Exception, exp_exception): train.init_training(CTX) # no new topic, no tutorial name but zenodo train.kwds['workflow'] = None train.kwds['zenodo_link'] = zenodo_link exp_exception = "A tutorial name is needed to add Zenodo information" with assert_raises_regexp(Exception, exp_exception): train.init_training(CTX) # no new topic, new tutorial train.kwds['tutorial_name'] = "new_tuto" train.kwds['workflow'] = None train.kwds['zenodo_link'] = None train.init_training(CTX) assert os.path.exists(train.tuto.dir) assert os.path.exists(train.tuto.tuto_fp) with open(train.tuto.tuto_fp, 'r') as fh: assert train.kwds['tutorial_title'] in fh.read() # clean after shutil.rmtree(train.topics_dir) shutil.rmtree("metadata")
def test_generate_tuto_from_wf(): """Test :func:`planemo.training.generate_tuto_from_wf`.""" train = Training(KWDS) train.kwds['tutorial_name'] = None train.kwds['slides'] = False train.init_training(CTX) train.kwds['tutorial_name'] = 'existing_tutorial' create_existing_tutorial('existing_tutorial', tuto_fp, train.topic) # no workflow train.kwds['workflow'] = None exp_exception = "A path to a local workflow or the id of a workflow on a running Galaxy instance should be provided" with assert_raises_regexp(Exception, exp_exception): train.generate_tuto_from_wf(CTX) # with workflow train.kwds['workflow'] = WF_FP train.generate_tuto_from_wf(CTX) assert '**FastQC** {% icon tool %} with the following parameters:' in open(train.tuto.tuto_fp, 'r').read() assert os.path.exists(train.tuto.wf_fp) # clean after shutil.rmtree(train.topics_dir) shutil.rmtree("metadata")
def test_training_init_training(): """Test :func:`planemo.training.Training.init_training`.""" train = Training(KWDS) # new topic, nothing else train.kwds['tutorial_name'] = None train.kwds['slides'] = None train.kwds['workflow'] = None train.kwds['workflow_id'] = None train.kwds['zenodo_link'] = None train.init_training(CTX) assert os.path.exists(train.topic.dir) assert not os.listdir(os.path.join(train.topic.dir, 'tutorials')) # no new topic, no tutorial name but hands-on train.kwds['slides'] = True exp_exception = "A tutorial name is needed to create the skeleton of a tutorial slide deck" with assert_raises_regexp(Exception, exp_exception): train.init_training(CTX) # no new topic, no tutorial name but workflow train.kwds['workflow'] = WF_FP train.kwds['slides'] = False exp_exception = "A tutorial name is needed to create the skeleton of the tutorial from a workflow" with assert_raises_regexp(Exception, exp_exception): train.init_training(CTX) # no new topic, no tutorial name but zenodo train.kwds['workflow'] = None train.kwds['zenodo_link'] = zenodo_link exp_exception = "A tutorial name is needed to add Zenodo information" with assert_raises_regexp(Exception, exp_exception): train.init_training(CTX) # no new topic, new tutorial train.kwds['tutorial_name'] = "new_tuto" train.kwds['workflow'] = None train.kwds['zenodo_link'] = None train.init_training(CTX) assert os.path.exists(train.tuto.dir) assert os.path.exists(train.tuto.tuto_fp) assert train.kwds['tutorial_title'] in open(train.tuto.tuto_fp, 'r').read() # clean after shutil.rmtree(train.topics_dir) shutil.rmtree("metadata")
def test_training_check_topic_init_tuto(): """Test :func:`planemo.training.Training.check_topic_init_tuto`.""" train = Training(KWDS) # no topic exp_exception = "The topic my_new_topic does not exists. It should be created" with assert_raises_regexp(Exception, exp_exception): train.check_topic_init_tuto() # add topic train.kwds['tutorial_name'] = None train.kwds['slides'] = None train.kwds['workflow'] = None train.kwds['workflow_id'] = None train.kwds['zenodo_link'] = None train.init_training(CTX) train.kwds['tutorial_name'] = 'existing_tutorial' create_existing_tutorial('existing_tutorial', tuto_fp, train.topic) train.check_topic_init_tuto() assert train.tuto.name == train.kwds['tutorial_name'] assert train.tuto.datatype_fp # clean after shutil.rmtree(train.topics_dir) shutil.rmtree("metadata")
def test_generate_tuto_from_wf(): """Test :func:`planemo.training.generate_tuto_from_wf`.""" train = Training(KWDS) train.kwds['tutorial_name'] = None train.kwds['slides'] = False train.init_training(CTX) train.kwds['tutorial_name'] = 'existing_tutorial' create_existing_tutorial('existing_tutorial', tuto_fp, train.topic) # no workflow train.kwds['workflow'] = None exp_exception = "A path to a local workflow or the id of a workflow on a running Galaxy instance should be provided" with assert_raises_regexp(Exception, exp_exception): train.generate_tuto_from_wf(CTX) # with workflow train.kwds['workflow'] = WF_FP train.generate_tuto_from_wf(CTX) assert_file_contains( train.tuto.tuto_fp, "{% tool [FastQC](toolshed.g2.bx.psu.edu/repos/devteam/fastqc/fastqc/0.71) %} with the following parameters:", ) assert os.path.exists(train.tuto.wf_fp) # clean after shutil.rmtree(train.topics_dir) shutil.rmtree("metadata")
def cli(ctx, uris, **kwds): """Build training template from workflow.""" kwds["no_dependency_resolution"] = True training = Training(kwds) training.init_training(ctx)
def generate(tuto): '''Generate skeleton of a tutorial''' shutil.rmtree('topics', ignore_errors=True) shutil.rmtree('metadata', ignore_errors=True) kwds = { 'topic_name': 'topic', 'topic_title': "New topic", 'topic_target': "use", 'topic_summary': "Topic summary", 'tutorial_name': tuto['name'], 'tutorial_title': tuto['title'], 'hands_on': True, 'slides': False, 'workflow_id': tuto['workflow_id'], 'zenodo_link': tuto['zenodo'], 'galaxy_url': tuto['galaxy_url'], 'galaxy_api_key': tuto['api_key'], 'workflow': None, 'datatypes': None } train = Training(kwds) ctx = cli.PlanemoCliContext() ctx.planemo_directory = "/tmp/planemo-test-workspace" error = None try: train.init_training(ctx) except bioblend.ConnectionError as connect_error: print(connect_error) if "Malformed id" in connect_error.body: error = ("The id of the workflow is malformed " "for the given Galaxy instance. " "Please check it before trying again.") elif "not owned by or shared with current user" in connect_error.body: error = ("The workflow is not shared publicly " "on the given Galaxy instance. " "Please share it before trying again.") else: error = connect_error.body tuto_dp = topic_dp / Path("%s" % tuto['name']) tuto_fp = tuto_dp / Path('tutorial.md') if error is None and not tuto_fp.is_file(): error = ("The tutorial file was not generated. " "The workflow may have some errors. " "Please check it before trying again.") if error is None: zip_fn = "%s" % (tuto['uuid']) shutil.make_archive(Path(zip_fn), 'zip', tuto_dp) zip_fp = Path('static') / Path("%s.zip" % zip_fn) shutil.move("%s.zip" % zip_fn, Path('ptdk') / zip_fp) shutil.rmtree('topics', ignore_errors=True) shutil.rmtree('metadata', ignore_errors=True) return zip_fp return error