NiftiTests   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setupNibabel() 0 6 2
A setUp() 0 10 1
A test_Tells_camera_to_save_snapshot_to_cache() 0 6 1
A test_Attach_method() 0 8 1
1
import unittest
2
from mock import Mock, sentinel
3
from datetime import datetime
4
from tests.test_basefile import BaseFileTests
5
6
7
class NiftiTests(BaseFileTests):
8
9
    def setUp(self):
10
        super(NiftiTests, self).setUp()
11
        self.libs = Mock()
12
        self.dependencies.getLibraries.return_value = self.libs
13
        self.img = Mock()
14
        self.hdr = Mock()
15
        self.setupNibabel()
16
        from niprov.nifti import NiftiFile
17
        self.constructor = NiftiFile
18
        self.file = NiftiFile(self.path, dependencies=self.dependencies)
19
20
    def setupNibabel(self):
21
        # Extension constructor simply creates a tuple of arguments
22
        self.img.get_header.return_value = self.hdr
23
        self.libs.nibabel.nifti1.Nifti1Extension = lambda x,y: ('extension',x,y)
24
        self.libs.nibabel.load.return_value = self.img
25
        self.libs.hasDependency.return_value = True
26
27
    def test_Attach_method(self):
28
        self.file.getProvenance = Mock()
29
        self.file.getProvenance.return_value = 'serial prov'
30
        self.file.attach('json')
31
        self.file.getProvenance.assert_called_with('json')
32
        self.hdr.extensions.append.assert_called_with(('extension','comment', 
33
            'serial prov'))
34
        self.img.to_filename.assert_called_with(self.file.path)
35
36
    def test_Tells_camera_to_save_snapshot_to_cache(self):
37
        img = self.libs.nibabel.load.return_value
38
        data = sentinel.imagedata
39
        img.get_data.return_value = data
40
        out = self.file.inspect()
41
        self.camera.saveSnapshot.assert_called_with(data, for_=self.file)
42
43