コード例 #1
0
ファイル: test_export.py プロジェクト: simon-dube/boutiques
 def test_export(self):
     example1_dir = os.path.join(self.get_examples_dir(), "example1")
     example1_desc = os.path.join(example1_dir, "example1_docker.json")
     example1_desc_doi = os.path.join(example1_dir,
                                      "example1_docker_with_doi.json")
     fout = "test-example1-carmin.json"
     ref_name = "example1_docker_exported.json"
     ref_file = opj(example1_dir, ref_name)
     ref_name_p2 = "example1_docker_exported_python2.json"
     ref_file_p2 = opj(example1_dir, ref_name_p2)
     # Identifier is passed, descriptor has no DOI
     self.assertFalse(
         bosh([
             "export", "carmin", example1_desc, "--identifier", "123", fout
         ]))
     result = open(fout, "r").read().strip()
     assert (result == open(ref_file, "r").read().strip()
             or result == open(ref_file_p2, "r").read().strip())
     # Identifier is not passed, descriptor has no DOI
     with self.assertRaises(ExportError) as e:
         bosh(["export", "carmin", example1_desc, fout])
     self.assertTrue("Descriptor must have a DOI, or identifier "
                     "must be specified" in str(e.exception))
     self.assertRaises(ExportError, )
     # Identifier is not passed, descriptor has a DOI
     ref_name = "example1_docker_exported_doi.json"
     ref_file = opj(example1_dir, ref_name)
     ref_name_p2 = "example1_docker_exported_doi_python2.json"
     ref_file_p2 = opj(example1_dir, ref_name_p2)
     self.assertFalse(bosh(["export", "carmin", example1_desc_doi, fout]))
     result = open(fout, "r").read().strip()
     assert (result == open(ref_file, "r").read().strip()
             or result == open(ref_file_p2, "r").read().strip())
     os.remove(fout)
コード例 #2
0
ファイル: test_import.py プロジェクト: xlecours/boutiques
 def test_import_cwl_valid(self):
     ex_dir = opj(op.split(bfile)[0], "tests/cwl")
     # These ones are supposed to crash
     bad_dirs = ["1st-workflow",  # workflow
                 "record",  # complex type
                 "array-inputs",  # input bindings specific to array element
                 "expression",  # Javascript expression
                 "nestedworkflows"  # workflow
                 ]
     for d in os.listdir(ex_dir):
         if d == "README.md":
             continue
         files = os.listdir(opj(ex_dir, d))
         cwl_descriptor = op.abspath(opj(ex_dir, d, d+".cwl"))
         cwl_invocation = op.abspath(opj(ex_dir, d, d+".yml"))
         assert(os.path.isfile(cwl_descriptor))
         out_desc = "./cwl_out.json"
         out_inv = "./cwl_inv_out.json"
         run = False
         if os.path.isfile(cwl_invocation):
             args = ["import",
                     "cwl",
                     out_desc,
                     cwl_descriptor,
                     "-i", cwl_invocation,
                     "-o", out_inv]
             run = True
         else:
             args = ["import",
                     "cwl",
                     out_desc,
                     cwl_descriptor]
         if d in bad_dirs:
             with pytest.raises(ImportError):
                 bosh(args)
         else:
             self.assertFalse(bosh(args), cwl_descriptor)
             if run:
                 # write files required by cwl tools
                 with open('hello.js', 'w') as f:
                     f.write("'hello'")
                 with open('goodbye.txt', 'w') as f:
                     f.write("goodbye")
                 # closing required for Python 2.6...
                 with tarfile.open('hello.tar',
                                   'w') as tar:
                     tar.add('goodbye.txt')
                 ret = boutiques.execute(
                         "launch",
                         out_desc,
                         out_inv,
                         "--skip-data-collection"
                       )
                 self.assertFalse(ret.exit_code,
                                  cwl_descriptor)
コード例 #3
0
ファイル: test_test.py プロジェクト: jecharriere/boutiques
 def test_test_invalid(self):
     with self.assertRaises(ValidationError) as context:
         bosh([
             "test",
             op.join(self.get_examples_dir(), "tests_invalid.json")
         ])
     error_1 = "TestError: \"this_id_does_not_exist\" output id not found, in test \"test1\""
     error_2 = "TestError: \"logfile\" output id cannot appear more than once within same test, in test \"test1\""
     error_3 = "TestError: \"testNameDefinedTwice\" test name is non-unique"
     self.assertTrue(error_1 in context.exception.message)
     self.assertTrue(error_2 in context.exception.message)
     self.assertTrue(error_3 in context.exception.message)
     self.assertTrue(context.exception.message.count("TestError") == 3)
