Completed
Push — master ( 52f46a...fb72da )
by Jasper
10s
created

ContextTests   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 56
rs 10
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A test_get() 0 2 1
A test_add() 0 4 1
A setUp() 0 8 1
A test_import() 0 4 1
A test_export() 0 4 1
A test_backup() 0 3 1
A test_log() 0 6 1
A test_record() 0 6 1
A test_view() 0 4 1
A test_print() 0 4 1
1
import unittest
2
from mock import Mock, patch
3
from tests.ditest import DependencyInjectionTestBase
4
5
6
class ContextTests(DependencyInjectionTestBase):
7
8
    def setUp(self):
9
        super(ContextTests, self).setUp()
10
        patcher = patch('niprov.context.niprov')
11
        self.niprov = patcher.start()
12
        self.addCleanup(patcher.stop)
13
        from niprov import ProvenanceContext
14
        self.context = ProvenanceContext()
15
        self.context.deps = self.dependencies
16
17
    def test_get(self):
18
        self.assertEqual(self.context.get(), self.query)
19
20
    def test_add(self):
21
        self.context.add('file.p', True, {'c':3})
22
        self.niprov.adding.add.assert_called_with('file.p', True, {'c':3},
23
            self.dependencies)
24
25
    def test_log(self):
26
        self.context.log('new', 'trf', 'parents', 'code', 'logtext', False,
27
            'script', 'user', {'prov':1}, 'opts')
28
        self.niprov.logging.log.assert_called_with('new', 'trf', 'parents', 
29
            'code', 'logtext', False, 'script', 'user', {'prov':1}, 'opts',
30
            self.dependencies)
31
32
    def test_backup(self):
33
        self.context.backup()
34
        self.niprov.exporting.backup.assert_called_with(self.dependencies)
35
36
    def test_export(self):
37
        self.context.export('prov', 'medium', 'form')
38
        self.niprov.exporting.export.assert_called_with('prov', 'medium',
39
            'form', False, self.dependencies)
40
41
    def test_import(self):
42
        self.context.importp('fpath')
43
        self.niprov.importing.importp.assert_called_with('fpath',
44
            self.dependencies)
45
46
    def test_print(self):
47
        self.context.print_('images')
48
        self.niprov.exporting.print_.assert_called_with('images', False, 
49
            self.dependencies)
50
51
    def test_record(self):
52
        self.context.record('cmd', 'new', 'parents', True, 'args', 'kwargs', 
53
            'user', 'opts')
54
        self.niprov.recording.record.assert_called_with('cmd', 'new', 
55
            'parents', True, 'args', 'kwargs', 'user', 'opts',
56
            self.dependencies)
57
58
    def test_view(self):
59
        self.context.view('images', pipeline=True)
60
        self.niprov.exporting.view.assert_called_with('images', True, 
61
            self.dependencies)
62
63
64
65