Example #1
0
    def test_skip_collection(self):
        # Register original size of cache directory for comparison
        cache_dir = os.path.join(os.path.expanduser('~'), ".cache",
                                 "boutiques", "data")
        original_size = 0
        if os.path.exists(cache_dir):
            cache_fls = os.listdir(cache_dir)
            original_size = len(cache_fls)

        example1_dir = os.path.join(self.get_examples_dir(), "example1")
        bosh.execute(
            "launch", os.path.join(example1_dir, "example1_docker.json"),
            os.path.join(example1_dir,
                         "invocation.json"), "--skip-data-collection", "-v",
            "{}:/test_mount1".format(self.get_file_path("example1_mount1")),
            "-v",
            "{}:/test_mount2".format(self.get_file_path("example1_mount2")))

        new_size = 0
        if os.path.exists(cache_dir):
            cache_fls = os.listdir(cache_dir)
            new_size = len(cache_fls)
        self.assertEqual(new_size, original_size)

        self.clean_up()
Example #2
0
    def test_directory_input_output(self):
        example1_dir = self.get_examples_dir()
        bosh.execute("launch",
                     os.path.join(example1_dir,
                                  "dir_input.json"),
                     os.path.join(example1_dir,
                                  "dir_invocation.json"))
        data_collect_dict = retrieve_data_record()

        public_in = data_collect_dict.get("public-invocation")
        self.assertIsNotNone(public_in)
        input_dir = public_in.get("input_dir")
        self.assertIsNotNone(input_dir)
        files = input_dir.get("files")
        self.assertIsNotNone(files)
        self.assertEqual(len(files), 2)

        public_out = data_collect_dict.get("public-output")
        self.assertIsNotNone(public_out)
        output_files = public_out.get("output-files")
        self.assertIsNotNone(output_files)
        results = output_files.get("results")
        self.assertIsNotNone(results)
        files = results.get("files")
        self.assertIsNotNone(files)
        self.assertEqual(len(files), 2)

        self.clean_up()
Example #3
0
    def test_example1_exec_docker(self):
        self.clean_up()
        ret = bosh.execute(
            "launch", self.get_file_path("example1_docker.json"),
            self.get_file_path("invocation.json"), "--skip-data-collection",
            "-v",
            "{}:/test_mount1".format(self.get_file_path("example1_mount1")),
            "-v",
            "{}:/test_mount2".format(self.get_file_path("example1_mount2")))

        # Make sure stdout and stderr are not printed on the fly
        # for non-streaming mode
        out, err = self.capfd.readouterr()
        self.assertNotIn("This is stdout", out)
        self.assertNotIn("This is stderr", out)

        self.assert_successful_return(ret, ["log-4-coin;plop.txt"], 2,
                                      self.assert_reflected_output)

        self.clean_up()
        self.assert_successful_return(
            bosh.execute(
                "launch", self.get_file_path("example1_docker.json"), "-x",
                self.get_file_path("invocation.json"),
                "--skip-data-collection", "-v", "{}:/test_mount1".format(
                    self.get_file_path("example1_mount1")),
                "-v", "{}:/test_mount2".format(
                    self.get_file_path("example1_mount2"))),
            ["log-4-coin;plop.txt"], 2, self.assert_reflected_output)
Example #4
0
    def test_example1_exec_docker_inv_as_json_obj(self):
        example1_dir = os.path.join(self.get_examples_dir(), "example1")
        self.clean_up()
        invocationStr = open(os.path.join(example1_dir,
                                          "invocation.json")).read()
        ret = bosh.execute("launch",
                           os.path.join(example1_dir, "example1_docker.json"),
                           invocationStr)

        print(ret)
        assert ("This is stdout" in ret.stdout)
        assert ("This is stderr" in ret.stderr)
        assert (ret.exit_code == 0)
        assert (ret.error_message == "")
        assert (ret.missing_files == [])
        assert (len(ret.output_files) == 2)
        assert (ret.output_files[0].file_name == "log-4-coin;plop.txt"
                or ret.output_files[1].file_name == "log-4-coin;plop.txt")

        self.clean_up()
        ret = bosh.execute("launch",
                           os.path.join(example1_dir, "example1_docker.json"),
                           "-x", os.path.join(example1_dir, "invocation.json"))
        print(ret)
        assert ("This is stdout" in ret.stdout)
        assert ("This is stderr" in ret.stderr)
        assert (ret.exit_code == 0)
        assert (ret.error_message == "")
        assert (ret.missing_files == [])
        assert (len(ret.output_files) == 2)
        assert (ret.output_files[0].file_name == "log-4-coin;plop.txt"
                or ret.output_files[1].file_name == "log-4-coin;plop.txt")
