Esempio n. 1
0
    def test_raises_exception_for_impossible_aggregation(self):
        """Test function raises an exception when attempting to create an
        accumulation_period that cannot be created from the input cubes."""

        time_interval = 61
        plugin = Accumulation(accumulation_period=120)
        msg = "The specified accumulation period "

        with self.assertRaisesRegex(ValueError, msg):
            plugin._get_period_sets(time_interval, self.cubes)
Esempio n. 2
0
    def test_raises_warning_for_unused_cubes(self, warning_list=None):
        """Test function raises a warning when there are insufficient cubes to
        complete the last period. In this test the accumulation period is 3
        minutes, but the total span of rates cubes covers 10 minutes, resulting
        in 3 complete periods and a final incomplete period that is not
        returned. This test checks that a warning is raised to highlight that
        there is an incomplete final period that is not returned."""

        time_interval = 60
        warning_msg = (
            "The provided cubes result in a partial period given the specified"
            " accumulation_period, i.e. the number of cubes is insufficient to"
            " give a set of complete periods. Only complete periods will be"
            " returned.")

        expected = [self.cubes[0:4], self.cubes[3:7], self.cubes[6:10]]

        plugin = Accumulation(accumulation_period=180)
        result = plugin._get_period_sets(time_interval, self.cubes)

        for index, sublist in enumerate(result):
            self.assertSequenceEqual(sublist, expected[index])
        self.assertTrue(
            any(item.category == UserWarning for item in warning_list))
        self.assertTrue(any(warning_msg in str(item) for item in warning_list))
Esempio n. 3
0
    def test_returns_correct_type(self):
        """Test function returns the expected list."""

        time_interval = 60
        plugin = Accumulation(accumulation_period=120)
        result = plugin._get_period_sets(time_interval, self.cubes)
        self.assertIsInstance(result, list)
Esempio n. 4
0
    def test_returns_all_cubes_if_period_unspecified(self):
        """Test function returns a list containing the original cube list if
        the accumulation_period is not set."""

        time_interval = 60
        plugin = Accumulation()
        result = plugin._get_period_sets(time_interval, self.cubes)
        self.assertSequenceEqual(result, [self.cubes])
Esempio n. 5
0
    def test_returns_expected_cubes(self, warning_list=None):
        """Test function returns lists containing the expected cubes for each
        period. In this test all the cubes are used as the total time span of
        precipitation rates cubes is divisible by the requested accumulation
        period."""

        time_interval = 60
        expected = [self.cubes[0:6], self.cubes[5:]]

        plugin = Accumulation(accumulation_period=300)
        result = plugin._get_period_sets(time_interval, self.cubes)

        for index, sublist in enumerate(result):
            self.assertSequenceEqual(sublist, expected[index])