Skip to content

Commit

Permalink
Add tests for mmap_mode='r+b' and not lazy and padding check
Browse files Browse the repository at this point in the history
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
  • Loading branch information
hakonanes committed Sep 22, 2019
1 parent 96b64e6 commit c203be2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
5 changes: 2 additions & 3 deletions kikuchipy/io_plugins/nordif.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ def file_reader(
'write' in mmap_mode and 'copyonwrite' != mmap_mode):
if lazy:
raise ValueError("Lazy loading does not support in-place writing")
f = open(filename, 'r+b')
scan['attributes']['_lazy'] = True
f = open(filename, mode='r+b')
else:
f = open(filename, 'rb')
f = open(filename, mode='rb')

# Get metadata from setting file
sem_node, ebsd_node = metadata_nodes()
Expand Down
37 changes: 24 additions & 13 deletions kikuchipy/io_plugins/test/test_nordif.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,25 @@ def test_load(self, setting_file):
.static_background.all() == static_bg.all()

@pytest.mark.parametrize('nav_shape, sig_shape', [
((3, 3), (60, 60)), ((3, 4), (50, 50))])
((3, 3), (60, 60)), ((3, 4), (60, 60)), (None, None)])
def test_load_parameters(self, nav_shape, sig_shape):
if sum(nav_shape + sig_shape) > 126:
# Check if zero padding user warning is raised if sum of data shape
# is bigger than file size
with pytest.warns(UserWarning):
if nav_shape is None and sig_shape is None:
with pytest.raises(ValueError):
kp.load(
PATTERN_FILE, setting_file='Setting.txt',
scan_size=nav_shape, pattern_size=sig_shape)
else:
if sum(nav_shape + sig_shape) > 126:
# Check if zero padding user warning is raised if sum of data
# shape is bigger than file size
with pytest.warns(UserWarning):
s = kp.load(
PATTERN_FILE, scan_size=nav_shape,
pattern_size=sig_shape)
else:
s = kp.load(
PATTERN_FILE, scan_size=nav_shape, pattern_size=sig_shape)
else:
s = kp.load(
PATTERN_FILE, scan_size=nav_shape, pattern_size=sig_shape)

assert s.data.shape == nav_shape[::-1] + sig_shape
assert s.data.shape == nav_shape[::-1] + sig_shape

def test_load_save_cycle(self, save_path):
s = kp.load(PATTERN_FILE)
Expand Down Expand Up @@ -238,9 +244,14 @@ def test_load_readonly(self):
with pytest.raises(NotImplementedError):
s.data[:] = 23

def test_load_inplace(self):
with pytest.raises(ValueError):
kp.load(PATTERN_FILE, lazy=True, mmap_mode='r+')
@pytest.mark.parametrize('lazy', [True, False])
def test_load_inplace(self, lazy):
if lazy:
with pytest.raises(ValueError):
s = kp.load(PATTERN_FILE, lazy=lazy, mmap_mode='r+')
else:
s = kp.load(PATTERN_FILE, lazy=lazy, mmap_mode='r+')
assert s.axes_manager.as_dictionary() == AXES_MANAGER

def test_save_fresh(self, save_path):
scan_size = (10, 3)
Expand Down

0 comments on commit c203be2

Please sign in to comment.