Example #5
0
    def test_example1_exec_docker_from_zenodo(self):
        example1_dir = os.path.join(self.get_examples_dir(), "example1")
        self.clean_up()
        ret = bosh.execute("launch", "zenodo.1472823",
                           os.path.join(example1_dir, "invocation.json"))

        # Make sure stdout and stderr are not printed on the fly
        # for non-streaming mode
        out, err = self.capfd.readouterr()
        assert ("This is stdout" not in out)
        assert ("This is stderr" not in out)

        print(ret)
        assert ("This is stdout" in ret.stdout)
        assert ("This is stderr" in ret.stderr)
        assert (ret.exit_code == 0)
        assert (ret.error_message == "")
        assert (ret.missing_files == [])
        assert (len(ret.output_files) == 2)
        assert (ret.output_files[0].file_name == "log-4-coin;plop.txt"
                or ret.output_files[1].file_name == "log-4-coin;plop.txt")

        self.clean_up()
        ret = bosh.execute("launch", "zenodo.1472823", "-x",
                           os.path.join(example1_dir, "invocation.json"))
        print(ret)
        assert ("This is stdout" in ret.stdout)
        assert ("This is stderr" in ret.stderr)
        assert (ret.exit_code == 0)
        assert (ret.error_message == "")
        assert (ret.missing_files == [])
        assert (len(ret.output_files) == 2)
        assert (ret.output_files[0].file_name == "log-4-coin;plop.txt"
                or ret.output_files[1].file_name == "log-4-coin;plop.txt")
Example #6
0
    def test_data_collection(self):
        example1_dir = os.path.join(self.get_examples_dir(), "example1")
        bosh.execute("launch",
                     os.path.join(example1_dir,
                                  "example1_docker.json"),
                     os.path.join(example1_dir,
                                  "invocation.json"))
        data_collect_dict = retrieve_data_record()

        summary = data_collect_dict.get("summary")
        self.assertIsNotNone(summary)
        self.assertEqual(summary.get("name"), "Example Boutiques Tool")
        public_in = data_collect_dict.get("public-invocation")
        self.assertIsNotNone(public_in)
        self.assertEqual(public_in.get("config_num"), 4)
        self.assertEqual(public_in.get("enum_input"), "val1")
        file_input = public_in.get("file_input")
        self.assertIsNotNone(file_input)
        self.assertEqual(file_input.get("file-name"), "setup.py")
        self.assertIsNotNone(file_input.get("md5sum"))
        public_out = data_collect_dict.get("public-output")
        self.assertIsNotNone(public_out)
        self.assertEqual(public_out.get("stdout"), "This is stdout")
        self.assertEqual(public_out.get("stderr"), "This is stderr")
        self.assertEqual(public_out.get("exit-code"), 0)
        self.assertEqual(public_out.get("error-message"), "")
        output_files = public_out.get("output-files")
        self.assertIsNotNone(output_files)
        self.assertIsNotNone(output_files.get("logfile"))
        self.assertIsNotNone(output_files.get("config_file"))
        logfile = output_files.get("logfile")
        self.assertEqual(logfile.get("file-name"), "log-4-coin;plop.txt")

        self.clean_up()
