Esempio n. 1
0
def get_measure_calculators(measures,
                            year=config.get('calculation.measures_year')):
    """Generate a dictionary of measure calculator object with correct definition and type."""
    json_path = config.get('assets.qpp_single_source_json')[year]
    single_source_json = measure_reader.load_single_source(json_path)
    return {
        measure: get_measure_calculator(
            measure_number=measure,
            year=year,
            single_source_json=single_source_json,
        )
        for measure in measures
    }
Esempio n. 2
0
 def setup_class(cls):
     """Load all measures for further tests."""
     # Use 2018 as measures year in config.
     year = 2018
     cls.measures = measure_mapping.get_all_measure_ids(year=year)
     cls.single_source = measure_reader.load_single_source(
         json_path=config.get('assets.qpp_single_source_json')[year])
     cls.measure_calculators = measure_mapping.get_measure_calculators(
         measures=cls.measures, year=year).values()
     cls.measure_definitions = [
         calculator.measure_definition
         for calculator in cls.measure_calculators
     ]
Esempio n. 3
0
 def setup_class(cls):
     """Load all measures for further tests."""
     # TODO: Test these functions with their default values from config.
     year = 2017
     cls.measures = measure_mapping.get_all_measure_ids(year=year)
     cls.single_source = measure_reader.load_single_source(
         json_path=config.get('assets.qpp_single_source_json')[year])
     cls.measure_calculators = measure_mapping.get_measure_calculators(
         measures=cls.measures, year=year).values()
     cls.measure_definitions = [
         calculator.measure_definition
         for calculator in cls.measure_calculators
     ]
Esempio n. 4
0
def get_measure_calculator(
        measure_number,
        year=config.get('calculation.measures_year'),
        single_source_json=measure_reader.load_single_source(),
):
    """Generate a measure calculator object with correct definition and type."""
    try:
        measure_definition = measure_reader.load_measure_definition(
            measure_number=measure_number,
            single_source_json=single_source_json)
        calculator_class = _get_measure_class(measure_number=measure_number,
                                              year=year)
        kwargs = _get_measure_args(measure_number=measure_number, year=year)
        return calculator_class(measure_definition=measure_definition,
                                **kwargs)
    except KeyError:
        raise KeyError(
            'Measure number {measure_number} is not yet supported for {year}.'.
            format(measure_number=measure_number,
                   year=config.get('calculation.measures_year')))
Esempio n. 5
0
def test_load_single_source_missing_file():
    """Test that load_measure_definition throws the expected error if file is missing."""
    with pytest.raises(IOError):
        measure_reader.load_single_source('missing_path')