Skip to content

Commit

Permalink
Fix version checking and other typos
Browse files Browse the repository at this point in the history
  • Loading branch information
hmaarrfk committed Aug 30, 2022
1 parent e61d763 commit 9c55cde
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions test/tst_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
import tempfile, unittest, os
import numpy as np

libversion= tuple(int(v) for v in netCDF4.__netcdf4libversion__.split('.'))
# During testing, sometimes development versions are used.
# They may be written as 4.9.1-development
libversion_no_development = netCDF4.__netcdf4libversion__.split('-')[0]
libversion = tuple(int(v) for v in libversion_no_development.split('.'))
has_alignment = (libversion[0] > 4) or (
libversion[0] == 4 and (libversion[1] >= 9)
)

file_name = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name


def is_aligned(dataset, offset=4096):
# Here we check if the dataset is aligned
return dataset.id.get_offset() % offset == 0


class AlignmentTestCase(unittest.TestCase):
def setUp(self):
self.file = file_name
Expand All @@ -40,12 +45,11 @@ def test_version_settings(self):
set_alignment(0, 0)
assert get_alignment() == (0, 0)
else:
with self.assertRaises(RunetimeError):
with self.assertRaises(RuntimeError):
set_alignment(0, 0)
with self.assertRaises(RunetimeError):
with self.assertRaises(RuntimeError):
get_alignment(0, 0)


def test_setting_alignment(self):
# if we have no support for alignment, we have no guarantees on
# how the data can be aligned
Expand All @@ -61,10 +65,10 @@ def test_setting_alignment(self):
v = h5file[f'data{i:02d}']
assert is_aligned(v, offset=4096)


def tearDown(self):
# Remove the temporary files
os.remove(self.file)


if __name__ == '__main__':
unittest.main()

0 comments on commit 9c55cde

Please sign in to comment.