예제 #1
0
def test_log_artifacts(gcs_mock, tmpdir):
    repo = GCSArtifactRepository("gs://test_bucket/some/path", gcs_mock)

    subd = tmpdir.mkdir("data").mkdir("subdir")
    subd.join("a.txt").write("A")
    subd.join("b.txt").write("B")
    subd.join("c.txt").write("C")

    mock_method_chain(
        gcs_mock,
        [
            "Client",
            "bucket",
            "blob",
            "upload_from_filename",
        ],
        side_effect=os.path.isfile,
    )
    repo.log_artifacts(subd.strpath)

    gcs_mock.Client().bucket.assert_called_with("test_bucket")
    gcs_mock.Client().bucket().blob().upload_from_filename.assert_has_calls(
        [
            mock.call(os.path.normpath("%s/a.txt" % subd.strpath)),
            mock.call(os.path.normpath("%s/b.txt" % subd.strpath)),
            mock.call(os.path.normpath("%s/c.txt" % subd.strpath)),
        ],
        any_order=True,
    )
예제 #2
0
def test_log_artifacts(gcs_mock, tmpdir):
    repo = GCSArtifactRepository("gs://test_bucket/some/path", gcs_mock)

    subd = tmpdir.mkdir("data").mkdir("subdir")
    subd.join("a.txt").write("A")
    subd.join("b.txt").write("B")
    subd.join("c.txt").write("C")

    gcs_mock.Client.return_value.get_bucket.return_value.blob.return_value\
        .upload_from_filename.side_effect = os.path.isfile
    repo.log_artifacts(subd.strpath)

    gcs_mock.Client().get_bucket.assert_called_with('test_bucket')
    gcs_mock.Client().get_bucket().blob().upload_from_filename\
        .assert_has_calls([
            mock.call(os.path.normpath('%s/a.txt' % subd.strpath)),
            mock.call(os.path.normpath('%s/b.txt' % subd.strpath)),
            mock.call(os.path.normpath('%s/c.txt' % subd.strpath)),
        ], any_order=True)
예제 #3
0
def test_log_artifacts(gcs_mock, tmpdir):
    repo = GCSArtifactRepository("gs://test_bucket/some/path", gcs_mock)

    subd = tmpdir.mkdir("data").mkdir("subdir")
    subd.join("a.txt").write("A")
    subd.join("b.txt").write("B")
    subd.join("c.txt").write("C")

    def custom_isfile(*args, **kwargs):
        if args:
            return os.path.isfile(args[0])
        return os.path.isfile(kwargs.get("filename"))

    mock_method_chain(
        gcs_mock,
        [
            "Client",
            "bucket",
            "blob",
            "upload_from_filename",
        ],
        side_effect=custom_isfile,
    )
    repo.log_artifacts(subd.strpath)

    gcs_mock.Client().bucket.assert_called_with("test_bucket")
    gcs_mock.Client().bucket().blob().upload_from_filename.assert_has_calls(
        [
            mock.call(os.path.normpath("%s/a.txt" % subd.strpath),
                      timeout=repo._GCS_DEFAULT_TIMEOUT),
            mock.call(os.path.normpath("%s/b.txt" % subd.strpath),
                      timeout=repo._GCS_DEFAULT_TIMEOUT),
            mock.call(os.path.normpath("%s/c.txt" % subd.strpath),
                      timeout=repo._GCS_DEFAULT_TIMEOUT),
        ],
        any_order=True,
    )