<commit_before>from __future__ import absolute_import

import numpy as np
import h5py

from ..common import ut, TestCase


@ut.skipUnless(h5py.version.hdf5_version_tuple < (1, 9, 178), 'SWMR is available. Skipping backwards compatible tests')
class TestSwmrNotAvailable(TestCase):
    """ Test backwards compatibility behaviour when using SWMR functions with 
    an older version of HDF5 which does not have this feature available.
    Skip this test if SWMR features *are* available in the HDF5 library.
    """
    
    def setUp(self):
        TestCase.setUp(self)
        self.data = np.arange(13).astype('f')
        self.dset = self.f.create_dataset('data', chunks=(13,), maxshape=(None,), data=self.data)
        fname = self.f.filename
        self.f.close()
       
        self.f = h5py.File(fname, 'r', swmr=True) # The swmr=True flag is ignored in this case
        self.dset = self.f['data']
        
    def test_read_data(self):
        self.assertArrayEqual(self.dset, self.data)
        
    def test_refresh_raises(self):
        """ If the SWMR feature is not available then Dataset.refresh() should throw an AttributeError
        """
        with self.assertRaises(AttributeError):
            self.dset.refresh()

    def test_flush_raises(self):
        """ If the SWMR feature is not available the Dataset.flush() should 
        throw an AttributeError
        """
        with self.assertRaises(AttributeError):
            self.dset.flush()
            
    def test_swmr_mode_raises(self):
        with self.assertRaises(AttributeError):
            self.f.swmr_mode
            
@ut.skipUnless(h5py.version.hdf5_version_tuple >= (1, 9, 178), 'SWMR requires HDF5 >= 1.9.178')
class TestDatasetSwmrRead(TestCase):
    """ Testing SWMR functions when reading a dataset.
    Skip this test if the HDF5 library does not have the SWMR features.
    """
    
    def setUp(self):
        TestCase.setUp(self)<commit_msg>SWMR unittest update<commit_after>from __future__ import absolute_import

import numpy as np
import h5py

from ..common import ut, TestCase


@ut.skipUnless(h5py.version.hdf5_version_tuple < (1, 9, 178), 'SWMR is available. Skipping backwards compatible tests')
class TestSwmrNotAvailable(TestCase):
    """ Test backwards compatibility behaviour when using SWMR functions with 
    an older version of HDF5 which does not have this feature available.
    Skip this test if SWMR features *are* available in the HDF5 library.
    """
    
    def setUp(self):
        TestCase.setUp(self)
        self.data = np.arange(13).astype('f')
        self.dset = self.f.create_dataset('data', chunks=(13,), maxshape=(None,), data=self.data)

    def test_open_swmr_raises(self):
        fname = self.f.filename
        self.f.close()
 
        with self.assertRaises(ValueError):
            self.f = h5py.File(fname, 'r', swmr=True)
        
    def test_refresh_raises(self):
        """ If the SWMR feature is not available then Dataset.refresh() should throw an AttributeError
        """
        with self.assertRaises(AttributeError):
            self.dset.refresh()

    def test_flush_raises(self):
        """ If the SWMR feature is not available the Dataset.flush() should 
        throw an AttributeError
        """
        with self.assertRaises(AttributeError):
            self.dset.flush()
            
    def test_swmr_mode_raises(self):
        with self.assertRaises(AttributeError):
            self.f.swmr_mode
            
@ut.skipUnless(h5py.version.hdf5_version_tuple >= (1, 9, 178), 'SWMR requires HDF5 >= 1.9.178')
class TestDatasetSwmrRead(TestCase):
    """ Testing SWMR functions when reading a dataset.
    Skip this test if the HDF5 library does not have the SWMR features.
    """
    
    def setUp(self):
        TestCase.setUp(self)
{'fraction_non_alphanumeric': 0.09758022093634929, 'fraction_numerical': 0.015255128879537085, 'mean_word_length': 2.76162215628091, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4208933', 'n_tokens_mistral': 1174, 'n_tokens_neox': 1127, 'n_words': 323}