コード例 #4
0
ファイル: test_import.py プロジェクト: ramou/boutiques
    def test_docopt_import_valid_options(self):
        base_path = op.join(op.split(bfile)[0], "tests/docopt/options")
        pydocopt_input = op.join(base_path, "test_options.py")
        descriptor_output = op.join(base_path, "test_options_output.json")

        import_args = ["import", "dcpt", descriptor_output, pydocopt_input]
        bosh(import_args)

        test_invocation = op.join(base_path, "test_options_invocation.json")
        launch_args = ["exec", "launch", descriptor_output, test_invocation]
        bosh(launch_args)

        os.remove(descriptor_output)
コード例 #5
0
ファイル: test_import.py プロジェクト: ramou/boutiques
    def test_docopt_import_invalid(self):
        base_path = op.join(op.split(bfile)[0], "tests/docopt")
        pydocopt_input = op.join(base_path, "test_invalid.py")
        descriptor_output = op.join(base_path, "foobar.json")

        args = ["import", "dcpt", descriptor_output, pydocopt_input]

        with pytest.raises(ImportError, match="Invalid docopt script"):
            bosh(args)
            self.fail("Did not raise ImportError or" +
                      " message did not match Invalid docopt script")

        if op.isfile(descriptor_output):
            self.fail("Output file should not exist")
コード例 #6
0
 def test_example1_exec(self):
     example1_dir = os.path.join(self.get_examples_dir(), "example1")
     self.assertFalse(
         bosh([
             "exec", "launch",
             os.path.join(example1_dir, "example1.json"),
             os.path.join(example1_dir, "invocation.json")
         ]))
     self.assertFalse(
         bosh([
             "exec", "launch",
             os.path.join(example1_dir, "example1.json"), "-x",
             os.path.join(example1_dir, "invocation.json")
         ]))
コード例 #7
0
    def export(cls, input_descriptor_path, output_descriptor_path):
        relative_path = os.path.relpath(output_descriptor_path,
                                        start=app.config['PIPELINE_DIRECTORY'])
        try:
            bosh([
                "export", "carmin", input_descriptor_path, "--identifier",
                relative_path, output_descriptor_path
            ])
        except Exception:
            return False, "Boutiques descriptor at '{}' is invalid and could not be translated. Please fix it before launching the server.".format(
                input_descriptor_path)

        if not os.path.exists(output_descriptor_path):
            return False, "Boutiques descriptor at '{}' was exported without error, but no output file was created."
        return True, None
コード例 #8
0
 def test_example1_no_exec_random(self):
     example1_dir = os.path.join(self.get_examples_dir(), "example1")
     self.assertFalse(
         bosh([
             "exec", "simulate",
             os.path.join(example1_dir, "example1.json"), "-r", "3"
         ]))
コード例 #9
0
ファイル: test_test.py プロジェクト: jecharriere/boutiques
 def test_test_failure_mismatched_exitcode(self):
     self.assertEqual(
         1,
         bosh([
             "test",
             op.join(self.get_examples_dir(), "tests_failure_exitcode.json")
         ]))
コード例 #10
0
 def test_test_good_desc_as_json_obj(self):
     self.assertFalse(
         bosh([
             "test",
             open(op.join(self.get_examples_dir(),
                          "tests_good.json")).read()
         ]))
コード例 #11
0
 def test_example1_no_exec(self):
     example1_dir = os.path.join(self.get_examples_dir(), "example1")
     self.assertFalse(
         bosh([
             "exec", "simulate",
             os.path.join(example1_dir, "example1.json"), "-i",
             os.path.join(example1_dir, "invocation.json")
         ]))
コード例 #12
0
ファイル: test_test.py プロジェクト: jecharriere/boutiques
 def test_test_failure_mismatched_reference_content(self):
     self.assertEqual(
         1,
         bosh([
             "test",
             op.join(self.get_examples_dir(),
                     "tests_failure_reference.json")
         ]))
コード例 #13
0
ファイル: test_test.py プロジェクト: jecharriere/boutiques
 def test_test_failure_unproduced_output(self):
     self.assertEqual(
         1,
         bosh([
             "test",
             op.join(self.get_examples_dir(),
                     "tests_failure_output_id.json")
         ]))
コード例 #14
0
ファイル: test_simulate.py プロジェクト: kokiscv/boutiques
 def test_success_json(self):
     example1_dir = os.path.join(self.get_examples_dir(), "example1")
     desc_json = open(os.path.join(example1_dir,
                                   "example1_docker.json")).read()
     siminvo = bosh.execute("simulate", desc_json, "-j").stdout
     assert(isinstance(json.loads(siminvo), dict))
     siminvo = bosh.bosh(args=["example", desc_json]).stdout
     assert(isinstance(json.loads(siminvo), dict))
