def test_both(images, deployments):
    result = compute_date_ranges(images=images,
                                 deployments=deployments,
                                 source="both")
    expected = pd.DataFrame({
        "deployment_id": ["001", "002", "003", "001", "002", "003"],
        "start_date":
        pd.to_datetime([
            "2021-02-16",
            "2021-02-03",
            "2021-02-03",
            "2021-02-13",
            "2021-02-01",
            "2021-03-01",
        ]),
        "end_date":
        pd.to_datetime([
            "2021-03-20",
            "2021-03-30",
            "2021-03-23",
            "2021-03-23",
            "2021-04-03",
            "2021-03-27",
        ]),
        "source": [
            "images",
            "images",
            "images",
            "deployments",
            "deployments",
            "deployments",
        ],
    })
    pd.testing.assert_frame_equal(result, expected)
def test_pivot(images, deployments):
    result = compute_date_ranges(images=images,
                                 deployments=deployments,
                                 source="both",
                                 pivot=True)
    expected = pd.DataFrame(
        {
            ("start_date", "deployments"):
            pd.to_datetime(["2021-02-13", "2021-02-01", "2021-03-01"]),
            ("start_date", "images"):
            pd.to_datetime(["2021-02-16", "2021-02-03", "2021-02-03"]),
            ("end_date", "deployments"):
            pd.to_datetime(["2021-03-23", "2021-04-03", "2021-03-27"]),
            ("end_date", "images"):
            pd.to_datetime(["2021-03-20", "2021-03-30", "2021-03-23"]),
        },
        index=pd.Index(["001", "002", "003"], name="deployment_id"),
    )
    pd.testing.assert_frame_equal(result, expected, check_names=False)
def test_compute_delta(images):
    result = compute_date_ranges(images=images,
                                 source="images",
                                 compute_delta=True)
    expected = pd.DataFrame({
        "deployment_id": ["001", "002", "003"],
        "start_date":
        pd.to_datetime([
            "2021-02-16",
            "2021-02-03",
            "2021-02-03",
        ]),
        "end_date":
        pd.to_datetime([
            "2021-03-20",
            "2021-03-30",
            "2021-03-23",
        ]),
        "source": ["images", "images", "images"],
        "delta": [32, 55, 48],
    })
    pd.testing.assert_frame_equal(result, expected)
def test_no_deployments(images):
    with pytest.raises(ValueError):
        compute_date_ranges(images=images, source="both")
def test_invalid_source(images, deployments):
    with pytest.raises(ValueError):
        compute_date_ranges(images=images,
                            deployments=deployments,
                            source="records")
def test_intact_input(images, deployments):
    images_original = images.copy()
    deployments_original = deployments.copy()
    compute_date_ranges(images=images, deployments=deployments, source="both")
    pd.testing.assert_frame_equal(images_original, images)
    pd.testing.assert_frame_equal(deployments_original, deployments)