Ejemplo n.º 1
0
    def test_transform(self):
        aws_burn_rate = AwsBurnRate.AwsBurnRate(config)
        res = aws_burn_rate.transform(data_block)
        verify_products(aws_burn_rate, res)

        expected_df = expected_transform_output["AWS_Burn_Rate"]
        res_df = res["AWS_Burn_Rate"]
        assert np.isclose(expected_df["BurnRate"], res_df["BurnRate"])
Ejemplo n.º 2
0
 def test_acquire(self):
     with mock.patch.object(google.auth, "default") as default:
         default.return_value = (None, None)
         with mock.patch.object(GceOccupancy.GceOccupancy, "_get_client") as client:
             client.return_value = MockClient()
             occupancy = GceOccupancy.GceOccupancy(CONFIG)
             res = occupancy.acquire()
             verify_products(occupancy, res)
             assert EXPECTED_DF.equals(res.get("GCE_Occupancy"))
def test_transform():
    nersc_figure_of_merit = NerscFigureOfMerit.NerscFigureOfMerit(config)
    res = nersc_figure_of_merit.transform(data_block)
    verify_products(nersc_figure_of_merit, res)
    for key, value in res.items():
        try:
            assert expected_transform_output[key].equals(value)
        except Exception:
            print(key, " fail\n", expected_transform_output[key], "\n", value)
def test_acquire():
    nersc_job_info = NerscJobInfo.NerscJobInfo(CONFIG)
    with mock.patch.object(newt.Newt, "get_status") as get_status:
        get_status.return_value = utils.input_from_file(STATUS_FIXTURE_FILE)
        with mock.patch.object(newt.Newt, "get_queue") as get_queue:
            get_queue.return_value = utils.input_from_file(JOBS_FIXTURE_FILE)
            res = nersc_job_info.acquire()
            verify_products(nersc_job_info, res)
            new_df = res["Nersc_Job_Info"]
            new_df = new_df.reindex(EXPECTED_PANDAS_DFRAME.columns, axis=1)
            pandas.testing.assert_frame_equal(EXPECTED_PANDAS_DFRAME, new_df)
def test_acquire():
    def side_effect_get_usage(username):
        if username == FAKE_USER:
            return {"items": []}
        return utils.input_from_file(ALLOCATIONS_FIXTURE_FILE)

    nersc_allocations = NerscAllocationInfo.NerscAllocationInfo(CONFIG)
    with mock.patch.object(newt.Newt, "get_usage") as f:
        f.side_effect = side_effect_get_usage
        res = nersc_allocations.acquire()
        verify_products(nersc_allocations, res)
        assert EXPECTED_PANDAS_DFRAME.equals(res["Nersc_Allocation_Info"])
def test_transform():
    data_block = create_datablock()
    fom = FigureOfMerit.FigureOfMerit(data_block)
    res = fom.transform(data_block)
    verify_products(fom, res)
    for k in expected_reply.keys():
        if k == "AWS_Price_Performance":
            df = fix_column(res[k], "AWS_Price_Performance")
            edf = fix_column(expected_reply[k], "AWS_Price_Performance")
        else:
            df = fix_column(res[k], "AWS_Figure_Of_Merit")
            edf = fix_column(expected_reply[k], "AWS_Figure_Of_Merit")
        pd.testing.assert_frame_equal(edf, df)
Ejemplo n.º 7
0
def test_wrong_product_types():
    @Source.produces(a=str, b=int)
    class AMaker(Source.Source):
        def __init__(self, config):
            super().__init__(config)

        def acquire(self):
            return {"a": 42, "b": 17}

    maker = AMaker({"channel_name": "test"})
    expected_err_msg = "The following products have the wrong types:\n" + r" - 'a' \(expected 'str', got 'int'\)"
    with pytest.raises(Exception, match=expected_err_msg):
        verify_products(maker, maker.acquire())
Ejemplo n.º 8
0
def test_wrong_product_names():
    @Source.produces(a=str)
    class BMaker(Source.Source):
        def __init__(self, config):
            super().__init__(config)

        def acquire(self):
            return {'b': ''}

    maker = BMaker({})
    expected_err_msg = "The following products were not produced:\n" + \
                       " - 'a' of type 'str'\n\n" + \
                       "The following products were not declared:\n" + \
                       " - 'b' of type 'str'"
    with pytest.raises(Exception, match=expected_err_msg):
        verify_products(maker, maker.acquire())
 def test_acquire(self):
     aws_i_p = AWSInstancePerformance.AWSInstancePerformance(config)
     res = aws_i_p.acquire()
     verify_products(aws_i_p, res)
     assert expected_pandas_df.equals(res.get("Performance_Data"))
 def test_acquire(self):
     aws_job_limits = AWSJobLimits.AWSJobLimits(config)
     res = aws_job_limits.acquire()
     verify_products(aws_job_limits, res)
     assert expected_pandas_df.equals(res.get("Job_Limits"))
 def test_acquire(self):
     gce_price_performance = GCEInstancePerformance.GCEInstancePerformance(
         CONFIG)
     res = gce_price_performance.acquire()
     verify_products(gce_price_performance, res)
     assert EXPECTED_PANDAS_DF.equals(res.get('GCE_Instance_Performance'))
 def test_acquire(self):
     nersc_instance_performance = NerscInstancePerformance.NerscInstancePerformance(CONFIG)
     res = nersc_instance_performance.acquire()
     verify_products(nersc_instance_performance, res)
     assert EXPECTED_PANDAS_DF.equals(res.get('Nersc_Instance_Performance'))