コード例 #1
0
 def setUp(self):
     self.filesystem = fake_filesystem.FakeFilesystem(path_separator='/')
     self.filesystem.is_windows_fs = False
     pathlib = fake_pathlib.FakePathlibModule(self.filesystem)
     self.path = pathlib.Path
     self.filesystem.CreateFile('/home/jane/test.py',
                                st_size=100,
                                st_mode=stat.S_IFREG | 0o666)
     self.filesystem.CreateDirectory('/home/john')
     self.filesystem.CreateLink('/john', '/home/john')
     self.filesystem.CreateLink('/test.py', '/home/jane/test.py')
     self.filesystem.CreateLink('/broken_dir_link', '/home/none')
     self.filesystem.CreateLink('/broken_file_link', '/home/none/test.py')
コード例 #2
0
def gamedb() -> Path:
    """Mock supported game database file."""

    file_path = '/gamedb.yaml'
    file_contents = {
        'minecraft': dict(id=432, version='DEFAULT'),
    }

    fs = fake_filesystem.FakeFilesystem(path_separator='/')
    pathlib = fake_pathlib.FakePathlibModule(fs)

    fs.CreateFile(file_path,
                  contents=yaml.dump(file_contents),
                  encoding='utf-8')
    return pathlib.Path(file_path)
コード例 #3
0
    def _refresh(self):
        """Renew the fake file system and set the _isStale flag to `False`."""
        if self._stubs is not None:
            self._stubs.SmartUnsetAll()
        self._stubs = mox3.stubout.StubOutForTesting()

        self.fs = fake_filesystem.FakeFilesystem()
        self.fake_os = fake_filesystem.FakeOsModule(self.fs)
        self.fake_path = self.fake_os.path
        if self.HAS_PATHLIB:
            self.fake_pathlib = fake_pathlib.FakePathlibModule(self.fs)
        self.fake_shutil = fake_filesystem_shutil.FakeShutilModule(self.fs)
        self.fake_tempfile_ = fake_tempfile.FakeTempfileModule(self.fs)
        self.fake_open = fake_filesystem.FakeFileOpen(self.fs)
        self.fake_io = fake_filesystem.FakeIoModule(self.fs)

        self._isStale = False
コード例 #4
0
 def setUp(self):
     super().setUp()
     if not self.use_real_fs():
         self.pathlib = fake_pathlib.FakePathlibModule(self.filesystem)
     self.path = self.pathlib.Path
コード例 #5
0
 def setUp(self):
     self.filesystem = fake_filesystem.FakeFilesystem(path_separator='/')
     self.pathlib = fake_pathlib.FakePathlibModule(self.filesystem)
     self.os = fake_filesystem.FakeOsModule(self.filesystem)
