CommandlineTests.test_exportedToFile_logs_info()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
import unittest, os
2
from mock import Mock, patch, call
3
from tests.ditest import DependencyInjectionTestBase
4
5
6
class CommandlineTests(DependencyInjectionTestBase):
7
8
    def setUp(self):
9
        super(CommandlineTests, self).setUp()
10
11
    def test_Only_prints_if_appropriate_verbosity_setting(self):
12
        from niprov.commandline import Commandline
13
        self.dependencies.config.verbosity = 'warning'
14
        with patch('__builtin__.print') as mprint:
15
            cmd = Commandline(self.dependencies)
16
            cmd.log('info','Do you remember..')
17
            assert not mprint.called
18
            cmd.log('warning','Watch out!')
19
            mprint.assert_called_with('[provenance:warning] Watch out!')
20
21
    def test_exportedToFile_logs_info(self):
22
        from niprov.commandline import Commandline
23
        self.dependencies.config.verbosity = 'info'
24
        cmd = Commandline(self.dependencies)
25
        cmd.log = Mock()
26
        cmd.exportedToFile('backupfile.x')
27
        cmd.log.assert_called_with('info','Exported to file: backupfile.x')
28
29
    def test_addUnknownParent(self):
30
        from niprov.commandline import Commandline
31
        self.dependencies.config.verbosity = 'info'
32
        cmd = Commandline(self.dependencies)
33
        cmd.log = Mock()
34
        cmd.addUnknownParent('backupfile.x')
35
        cmd.log.assert_called_with('warning', 'backupfile.x unknown. Adding to provenance')
36
37
    def test_fileAdded(self):
38
        from niprov.commandline import Commandline
39
        self.dependencies.config.verbosity = 'info'
40
        cmd = Commandline(self.dependencies)
41
        cmd.log = Mock()
42
        img = Mock()
43
        img.path = 'xyz'
44
        img.status = 'new'
45
        cmd.fileAdded(img)
46
        cmd.log.assert_called_with('info', 'New file: xyz')
47
        img.status = 'series-new-file'
48
        img.provenance = {'filesInSeries':[1, 2, 3]}
49
        img.getSeriesId.return_value = 'series987'
50
        cmd.fileAdded(img)
51
        cmd.log.assert_called_with('info', 'Added 3rd file to series: series987')
52
        img.status = 'new-version'
53
        cmd.fileAdded(img)
54
        cmd.log.assert_called_with('info', 'Added new version for: xyz')
55
56
    def test_usingCopyAsParent(self):
57
        from niprov.commandline import Commandline
58
        self.dependencies.config.verbosity = 'info'
59
        cmd = Commandline(self.dependencies)
60
        cmd.log = Mock()
61
        copy = Mock()
62
        copy.location = 'moon:/copy/location'
63
        cmd.usingCopyAsParent(copy)
64
        cmd.log.assert_called_with('warning', 
65
            'Used provenance from copy found at '+str(copy.location))
66
        
67
68