Skip to content

added tutorial and better tests #691

added tutorial and better tests

added tutorial and better tests #691

GitHub Actions / Core / Unit Test Results (3.10) failed Jun 20, 2024 in 0s

3 fail, 662 pass in 8m 3s

665 tests  ±0   662 ✅ ±0   8m 3s ⏱️ +2s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     3 ❌ ±0 

Results for commit 8709a71. ± Comparison against earlier commit 0465790.

Annotations

Check warning on line 0 in climada.hazard.test.test_base.TestSelect

See this annotation in the file changed.

@github-actions github-actions / Core / Unit Test Results (3.10)

test_select_new_fraction_zero (climada.hazard.test.test_base.TestSelect) failed

tests_xml/tests.xml [took 0s]
Raw output
AssertionError: RuntimeError not raised
self = <climada.hazard.test.test_base.TestSelect testMethod=test_select_new_fraction_zero>

    def test_select_new_fraction_zero(self):
        """Check if a new fraction of only zeros is handled correctly"""
        hazard = dummy_hazard()
        hazard.centroids.gdf["region_id"] = [1, 1, 2]
    
        # Select a part of the hazard where fraction is zero only
>       with self.assertRaisesRegex(
            RuntimeError,
            "Your selection created a Hazard object where the fraction matrix is zero "
            "everywhere"
        ):
E       AssertionError: RuntimeError not raised

climada/hazard/test/test_base.py:603: AssertionError

Check warning on line 0 in climada.hazard.test.test_io.TestReadDefaultNetCDF

See this annotation in the file changed.

@github-actions github-actions / Core / Unit Test Results (3.10)

test_event_no_time (climada.hazard.test.test_io.TestReadDefaultNetCDF) failed

tests_xml/tests.xml [took 0s]
Raw output
AssertionError: no logs of level WARNING or higher triggered on climada.hazard.io
self = <climada.hazard.test.test_io.TestReadDefaultNetCDF testMethod=test_event_no_time>

    def test_event_no_time(self):
        """Test if an event coordinate that is not a time works"""
        with xr.open_dataset(self.netcdf_path) as dataset:
            size = dataset.sizes["time"]
    
            # Positive integers (interpreted as ordinals)
            time = [2, 1]
            dataset["time"] = time
            hazard = Hazard.from_xarray_raster(dataset, "", "")
            self._assert_default_types(hazard)
            np.testing.assert_array_equal(
                hazard.intensity.toarray(), [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11]]
            )
            np.testing.assert_array_equal(hazard.date, time)
            np.testing.assert_array_equal(hazard.event_name, np.full(size, ""))
    
            # Strings
            dataset["time"] = ["a", "b"]
>           with self.assertLogs("climada.hazard.io", "WARNING") as cm:

climada/hazard/test/test_io.py:182: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../micromamba/envs/climada_env_3.10/lib/python3.10/unittest/_log.py:84: in __exit__
    self._raiseFailure(
E   AssertionError: no logs of level WARNING or higher triggered on climada.hazard.io

Check warning on line 0 in climada.hazard.test.test_io.TestHDF5

See this annotation in the file changed.

@github-actions github-actions / Core / Unit Test Results (3.10)

test_write_read_unsupported_type (climada.hazard.test.test_io.TestHDF5) failed

tests_xml/tests.xml [took 0s]
Raw output
AssertionError: no logs of level WARNING or higher triggered on climada.hazard.io
self = <climada.hazard.test.test_io.TestHDF5 testMethod=test_write_read_unsupported_type>

    def test_write_read_unsupported_type(self):
        """Check if the write command correctly handles unsupported types"""
        file_name = str(DATA_DIR.joinpath('test_unsupported.h5'))
    
        # Define an unsupported type
        class CustomID:
            id = 1
    
        # Create a hazard with unsupported type as attribute
        hazard = dummy_hazard()
        hazard.event_id = CustomID()
    
        # Write the hazard and check the logs for the correct warning
>       with self.assertLogs(logger="climada.hazard.io", level="WARN") as cm:

climada/hazard/test/test_io.py:676: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../micromamba/envs/climada_env_3.10/lib/python3.10/unittest/_log.py:84: in __exit__
    self._raiseFailure(
E   AssertionError: no logs of level WARNING or higher triggered on climada.hazard.io