<commit_before>from unittest import TestCase

from ect.core import DatasetCollection


class CdmTest(TestCase):
    def test_use_case(self):
        xarray_ds = {}
        shapefile_ds = {}

        collection = DatasetCollection()

        collection.add_xarray_dataset(xarray_ds)
        collection.add_shapefile_dataset(shapefile_ds)

        self.assertEqual(len(collection.wrapped_datasets), 2)
        self.assertEqual(len(collection.datasets), 2)

        subset = collection.subset(spatial_roi=(0, 0, 1, 1))

        self.assertEqual(len(subset.wrapped_datasets), 2)

        subset.close()

        collection.remove_dataset(xarray_ds)
        collection.remove_dataset(shapefile_ds)

        self.assertEqual(len(collection.wrapped_datasets), 0)

        collection.close()


from ect.core.cdm_xarray import XArrayDatasetAdapter


class DatasetCollectionTest(TestCase):
    def test_use_case(self):
        ds1 = XArrayDatasetAdapter({'a': 1})
        ds2 = XArrayDatasetAdapter({'b': 2})
        ds3 = XArrayDatasetAdapter({'c': 3})
        ds4 = XArrayDatasetAdapter({'d': 4})
        ds5 = XArrayDatasetAdapter({'e': 5})

        dsc = DatasetCollection(ds1, ds2, ds3, ozone=ds4, aerosol=ds5)
        self.assertEqual(dsc.datasets, [ds1, ds2, ds3, ds4, ds5])
        self.assertEqual(dsc.wrapped_datasets, [{'a': 1}, {'b': 2}, {'c': 3}, {'d': 4}, {'e': 5}])

        removed_ds = dsc.remove_dataset('ozone')
        self.assertIs(removed_ds, ds4)
        self.assertEqual(dsc.datasets, [ds1, ds2, ds3, ds5])
        self.assertEqual(dsc.wrapped_datasets, [{'a': 1}, {'b': 2}, {'c': 3}, {'e': 5}])

        removed_ds = dsc.remove_dataset(ds1)
        self.assertIs(removed_ds, ds1)
        self.assertEqual(dsc.datasets, [ds2, ds3, ds5])
        self.assertEqual(dsc.wrapped_datasets, [{'b': 2}, {'c': 3}, {'e': 5}])

        removed_ds = dsc.remove_dataset(ds3.wrapped_dataset)
        self.assertIs(removed_ds, ds3)
        self.assertEqual(dsc.datasets, [ds2, ds5])
        self.assertEqual(dsc.wrapped_datasets, [{'b': 2}, {'e': 5}])

        removed_ds = dsc.remove_dataset(ds3)
        self.assertIs(removed_ds, None)
<commit_msg>fixed test bug<commit_after>from unittest import TestCase

from ect.core import DatasetCollection


class CdmTest(TestCase):
    def test_use_case(self):
        xarray_ds = {}
        shapefile_ds = {}

        collection = DatasetCollection()

        collection.add_xarray_dataset(xarray_ds)
        collection.add_shapefile_dataset(shapefile_ds)

        self.assertEqual(len(collection.wrapped_datasets), 2)
        self.assertEqual(len(collection.datasets), 2)

        subset = collection.subset(spatial_roi=(0, 0, 1, 1))

        self.assertEqual(len(subset.wrapped_datasets), 2)

        subset.close()

        collection.remove_dataset(xarray_ds)
        collection.remove_dataset(shapefile_ds)

        self.assertEqual(len(collection.wrapped_datasets), 0)

        collection.close()


from ect.core.cdm_xarray import XArrayDatasetAdapter


class DatasetCollectionTest(TestCase):
    def test_use_case(self):
        ds1 = XArrayDatasetAdapter('A')
        ds2 = XArrayDatasetAdapter('B')
        ds3 = XArrayDatasetAdapter('C')
        ds4 = XArrayDatasetAdapter('D')
        ds5 = XArrayDatasetAdapter('E')

        dsc = DatasetCollection(ds1, ds2, ds3, ozone=ds4, aerosol=ds5)
        self.assertEqual(set(dsc.datasets), {ds1, ds2, ds3, ds4, ds5})
        self.assertEqual(set(dsc.wrapped_datasets), {'A', 'B', 'C', 'D', 'E'})

        removed_ds = dsc.remove_dataset('ozone')
        self.assertIs(removed_ds, ds4)
        self.assertEqual(set(dsc.datasets), {ds1, ds2, ds3, ds5})
        self.assertEqual(set(dsc.wrapped_datasets), {'A', 'B', 'C', 'E'})

        removed_ds = dsc.remove_dataset(ds1)
        self.assertIs(removed_ds, ds1)
        self.assertEqual(set(dsc.datasets), {ds2, ds3, ds5})
        self.assertEqual(set(dsc.wrapped_datasets), {'B', 'C', 'E'})

        removed_ds = dsc.remove_dataset(ds3.wrapped_dataset)
        self.assertIs(removed_ds, ds3)
        self.assertEqual(set(dsc.datasets), {ds2, ds5})
        self.assertEqual(set(dsc.wrapped_datasets), {'B', 'E'})

        removed_ds = dsc.remove_dataset(ds3)
        self.assertIs(removed_ds, None)

{'fraction_non_alphanumeric': 0.1378416588124411, 'fraction_numerical': 0.022384542884071632, 'mean_word_length': 3.2620481927710845, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1254971', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1453, 'n_words': 243}