Example #7
0
    def test_example1_exec_singularity(self):
        example1_dir = os.path.join(self.get_examples_dir(), "example1")
        self.clean_up()
        ret = bosh.execute("launch",
                           os.path.join(example1_dir, "example1_sing.json"),
                           os.path.join(example1_dir, "invocation_sing.json"))
        print(ret)
        assert ("This is stdout" in ret.stdout)
        assert ("This is stderr" in ret.stderr)
        assert (ret.exit_code == 0)
        assert (ret.error_message == "")
        assert (ret.missing_files == [])
        assert (len(ret.output_files) == 2)
        assert (ret.output_files[0].file_name == "log-4.txt"
                or ret.output_files[1].file_name == "log-4.txt")

        self.clean_up()
        ret = bosh.execute("launch",
                           os.path.join(example1_dir, "example1_sing.json"),
                           "-x",
                           os.path.join(example1_dir, "invocation_sing.json"))
        print(ret)
        assert ("This is stdout" in ret.stdout)
        assert ("This is stderr" in ret.stderr)
        assert (ret.exit_code == 0)
        assert (ret.error_message == "")
        assert (ret.missing_files == [])
        assert (len(ret.output_files) == 2)
        assert (ret.output_files[0].file_name == "log-4.txt"
                or ret.output_files[1].file_name == "log-4.txt")
Example #8
0
 def test_example1_crash_pull_singularity(self):
     self.clean_up()
     with pytest.raises(ExecutorError) as e:
         bosh.execute("launch",
                      self.get_file_path("example1_sing_crash_pull.json"),
                      self.get_file_path("invocation_sing.json"),
                      "--skip-data-collection")
     self.assertIn("Could not pull Singularity image", str(e))
Example #9
0
 def test_consistency_withAndWithout_invoc(self):
     descriptor = os.path.join(
         os.path.split(bfile)[0], 'schema/examples/'
         'test_simulate_consistency.json')
     noInvoc = bosh.execute("simulate", descriptor).stdout
     wInvoc = bosh.execute("simulate", descriptor, "-i",
                           bosh.example(descriptor)).stdout
     self.assertEqual(noInvoc, wInvoc)
Example #10
0
 def test_example1_exec_docker_json_string_invalid(self):
     self.clean_up()
     invocationStr = open(
         self.get_file_path("invocation_invalid.json")).read()
     with pytest.raises(LoadError) as e:
         bosh.execute("launch", self.get_file_path("example1_docker.json"),
                      "-u", invocationStr, "--skip-data-collection")
     self.assertIn("Cannot parse input", str(e.getrepr(style='long')))
Example #11
0
 def test_raise_error(self):
     example1_dir = os.path.join(self.get_examples_dir(), "example1")
     invocationStr = open(
         os.path.join(example1_dir, "invocation_invalid.json")).read()
     with pytest.raises(LoadError) as e:
         bosh.execute("launch",
                      os.path.join(example1_dir, "example1_docker.json"),
                      invocationStr, "--skip-data-collection")
     self.assertIn("[ ERROR ]", str(e))
Example #12
0
 def test_example2_exec(self):
     example2_dir = os.path.join(self.get_examples_dir(), "example2")
     self.assertFalse(
         bosh.execute("launch", os.path.join(example2_dir, "example2.json"),
                      os.path.join(example2_dir, "invocation.json"))[2])
     self.assertFalse(
         bosh.execute("launch", os.path.join(example2_dir,
                                             "example2.json"), "-x",
                      os.path.join(example2_dir, "invocation.json"))[2])
Example #13
0
 def test_example1_crash_pull_singularity(self):
     example1_dir = os.path.join(self.get_examples_dir(), "example1")
     self.clean_up()
     with pytest.raises(ExecutorError) as e:
         bosh.execute(
             "launch",
             os.path.join(example1_dir, "example1_sing_crash_pull.json"),
             os.path.join(example1_dir, "invocation_sing.json"))
     assert ("Could not pull Singularity image" in str(e))
Example #14
0
    def test_success_desc_from_zenodo(self):
        self.assertFalse(bosh.execute("simulate",
                                      "zenodo.1472823",
                                      "-r", "1").exit_code)

        self.assertFalse(bosh.execute("simulate",
                                      os.path.join(self.get_examples_dir(),
                                                   "good_nooutputs.json"),
                                      "-r", "1").exit_code)
Example #15
0
 def test_raise_error(self):
     example1_dir = os.path.join(self.get_examples_dir(), "example1")
     invocationStr = open(
         os.path.join(example1_dir, "invocation_invalid.json")).read()
     with pytest.raises(ExecutorError) as e:
         bosh.execute("launch",
                      os.path.join(example1_dir, "example1_docker.json"),
                      invocationStr)
     assert ("[ ERROR ]" in str(e))
