コード例 #1
0
ファイル: test_bundle_download.py プロジェクト: Nic-Ma/MONAI
 def test_url_download_bundle(self, bundle_files, bundle_name, url,
                              hash_val):
     with skip_if_downloading_fails():
         # download a single file from url, also use `args_file`
         with tempfile.TemporaryDirectory() as tempdir:
             def_args = {
                 "name": bundle_name,
                 "bundle_dir": tempdir,
                 "url": ""
             }
             def_args_file = os.path.join(tempdir, "def_args.json")
             parser = ConfigParser()
             parser.export_config_file(config=def_args,
                                       filepath=def_args_file)
             cmd = [
                 "coverage", "run", "-m", "monai.bundle", "download",
                 "--args_file", def_args_file
             ]
             cmd += ["--url", url]
             subprocess.check_call(cmd)
             for file in bundle_files:
                 file_path = os.path.join(tempdir, bundle_name, file)
                 self.assertTrue(os.path.exists(file_path))
             if file == "network.json":
                 self.assertTrue(
                     check_hash(filepath=file_path, val=hash_val))
コード例 #2
0
    def test_result(self, md5_value, t, expected_result):
        test_image = np.ones((5, 5, 3))
        with tempfile.TemporaryDirectory() as tempdir:
            filename = os.path.join(tempdir, "test_file.png")
            test_image.tofile(filename)

            result = check_hash(filename, md5_value, hash_type=t)
            self.assertTrue(result == expected_result)
コード例 #3
0
ファイル: test_bundle_download.py プロジェクト: Nic-Ma/MONAI
 def test_download_bundle(self, bundle_files, bundle_name, repo, hash_val):
     with skip_if_downloading_fails():
         # download a whole bundle from github releases
         with tempfile.TemporaryDirectory() as tempdir:
             cmd = [
                 "coverage", "run", "-m", "monai.bundle", "download",
                 "--name", bundle_name, "--source", "github"
             ]
             cmd += [
                 "--bundle_dir", tempdir, "--repo", repo, "--progress",
                 "False"
             ]
             subprocess.check_call(cmd)
             for file in bundle_files:
                 file_path = os.path.join(tempdir, bundle_name, file)
                 self.assertTrue(os.path.exists(file_path))
                 if file == "network.json":
                     self.assertTrue(
                         check_hash(filepath=file_path, val=hash_val))
コード例 #4
0
 def test_hash_type_error(self):
     with self.assertRaises(NotImplementedError):
         with tempfile.TemporaryDirectory() as tempdir:
             check_hash(tempdir, "test_hash", "test_type")