コード例 #6
0
def test_run_sodar_ingest_fastq_smoke_test(mocker, requests_mock):
    # --- setup arguments
    irods_path = "/irods/dest"
    landing_zone_uuid = "landing_zone_uuid"
    dest_path = "target/folder/generic_file.fq.gz"
    fake_base_path = "/base/path"
    argv = [
        "--verbose",
        "sodar",
        "ingest-fastq",
        "--num-parallel-transfers",
        "0",
        "--sodar-api-token",
        "XXXX",
        "--yes",
        "--remote-dir-pattern",
        dest_path,
        fake_base_path,
        landing_zone_uuid,
    ]

    parser, _subparsers = setup_argparse()
    args = parser.parse_args(argv)

    # Setup fake file system but only patch selected modules.  We cannot use the Patcher approach here as this would
    # break biomedsheets.
    fs = fake_filesystem.FakeFilesystem()
    fake_os = fake_filesystem.FakeOsModule(fs)
    fake_pl = fake_pathlib.FakePathlibModule(fs)

    # --- add test files
    fake_file_paths = []
    for member in ("sample1", "sample2", "sample3"):
        for ext in ("", ".md5"):
            fake_file_paths.append("%s/%s/%s-N1-RNA1-RNA_seq1.fastq.gz%s" %
                                   (fake_base_path, member, member, ext))
            fs.create_file(fake_file_paths[-1])
            fake_file_paths.append("%s/%s/%s-N1-DNA1-WES1.fq.gz%s" %
                                   (fake_base_path, member, member, ext))
            fs.create_file(fake_file_paths[-1])

    # Remove index's log MD5 file again so it is recreated.
    fs.remove(fake_file_paths[3])

    # --- mock modules
    mocker.patch("glob.os", fake_os)
    mocker.patch("cubi_tk.sea_snap.itransfer_results.pathlib", fake_pl)
    mocker.patch("cubi_tk.sea_snap.itransfer_results.os", fake_os)
    mocker.patch("cubi_tk.snappy.itransfer_common.os", fake_os)

    mock_check_output = mock.MagicMock(return_value=0)
    mocker.patch("cubi_tk.snappy.itransfer_common.check_output",
                 mock_check_output)

    mock_check_call = mock.MagicMock(return_value=0)
    mocker.patch("cubi_tk.snappy.itransfer_common.check_call", mock_check_call)

    mocker.patch("cubi_tk.sodar.ingest_fastq.pathlib", fake_pl)
    mocker.patch("cubi_tk.sodar.ingest_fastq.os", fake_os)

    fake_open = fake_filesystem.FakeFileOpen(fs)
    mocker.patch("cubi_tk.snappy.itransfer_common.open", fake_open)

    # necessary because independent test fail
    mock_value = mock.MagicMock()
    mocker.patch("cubi_tk.sodar.ingest_fastq.Value", mock_value)
    mocker.patch("cubi_tk.snappy.itransfer_common.Value", mock_value)

    # requests mock
    return_value = dict(
        assay="",
        config_data="",
        configuration="",
        date_modified="",
        description="",
        irods_path=irods_path,
        project="",
        sodar_uuid="",
        status="",
        status_info="",
        title="",
        user=dict(sodar_uuid="", username="", name="", email=""),
    )
    url = os.path.join(args.sodar_url, "landingzones", "api", "retrieve",
                       args.destination)
    requests_mock.register_uri("GET", url, text=json.dumps(return_value))

    # --- run tests
    res = main(argv)

    assert not res

    # TODO: make mock check_output actually create the file?
    # assert fs.exists(fake_file_paths[3])

    assert mock_check_call.call_count == 1
    assert mock_check_call.call_args[0] == ([
        "md5sum", "sample1-N1-DNA1-WES1.fq.gz"
    ], )

    assert mock_check_output.call_count == len(fake_file_paths) * 3
    remote_path = os.path.join(irods_path, dest_path)
    for path in fake_file_paths:
        expected_mkdir_argv = ["imkdir", "-p", os.path.dirname(remote_path)]
        ext = ".md5" if path.split(".")[-1] == "md5" else ""
        expected_irsync_argv = [
            "irsync", "-a", "-K", path, ("i:%s" + ext) % remote_path
        ]
        expected_ils_argv = ["ils", os.path.dirname(remote_path)]

        assert ((expected_mkdir_argv, ), ) in mock_check_output.call_args_list
        assert ((expected_irsync_argv, ), ) in mock_check_output.call_args_list
        assert ((expected_ils_argv, ), {
            "stderr": -2
        }) in mock_check_output.call_args_list
コード例 #7
0
 def setUp(self):
     filesystem = fake_filesystem.FakeFilesystem(path_separator='/')
     filesystem.is_windows_fs = True
     pathlib = fake_pathlib.FakePathlibModule(filesystem)
     self.path = pathlib.Path
コード例 #8
0
 def setUp(self):
     self.filesystem = fake_filesystem.FakeFilesystem(path_separator='!')
     # self.filesystem.is_windows_fs = False
     self.filesystem.is_case_sensitive = True
     pathlib = fake_pathlib.FakePathlibModule(self.filesystem)
     self.path = pathlib.Path