コード例 #15
0
    def test_number_bounds(self, mock_random):
        example1_dir = os.path.join(self.get_examples_dir(), "example1")
        desc_json = open(os.path.join(example1_dir,
                                      "example1_docker.json")).read()
        test_json = json.loads(desc_json)
        del test_json['groups']
        target_input = [
            i for i in test_json["inputs"] if i["id"] == "num_input"
        ][0]
        target_input["optional"] = False

        # Test inclusive lower bound
        target_input["exclusive-minimum"] = False
        mock_random.return_value = -0.001
        self.assertRaises(SystemExit, bosh.execute,
                          ["simulate", json.dumps(test_json), "-j"])
        mock_random.return_value = 0
        ret = bosh.bosh(args=["example", json.dumps(test_json)])
        self.assertIsInstance(json.loads(ret), dict)

        # Test exclusive lower bound
        target_input["exclusive-minimum"] = True
        self.assertRaises(SystemExit, bosh.execute,
                          ["simulate", json.dumps(test_json), "-j"])
        mock_random.return_value = 0.001
        ret = bosh.bosh(args=["example", json.dumps(test_json)])
        self.assertIsInstance(json.loads(ret), dict)

        # Test inclusive upper bound
        target_input["exclusive-maximum"] = False
        mock_random.return_value = 1.001
        self.assertRaises(SystemExit, bosh.execute,
                          ["simulate", json.dumps(test_json), "-j"])
        mock_random.return_value = 1
        ret = bosh.bosh(args=["example", json.dumps(test_json)])
        self.assertIsInstance(json.loads(ret), dict)

        # Test exclusive upper bound
        target_input["exclusive-maximum"] = True
        self.assertRaises(SystemExit, bosh.execute,
                          ["simulate", json.dumps(test_json), "-j"])
        mock_random.return_value = 0.999
        ret = bosh.bosh(args=["example", json.dumps(test_json)])
        self.assertIsInstance(json.loads(ret), dict)
コード例 #16
0
ファイル: test.py プロジェクト: ramou/BoutiquesDescriptors
def testTools(target):
    path, file = os.path.split(target)
    tool = file[0:-5]
    tmp = tempfile.mkdtemp()
    toolTestSrc = os.path.join(path, tool)
    toolTestDes = os.path.join(tmp, tool)
    old_wd = os.getcwd()
    try:
        if os.path.isdir(toolTestSrc):
            copytree(toolTestSrc, toolTestDes)
        else:
            os.mkdir(toolTestDes)
        copyfile(target, os.path.join(toolTestDes, file))
        os.chdir(toolTestDes)
        bosh(["validate", os.path.join(toolTestDes, file)])
        bosh(["test", os.path.join(toolTestDes, file)])
    finally:
        os.chdir(old_wd)
        rmtree(tmp)
コード例 #17
0
ファイル: test_import.py プロジェクト: ramou/boutiques
 def test_import_bids_good(self):
     bids_app = opj(
         op.split(bfile)[0], "schema/examples/bids-apps/example_good")
     outfile = "test-import.json"
     ref_name = "test-import-ref.json"
     if op.isfile(outfile):
         os.remove(outfile)
     self.assertFalse(bosh(["import", "bids", outfile, bids_app]))
     self.assertEqual(
         open(outfile, "U").read().strip(),
         open(opj(bids_app, ref_name), "U").read().strip())
コード例 #18
0
ファイル: test_import.py プロジェクト: soudabeh19/boutiques
 def test_upgrade_04(self):
     fin = opj(op.split(bfile)[0], "schema/examples/upgrade04.json")
     fout = opj(op.split(bfile)[0], "schema/examples/upgraded05.json")
     ref_name = "test-import-04-ref.json"
     ref_file = opj(op.split(bfile)[0], "schema/examples", ref_name)
     ref_name_p2 = "test-import-04-ref-python2.json"
     ref_file_p2 = opj(op.split(bfile)[0], "schema/examples", ref_name_p2)
     if op.isfile(fout):
         os.remove(fout)
     self.assertFalse(bosh(["import", "0.4", fout, fin]))
     result = open(fout, "r").read().strip()
     assert (result == open(ref_file, "r").read().strip()
             or result == open(ref_file_p2, "r").read().strip())
     os.remove(fout)
