Esempio n. 1
0
def _extend_help(fn):
    # TODO: speed up help - pulling in decision tree imports iris
    # (and gets executed at import time)
    from improver.wxcode.utilities import interrogate_decision_tree
    for wxtree in ('high_resolution', 'global'):
        title = wxtree.title().replace('_', ' ') + ' tree inputs'
        inputs = interrogate_decision_tree(wxtree).replace('\n', '\n    ')
        tree_help = f"""
{title}:

    {inputs}
    """
        fn.__doc__ += tree_help
    return fn
Esempio n. 2
0
def _extend_help(fn):
    # TODO: speed up help - pulling in decision tree imports iris
    # (and gets executed at import time)
    from improver.wxcode.utilities import interrogate_decision_tree

    for wxtree in ("high_resolution", "global"):
        title = wxtree.capitalize().replace("_", " ") + " tree inputs"
        inputs = interrogate_decision_tree(wxtree).replace("\n", "\n        ")
        tree_help = f"""
    {title}::

        {inputs}
    """
        fn.__doc__ += tree_help
    return fn
Esempio n. 3
0
def test_interrogate_decision_tree():
    """Test that the function returns the right strings."""
    expected = (
        "\u26C5 probability_of_low_and_medium_type_cloud_area_fraction_above_threshold (1): 0.1875, 0.8125\n"  # noqa: E501
        "\u26C5 probability_of_low_type_cloud_area_fraction_above_threshold (1): 0.85\n"
        "\u26C5 probability_of_lwe_precipitation_rate_above_threshold (mm hr-1): 0.03, 1.0\n"  # noqa: E501
        "\u26C5 probability_of_lwe_precipitation_rate_in_vicinity_above_threshold (mm hr-1): 0.1, 1.0\n"  # noqa: E501
        "\u26C5 probability_of_lwe_sleetfall_rate_above_threshold (mm hr-1): 0.03, 1.0\n"
        "\u26C5 probability_of_lwe_snowfall_rate_above_threshold (mm hr-1): 0.03, 1.0\n"
        "\u26C5 probability_of_number_of_lightning_flashes_per_unit_area_in_vicinity_above_threshold (m-2): 0.0\n"  # noqa: E501
        "\u26C5 probability_of_rainfall_rate_above_threshold (mm hr-1): 0.03, 1.0\n"
        "\u26C5 probability_of_shower_condition_above_threshold (1): 1.0\n"
        "\u26C5 probability_of_visibility_in_air_below_threshold (m): 1000.0, 5000.0\n"
    )
    tree = update_tree_units(wxcode_decision_tree())
    result = interrogate_decision_tree(tree)
    assert result == expected
Esempio n. 4
0
 def test_raises_exception(self):
     """Test the function raises an exception for an unknown weather symbol
     tree name."""
     msg = "Unknown decision tree name provided."
     with self.assertRaisesRegex(ValueError, msg):
         interrogate_decision_tree('kittens')
Esempio n. 5
0
 def test_return_type(self):
     """Test that the function returns a string."""
     result = interrogate_decision_tree('global')
     self.assertIsInstance(result, str)
Esempio n. 6
0
def test_interrogate_decision_tree(tree_name, expected):
    """Test that the function returns the right strings."""
    result = interrogate_decision_tree(tree_name)
    assert result == expected