コード例 #9
0
def test_run_seasnap_itransfer_results_smoke_test(mocker):
    # --- setup arguments
    dest_path = "/irods/dest"
    fake_base_path = "/base/path"
    blueprint_path = os.path.join(os.path.dirname(__file__), "data",
                                  "test_blueprint.txt")

    argv = [
        "--verbose",
        "sea-snap",
        "itransfer-results",
        blueprint_path,
        dest_path,
        "--num-parallel-transfers",
        "0",
    ]

    parser, subparsers = setup_argparse()

    # Setup fake file system but only patch selected modules.  We cannot use the Patcher approach here as this would
    # break biomedsheets.
    fs = fake_filesystem.FakeFilesystem()
    fake_os = fake_filesystem.FakeOsModule(fs)
    fake_pl = fake_pathlib.FakePathlibModule(fs)

    # --- add test files
    fake_file_paths = []
    for member in ("sample1", "sample2", "sample3"):
        for ext in ("", ".md5"):
            fake_file_paths.append(
                "%s/mapping/star/%s/out/star.%s-N1-RNA1-RNA-Seq1.bam%s" %
                (fake_base_path, member, member, ext))
            fs.create_file(fake_file_paths[-1])
            fake_file_paths.append(
                "%s/mapping/star/%s/report/star.%s-N1-RNA1-RNA-Seq1.log%s" %
                (fake_base_path, member, member, ext))
            fs.create_file(fake_file_paths[-1])

    fs.add_real_file(blueprint_path)
    fake_pl.Path(blueprint_path).touch()

    # Remove index's log MD5 file again so it is recreated.
    fs.remove(fake_file_paths[3])

    # --- mock modules
    mocker.patch("glob.os", fake_os)
    mocker.patch("cubi_tk.sea_snap.itransfer_results.pathlib", fake_pl)
    mocker.patch("cubi_tk.sea_snap.itransfer_results.os", fake_os)
    mocker.patch("cubi_tk.snappy.itransfer_common.os", fake_os)

    mock_check_output = mock.mock_open()
    mocker.patch("cubi_tk.sea_snap.itransfer_results.check_output",
                 mock_check_output)
    mocker.patch("cubi_tk.snappy.itransfer_common.check_output",
                 mock_check_output)

    mock_check_call = mock.mock_open()
    mocker.patch("cubi_tk.snappy.itransfer_common.check_call", mock_check_call)

    fake_open = fake_filesystem.FakeFileOpen(fs)
    mocker.patch("cubi_tk.snappy.itransfer_common.open", fake_open)

    # necessary because independent test fail
    mock_value = mock.MagicMock()
    mocker.patch("cubi_tk.sea_snap.itransfer_results.Value", mock_value)
    mocker.patch("cubi_tk.snappy.itransfer_common.Value", mock_value)

    # --- run tests
    res = main(argv)

    print(mock_check_output.call_args_list)

    assert not res

    assert fs.exists(fake_file_paths[3])

    assert mock_check_call.call_count == 1
    assert mock_check_call.call_args[0] == ([
        "md5sum", "star.sample1-N1-RNA1-RNA-Seq1.log"
    ], )

    assert mock_check_output.call_count == len(fake_file_paths) * 2
    remote_path = os.path.join(dest_path, "fakedest")
    for path in fake_file_paths:
        expected_mkdir_argv = f"imkdir -p $(dirname {remote_path} )"
        ext = ".md5" if path.split(".")[-1] == "md5" else ""
        expected_irsync_argv = f"irsync -a -K {path} {('i:%s' + ext) % remote_path}"

        assert ((expected_mkdir_argv, ), {
            "shell": True
        }) in mock_check_output.call_args_list
        assert ((expected_irsync_argv, ), {
            "shell": True
        }) in mock_check_output.call_args_list