コード例 #19
0
    def _execute_test(self):

        results = []
        desc_JSON = json.loads(self.db_desc.data_file.read())

        # This is a work-around:
        # To individually test each of the descriptors,
        # the source descriptor will be broken into x copies of the descriptor, where x is the amount of tests defined.
        # Each of those clones will be only include each of the tests in the source descriptor.
        # To perform a test on a single defined test-case, we only need to supply the descriptor which includes it.
        # - The output of bosh should indicate the successfullness of the test.
        # - The stdout procuced by the command will represent the console logs we need to capture.

        tests = desc_JSON["tests"]

        # We remove the test entries in the JSON descriptor.
        desc_JSON["tests"] = []

        for test in tests:
            # We remove all the test entries in the JSON descriptor and only the current test entry
            desc_JSON["tests"] = [test]
            temporary_desc_file = create_temporary_file(
                json.dumps(desc_JSON).encode())

            # Preparation of the bosh test call
            # Capture of the stdout
            old_stdout = sys.stdout
            sys.stdout = mystdout = StringIO()

            if (bosh.bosh(["test", temporary_desc_file.name]) == 0):
                # Bosh test (pytest) returned 0, this means that the test was successful.
                status = TEST_STATUS_SUCCESS
            else:
                # Otherwise, any other exit-code indicates failure.
                status = TEST_STATUS_FAILURE

            temporary_desc_file.close()
            sys.stdout = old_stdout

            console = mystdout.getvalue().replace('\\n', '<br>')

            results.append((status, console))

        return results
コード例 #20
0
ファイル: test_export.py プロジェクト: jecharriere/boutiques
 def test_export(self):
     example1_dir = os.path.join(self.get_examples_dir(), "example1")
     example1_desc = os.path.join(example1_dir, "example1.json")
     fout = "test-example1-carmin.json"
     self.assertFalse(bosh(["export", "carmin", example1_desc, fout]))
     os.remove(fout)
コード例 #21
0
 def test_import_bids_good(self):
     bids_app = op.join(op.split(bfile)[0], "schema/examples/bids-apps/example_good")
     self.assertFalse(bosh(["import", "bids", "test-import.json", bids_app]))
コード例 #22
0
 def test_upgrade_04(self):
     fin = op.join(op.split(bfile)[0], "schema/examples/upgrade04.json")
     fout = op.join(op.split(bfile)[0], "schema/examples/upgraded05.json")
     self.assertFalse(bosh(["import", "0.4",  fout, fin]))
     os.remove(fout)
コード例 #23
0
 def validate(cls, descriptor_path, input_path):
     try:
         bosh(["invocation", descriptor_path, "-i", input_path])
     except ValidationError as e:
         return False, e.message
     return True, None
コード例 #24
0
ファイル: test_test.py プロジェクト: jecharriere/boutiques
 def test_test_good(self):
     self.assertFalse(
         bosh(["test",
               op.join(self.get_examples_dir(), "tests_good.json")]))
コード例 #25
0
ファイル: test_import.py プロジェクト: ramou/boutiques
 def test_import_bids_valid(self):
     self.assertFalse(bosh(["validate", "test-import.json", "-b"]))
     os.remove("test-import.json")
コード例 #26
0
ファイル: test_import.py プロジェクト: ramou/boutiques
    def test_docopt_nf(self):
        base_path = op.join(op.split(bfile)[0], "tests/docopt/naval_fate")
        pydocopt_input = op.join(base_path, "naval_fate.py")
        descriptor_output = op.join(base_path, "naval_fate_descriptor.json")

        import_args = ["import", "dcpt", descriptor_output, pydocopt_input]
        bosh(import_args)

        test_invocation = op.join(base_path, "nf_invoc_new.json")
        launch_args = ["exec", "launch", descriptor_output, test_invocation]
        bosh(launch_args)

        test_invocation = op.join(base_path, "nf_invoc_move.json")
        launch_args = ["exec", "launch", descriptor_output, test_invocation]
        bosh(launch_args)

        test_invocation = op.join(base_path, "nf_invoc_shoot.json")
        launch_args = ["exec", "launch", descriptor_output, test_invocation]
        bosh(launch_args)

        test_invocation = op.join(base_path, "nf_invoc_mine.json")
        launch_args = ["exec", "launch", descriptor_output, test_invocation]
        bosh(launch_args)

        test_invocation = op.join(base_path, "nf_invoc_help.json")
        launch_args = ["exec", "launch", descriptor_output, test_invocation]
        bosh(launch_args)

        os.remove(descriptor_output)
コード例 #27
0
 def test_test_good_from_zenodo(self, mock_get):
     self.assertFalse(
         bosh(["test", "zenodo." + str(example_boutiques_tool.id)]))
コード例 #28
0
 def test_test_good_from_zenodo(self, mock_get):
     self.assertFalse(bosh(["test", "zenodo.1472823"]))