Example #16
0
 def test_example1_exec_docker_json_string_invalid(self):
     example1_dir = os.path.join(self.get_examples_dir(), "example1")
     self.clean_up()
     invocationStr = open(
         os.path.join(example1_dir, "invocation_invalid.json")).read()
     with pytest.raises(ExecutorError) as e:
         bosh.execute("launch",
                      os.path.join(example1_dir, "example1_docker.json"),
                      invocationStr)
     assert ("Cannot parse input" in str(e))
Example #17
0
    def test_success(self):
        example1_dir = os.path.join(self.get_examples_dir(), "example1")
        self.assertFalse(bosh.execute("simulate",
                                      os.path.join(example1_dir,
                                                   "example1_docker.json"
                                                   )).exit_code)

        self.assertFalse(bosh.execute("simulate",
                                      os.path.join(self.get_examples_dir(),
                                                   "good_nooutputs.json"
                                                   )).exit_code)
Example #18
0
 def test_prepare_sing_image_does_not_exist(self):
     example1_dir = os.path.join(self.get_examples_dir(), "example1")
     # Specify the wrong path for the image
     # Will try to pull it and pull will fail
     with pytest.raises(ExecutorError) as e:
         bosh.execute(
             "prepare", os.path.join(example1_dir, "example1_sing.json"),
             "--imagepath",
             os.path.join(os.path.expanduser('~'),
                          "boutiques-example1-test.simg"))
     self.assertIn("Could not pull Singularity image", str(e))
Example #19
0
    def test_read_doi_zenodo(self, mock_get):
        example1_dir = os.path.join(self.get_examples_dir(), "example1")
        bosh.execute("launch", "zenodo." + str(example_boutiques_tool.id),
                     os.path.join(example1_dir, "invocation.json"))
        data_collect_dict = retrieve_data_record()

        summary = data_collect_dict.get("summary")
        self.assertIsNotNone(summary)
        self.assertEqual(summary.get("descriptor-doi"),
                         "10.5281/zenodo." + str(example_boutiques_tool.id))
        self.clean_up()
Example #20
0
    def bosh_exec(self, invocation_file, mount=None):
        try:

            if mount is None:
                boutiques.execute("launch",self.boutiques_descriptor,invocation_file, "-x")
            else:
                boutiques.execute("launch", self.boutiques_descriptor, invocation_file, "-v",
                         "{0}:{0}".format(mount), "-x")
            result = 0
        except SystemExit as e:
            result = e.code
        return (result, "Empty log, Boutiques API doesn't return it yet.\n")
Example #21
0
    def test_success_desc_as_json_obj(self):
        example1_dir = os.path.join(self.get_examples_dir(), "example1")
        desc_json = open(os.path.join(example1_dir,
                                      "example1_docker.json")).read()
        self.assertFalse(bosh.execute("simulate",
                                      desc_json,
                                      "-r", "1").exit_code)

        self.assertFalse(bosh.execute("simulate",
                                      os.path.join(self.get_examples_dir(),
                                                   "good_nooutputs.json"),
                                      "-r", "1").exit_code)
Example #22
0
    def test_example2_exec(self):
        self.assert_successful_return(
            bosh.execute("launch", self.get_file_path("example2.json"),
                         self.get_file_path("invocation.json"),
                         "--skip-data-collection"),
            aditional_assertions=self.assert_no_output)

        self.assert_successful_return(
            bosh.execute("launch", self.get_file_path("example2.json"), "-x",
                         self.get_file_path("invocation.json"),
                         "--skip-data-collection"),
            aditional_assertions=self.assert_no_output)
Example #23
0
 def test_prepare_sing_timeout(self, mock_mkdir, mock_sleep):
     example1_dir = os.path.join(self.get_examples_dir(), "example1")
     # Specify path for image that does not exist.
     # Mock that another process has the lockdir and this one
     # times out while waiting.
     with pytest.raises(ExecutorError) as e:
         bosh.execute(
             "prepare", os.path.join(example1_dir, "example1_sing.json"),
             "--imagepath",
             os.path.join(os.path.expanduser('~'),
                          "boutiques-example1-test.simg"))
     self.assertIn("Unable to retrieve Singularity image", str(e))
Example #24
0
 def test_example1_crash_pull_singularity(self):
     self.clean_up()
     with pytest.raises(ExecutorError) as e:
         bosh.execute(
             "launch", self.get_file_path("example1_sing_crash_pull.json"),
             self.get_file_path("invocation_sing.json"),
             "--skip-data-collection", "-v", "{}:/test_mount1".format(
                 self.get_file_path("example1_mount1")),
             "-v", "{}:/test_mount2".format(
                 self.get_file_path("example1_mount2")))
     self.assertIn("Could not pull Singularity image",
                   str(e.getrepr(style='long')))
Example #25
0
    def test_example1_exec_singularity(self):
        self.clean_up()
        self.assert_successful_return(
            bosh.execute("launch", self.get_file_path("example1_sing.json"),
                         self.get_file_path("invocation_sing.json"),
                         "--skip-data-collection"), ["log-4.txt"], 2,
            self.assert_reflected_output)

        self.clean_up()
        self.assert_successful_return(
            bosh.execute("launch", self.get_file_path("example1_sing.json"),
                         "-x", self.get_file_path("invocation_sing.json")),
            ["log-4.txt"], 2, self.assert_reflected_output)
Example #26
0
    def test_example1_exec_docker_inv_as_json_obj(self):
        self.clean_up()
        invocationStr = open(self.get_file_path("invocation.json")).read()
        self.assert_successful_return(
            bosh.execute("launch", self.get_file_path("example1_docker.json"),
                         invocationStr, "--skip-data-collection"),
            ["log-4-coin;plop.txt"], 2, self.assert_reflected_output)

        self.clean_up()
        self.assert_successful_return(
            bosh.execute("launch", self.get_file_path("example1_docker.json"),
                         "-x", self.get_file_path("invocation.json"),
                         "--skip-data-collection"), ["log-4-coin;plop.txt"], 2,
            self.assert_reflected_output)
Example #27
0
    def test_example2_exec(self):
        example2_dir = os.path.join(self.get_examples_dir(), "example2")
        ret = bosh.execute("launch", os.path.join(example2_dir,
                                                  "example2.json"),
                           os.path.join(example2_dir, "invocation.json"))
        print(ret)
        assert (ret.stdout == "" and ret.stderr == "" and ret.exit_code == 0
                and ret.error_message == "")

        ret = bosh.execute("launch", os.path.join(example2_dir,
                                                  "example2.json"), "-x",
                           os.path.join(example2_dir, "invocation.json"))
        print(ret)
        assert (ret.stdout == "" and ret.stderr == "" and ret.exit_code == 0
                and ret.error_message == "")
Example #28
0
    def test_example1_exec_docker_non_utf8(self):
        self.clean_up()
        ret = bosh.execute("launch",
                           self.get_file_path("example1_docker_nonutf8.json"),
                           self.get_file_path("invocation.json"))

        self.assert_successful_return(ret, ["log-4-coin;plop.txt"], 2,
                                      self.assert_reflected_output_nonutf8)

        self.clean_up()
        self.assert_successful_return(
            bosh.execute("launch",
                         self.get_file_path("example1_docker_nonutf8.json"),
                         "-x", self.get_file_path("invocation.json")),
            ["log-4-coin;plop.txt"], 2, self.assert_reflected_output_nonutf8)
Example #29
0
 def test_no_container(self):
     self.assertFalse(bosh.execute("launch",
                                   os.path.join(self.get_examples_dir(),
                                                "no_container.json"),
                                   os.path.join(self.get_examples_dir(),
                                                "no_container_invocation."
                                                + "json")).exit_code)
Example #30
0
 def test_prepare_sing_specify_imagepath_basename_only(self):
     example1_dir = os.path.join(self.get_examples_dir(), "example1")
     ret = bosh.execute("prepare",
                        os.path.join(example1_dir, "example1_sing.json"),
                        "--imagepath", "boutiques-example1-test.simg")
     self.assertIn("Local (boutiques-example1-test.simg)", ret.stdout)
     self.assertNotIn("SINGULARITY_PULLFOLDER", os.environ)